From 14c242d65b11d6a261c6a00c9b087778ae0baa67 Mon Sep 17 00:00:00 2001 From: Leo Feyer <1192057+leofeyer@users.noreply.github.com> Date: Fri, 24 May 2024 14:18:50 +0200 Subject: [PATCH] Use the `attr()` method in templates (see #7218) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description ----------- See https://github.com/contao/contao/pull/7209/files#r1598224759 The content element templates belong to deprecated legacy elements, so I‘m not sure if we want to update these, too? Commits ------- b8eaf2d9 Use the `attr()` method in templates 01e85a54 Allow overwriting the wrapper attributes in child templates 3f428e9c Reduce duplicate code 9dcc4271 Unify HtmlAttributes usage in legacy templates (see #13) 3f4899c1 Clean up 3e27bb57 Move the $this->extend() call to the top a62e0720 Adjust the ce_teaser.html5 template bf5e8ee0 Adjust the info_default.html5 template Co-authored-by: fritzmg --- .../templates/block/block_searchable.html5 | 30 +++++++++++++------ .../templates/block/block_unsearchable.html5 | 20 ++++--------- .../elements/ce_accordionSingle.html5 | 12 +++++++- .../elements/ce_accordionStart.html5 | 12 +++++++- .../templates/elements/ce_headline.html5 | 12 +++++++- .../templates/elements/ce_sliderStart.html5 | 12 +++++++- .../contao/templates/elements/ce_teaser.html5 | 20 +++++++++---- .../templates/elements/ce_toplink.html5 | 12 +++++++- .../templates/forms/form_explanation.html5 | 11 ++++++- .../contao/templates/forms/form_row.html5 | 11 ++++++- .../contao/templates/forms/form_wrapper.html5 | 12 +++++++- .../templates/member/member_default.html5 | 20 ++++++++----- .../templates/member/member_grouped.html5 | 20 ++++++++----- .../templates/modules/mod_article.html5 | 14 +++++++-- .../templates/modules/mod_articlenav.html5 | 19 +++++++----- .../templates/modules/mod_breadcrumb.html5 | 13 +++++++- .../modules/mod_changePassword.html5 | 11 ++----- .../contao/templates/modules/mod_login.html5 | 19 +++++++----- .../templates/modules/mod_navigation.html5 | 12 +++++++- .../templates/modules/mod_password.html5 | 11 ++----- .../templates/modules/mod_two_factor.html5 | 19 +++++++----- .../contao/templates/rss/rss_items_only.html5 | 2 +- .../contao/templates/info/info_default.html5 | 17 +++++++---- .../templates/listing/list_default.html5 | 17 +++++++---- 24 files changed, 255 insertions(+), 103 deletions(-) diff --git a/core-bundle/contao/templates/block/block_searchable.html5 b/core-bundle/contao/templates/block/block_searchable.html5 index 3a0aef47ea4..7f2168375f2 100644 --- a/core-bundle/contao/templates/block/block_searchable.html5 +++ b/core-bundle/contao/templates/block/block_searchable.html5 @@ -1,13 +1,25 @@ +class ?> block"cssID ?>style): ?> style="style ?>"> +$this->wrapperAttributes = $this + ->attr($this->cssID) + ->addClass([$this->class, 'block']) + ->addStyle($this->style) + ->mergeWith($this->wrapperAttributes) +; - block('headline'); ?> - headline): ?> - <hl ?>>headline ?>hl ?>> - - endblock(); ?> +?> - block('content'); ?> - endblock(); ?> +block('wrapper'); ?> + wrapperAttributes ?>> - + block('headline'); ?> + headline): ?> + <hl ?>>headline ?>hl ?>> + + endblock(); ?> + + block('content'); ?> + endblock(); ?> + + +endblock(); ?> diff --git a/core-bundle/contao/templates/block/block_unsearchable.html5 b/core-bundle/contao/templates/block/block_unsearchable.html5 index af1e3925a57..8e0df1da3c6 100644 --- a/core-bundle/contao/templates/block/block_unsearchable.html5 +++ b/core-bundle/contao/templates/block/block_unsearchable.html5 @@ -1,15 +1,7 @@ +extend('block_searchable') ?> - -
cssID ?>style): ?> style="style ?>"> - - block('headline'); ?> - headline): ?> - <hl ?>>headline ?>hl ?>> - - endblock(); ?> - - block('content'); ?> - endblock(); ?> - -
- +block('wrapper'); ?> + + parent(); ?> + +endblock(); ?> diff --git a/core-bundle/contao/templates/elements/ce_accordionSingle.html5 b/core-bundle/contao/templates/elements/ce_accordionSingle.html5 index 01b08bbcf85..7ce926cbea5 100644 --- a/core-bundle/contao/templates/elements/ce_accordionSingle.html5 +++ b/core-bundle/contao/templates/elements/ce_accordionSingle.html5 @@ -1,5 +1,15 @@ +class ?> ce_accordion ce_text block"cssID ?>style): ?> style="style ?>"> +$this->wrapperAttributes = $this + ->attr($this->cssID) + ->addClass([$this->class, 'ce_accordion', 'ce_text', 'block']) + ->addStyle($this->style) + ->mergeWith($this->wrapperAttributes) +; + +?> + +wrapperAttributes ?>>
headlineStyle): ?> style="headlineStyle ?>"> headline ?> diff --git a/core-bundle/contao/templates/elements/ce_accordionStart.html5 b/core-bundle/contao/templates/elements/ce_accordionStart.html5 index 078a74d16f4..dbf45fa0274 100644 --- a/core-bundle/contao/templates/elements/ce_accordionStart.html5 +++ b/core-bundle/contao/templates/elements/ce_accordionStart.html5 @@ -1,5 +1,15 @@ +class ?> ce_accordion block"cssID ?>style): ?> style="style ?>"> +$this->wrapperAttributes = $this + ->attr($this->cssID) + ->addClass([$this->class, 'ce_accordion', 'block']) + ->addStyle($this->style) + ->mergeWith($this->wrapperAttributes) +; + +?> + +wrapperAttributes ?>>
headlineStyle): ?> style="headlineStyle ?>"> headline ?> diff --git a/core-bundle/contao/templates/elements/ce_headline.html5 b/core-bundle/contao/templates/elements/ce_headline.html5 index 1bf6aaeb25d..03c1707ccab 100644 --- a/core-bundle/contao/templates/elements/ce_headline.html5 +++ b/core-bundle/contao/templates/elements/ce_headline.html5 @@ -1,4 +1,14 @@ +hl ?> class="class ?>"cssID ?>style): ?> style="style ?>"> +$this->wrapperAttributes = $this + ->attr($this->cssID) + ->addClass($this->class) + ->addStyle($this->style) + ->mergeWith($this->wrapperAttributes) +; + +?> + +<hl ?>wrapperAttributes ?>> headline ?> hl ?>> diff --git a/core-bundle/contao/templates/elements/ce_sliderStart.html5 b/core-bundle/contao/templates/elements/ce_sliderStart.html5 index a17580b1e56..b8c8ef2316a 100644 --- a/core-bundle/contao/templates/elements/ce_sliderStart.html5 +++ b/core-bundle/contao/templates/elements/ce_sliderStart.html5 @@ -1,5 +1,15 @@ +class ?> block"cssID ?>style): ?> style="style ?>"> +$this->wrapperAttributes = $this + ->attr($this->cssID) + ->addClass([$this->class, 'block']) + ->addStyle($this->style) + ->mergeWith($this->wrapperAttributes) +; + +?> + +wrapperAttributes ?>> headline): ?> <hl ?>>headline ?>hl ?>> diff --git a/core-bundle/contao/templates/elements/ce_teaser.html5 b/core-bundle/contao/templates/elements/ce_teaser.html5 index 773abe89342..fe7d67d9dec 100644 --- a/core-bundle/contao/templates/elements/ce_teaser.html5 +++ b/core-bundle/contao/templates/elements/ce_teaser.html5 @@ -1,12 +1,20 @@ +extend('block_searchable'); ?> -
cssID ?>style): ?> style="style ?>"> +headline): ?> -

headline ?>

- +$this->wrapperAttributes = $this + ->attr() + ->addClass('ce_text') + ->mergeWith($this->wrapperAttributes) +; - text ?> +$this->hl = 'h1'; + +?> +block('content'); ?> + + text ?>

more ?>

-
+endblock(); ?> diff --git a/core-bundle/contao/templates/elements/ce_toplink.html5 b/core-bundle/contao/templates/elements/ce_toplink.html5 index 6d1f9071399..fcc6fb5c933 100644 --- a/core-bundle/contao/templates/elements/ce_toplink.html5 +++ b/core-bundle/contao/templates/elements/ce_toplink.html5 @@ -1,6 +1,16 @@ +wrapperAttributes = $this + ->attr($this->cssID) + ->addClass([$this->class, 'block']) + ->addStyle($this->style) + ->mergeWith($this->wrapperAttributes) +; + +?> -
cssID ?>style): ?> style="style ?>"> +wrapperAttributes ?>> label ?>
diff --git a/core-bundle/contao/templates/forms/form_explanation.html5 b/core-bundle/contao/templates/forms/form_explanation.html5 index 3730bdeef76..0865052585e 100644 --- a/core-bundle/contao/templates/forms/form_explanation.html5 +++ b/core-bundle/contao/templates/forms/form_explanation.html5 @@ -1,4 +1,13 @@ +prefix ?> explanationclass): ?> class ?>"> +$this->wrapperAttributes = $this + ->attr() + ->addClass([$this->prefix, 'explanation', $this->class]) + ->mergeWith($this->wrapperAttributes) +; + +?> + +wrapperAttributes ?>> cspInlineStyles($this->generate()) ?>
diff --git a/core-bundle/contao/templates/forms/form_row.html5 b/core-bundle/contao/templates/forms/form_row.html5 index 6daf04df54d..66b3913f913 100644 --- a/core-bundle/contao/templates/forms/form_row.html5 +++ b/core-bundle/contao/templates/forms/form_row.html5 @@ -1,5 +1,14 @@ +prefix ?>class): ?> class ?>"> +$this->wrapperAttributes = $this + ->attr() + ->addClass([$this->prefix, $this->class]) + ->mergeWith($this->wrapperAttributes) +; + +?> + +wrapperAttributes ?>> block('label'); ?> endblock(); ?> diff --git a/core-bundle/contao/templates/forms/form_wrapper.html5 b/core-bundle/contao/templates/forms/form_wrapper.html5 index 8627af64461..4b8029323a5 100644 --- a/core-bundle/contao/templates/forms/form_wrapper.html5 +++ b/core-bundle/contao/templates/forms/form_wrapper.html5 @@ -1,6 +1,16 @@ +wrapperAttributes = $this + ->attr($this->cssID) + ->addClass([$this->class, 'block']) + ->addStyle($this->style) + ->mergeWith($this->wrapperAttributes) +; + +?> -
cssID ?>style): ?> style="style ?>"> +wrapperAttributes ?>> headline): ?> <hl ?>>headline ?>hl ?>> diff --git a/core-bundle/contao/templates/member/member_default.html5 b/core-bundle/contao/templates/member/member_default.html5 index 0486e654b89..72cbd7df286 100644 --- a/core-bundle/contao/templates/member/member_default.html5 +++ b/core-bundle/contao/templates/member/member_default.html5 @@ -1,10 +1,17 @@ +extend('block_unsearchable'); ?> - -
cssID ?>style): ?> style="style ?>"> +headline): ?> - <hl ?>>headline ?>hl ?>> - +$this->wrapperAttributes = $this + ->attr($this->cssID) + ->addClass([$this->class, 'block']) + ->addStyle($this->style) + ->mergeWith($this->wrapperAttributes) +; + +?> + +block('content'); ?> message): ?>

message ?>

@@ -21,5 +28,4 @@
-
- +endblock(); ?> diff --git a/core-bundle/contao/templates/member/member_grouped.html5 b/core-bundle/contao/templates/member/member_grouped.html5 index 368833aeb12..c7db93e2f16 100644 --- a/core-bundle/contao/templates/member/member_grouped.html5 +++ b/core-bundle/contao/templates/member/member_grouped.html5 @@ -1,10 +1,17 @@ +extend('block_unsearchable'); ?> - -
cssID ?>style): ?> style="style ?>"> +headline): ?> - <hl ?>>headline ?>hl ?>> - +$this->wrapperAttributes = $this + ->attr($this->cssID) + ->addClass([$this->class, 'block']) + ->addStyle($this->style) + ->mergeWith($this->wrapperAttributes) +; + +?> + +block('content'); ?> message): ?>

message ?>

@@ -30,5 +37,4 @@
-
- +endblock(); ?> diff --git a/core-bundle/contao/templates/modules/mod_article.html5 b/core-bundle/contao/templates/modules/mod_article.html5 index 0ec200759d2..3be35bca8af 100644 --- a/core-bundle/contao/templates/modules/mod_article.html5 +++ b/core-bundle/contao/templates/modules/mod_article.html5 @@ -1,8 +1,18 @@ +wrapperAttributes = $this + ->attr($this->cssID) + ->addClass([$this->class, 'block']) + ->addStyle($this->style) + ->mergeWith($this->wrapperAttributes) +; + +?> teaserOnly): ?> block('alias'); ?> -
cssID ?>style): ?> style="style ?>"> + wrapperAttributes ?>>

headline ?>

@@ -21,7 +31,7 @@ -
cssID ?>style): ?> style="style ?>"> + wrapperAttributes ?>> printable): ?> block('syndication'); ?> diff --git a/core-bundle/contao/templates/modules/mod_articlenav.html5 b/core-bundle/contao/templates/modules/mod_articlenav.html5 index 2687fb3fa5e..da83a810998 100644 --- a/core-bundle/contao/templates/modules/mod_articlenav.html5 +++ b/core-bundle/contao/templates/modules/mod_articlenav.html5 @@ -1,10 +1,16 @@ +extend('block_unsearchable'); ?> - - - +endblock(); ?> diff --git a/core-bundle/contao/templates/modules/mod_breadcrumb.html5 b/core-bundle/contao/templates/modules/mod_breadcrumb.html5 index 03c70c4a7f9..a337fdd497e 100644 --- a/core-bundle/contao/templates/modules/mod_breadcrumb.html5 +++ b/core-bundle/contao/templates/modules/mod_breadcrumb.html5 @@ -1,6 +1,17 @@ +wrapperAttributes = $this + ->attr($this->cssID) + ->addClass([$this->class, 'block']) + ->addStyle($this->style) + ->set('aria-label', 'Breadcrumb') + ->mergeWith($this->wrapperAttributes) +; + +?> -
- +endblock(); ?> diff --git a/core-bundle/contao/templates/modules/mod_login.html5 b/core-bundle/contao/templates/modules/mod_login.html5 index e8ef6c4f181..b7898c5c9bc 100644 --- a/core-bundle/contao/templates/modules/mod_login.html5 +++ b/core-bundle/contao/templates/modules/mod_login.html5 @@ -1,10 +1,16 @@ +extend('block_unsearchable'); ?> - -
cssID ?>style): ?> style="style ?>"> +headline): ?> - <hl ?>>headline ?>hl ?>> - +$this->wrapperAttributes = $this + ->attr() + ->addClass($this->logout ? 'logout' : 'login') + ->mergeWith($this->wrapperAttributes) +; + +?> + +block('content'); ?> action): ?> action="action ?>" id="formId ?>" method="post">
@@ -67,5 +73,4 @@
-
- +endblock(); ?> diff --git a/core-bundle/contao/templates/modules/mod_navigation.html5 b/core-bundle/contao/templates/modules/mod_navigation.html5 index 3dfe1adc710..ebaa6b177bc 100644 --- a/core-bundle/contao/templates/modules/mod_navigation.html5 +++ b/core-bundle/contao/templates/modules/mod_navigation.html5 @@ -1,6 +1,16 @@ +wrapperAttributes = $this + ->attr($this->cssID) + ->addClass([$this->class, 'block']) + ->addStyle($this->style) + ->mergeWith($this->wrapperAttributes) +; + +?> -
- +endblock(); ?> diff --git a/core-bundle/contao/templates/rss/rss_items_only.html5 b/core-bundle/contao/templates/rss/rss_items_only.html5 index 650afe83f83..c11e622ed3b 100644 --- a/core-bundle/contao/templates/rss/rss_items_only.html5 +++ b/core-bundle/contao/templates/rss/rss_items_only.html5 @@ -3,7 +3,7 @@ block('content'); ?> items as $item): ?> -
+

diff --git a/listing-bundle/contao/templates/info/info_default.html5 b/listing-bundle/contao/templates/info/info_default.html5 index b49cad3b881..9ec043ab11a 100644 --- a/listing-bundle/contao/templates/info/info_default.html5 +++ b/listing-bundle/contao/templates/info/info_default.html5 @@ -1,9 +1,16 @@ +extend('block_searchable'); ?> -
cssID ?>style): ?> style="style ?>"> +headline): ?> - <hl ?>>headline ?>hl ?>> - +$this->wrapperAttributes = $this + ->attr() + ->addClass('listing') + ->mergeWith($this->wrapperAttributes) +; + +?> + +block('content'); ?> @@ -20,4 +27,4 @@

back ?>

- +endblock(); ?> diff --git a/listing-bundle/contao/templates/listing/list_default.html5 b/listing-bundle/contao/templates/listing/list_default.html5 index 9ec4a6969f2..7eb051e5e5e 100644 --- a/listing-bundle/contao/templates/listing/list_default.html5 +++ b/listing-bundle/contao/templates/listing/list_default.html5 @@ -1,9 +1,16 @@ +extend('block_searchable'); ?> -
cssID ?>style): ?> style="style ?>"> +headline): ?> - <hl ?>>headline ?>hl ?>> - +$this->wrapperAttributes = $this + ->attr() + ->addClass(['ce_table', 'listing']) + ->mergeWith($this->wrapperAttributes) +; + +?> + +block('content'); ?> searchable): ?> +endblock(); ?>