Skip to content

Commit e7ce064

Browse files
Merge pull request #357 from emulsify-ds/codex-add-attributes-helper-cleanup
fix(theme): align add_attributes with helper semantics
2 parents ceb48e8 + 922002a commit e7ce064

20 files changed

Lines changed: 374 additions & 84 deletions

templates/admin/status-report-grouped.html.twig

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,45 @@
2121
<div>
2222
{% for group in grouped_requirements %}
2323
<div>
24-
<h3 id="{{ group.type }}">{{ group.title }}</h3>
24+
{% set status_report_group_title_attributes = {
25+
id: group.type,
26+
} %}
27+
<h3{{ add_attributes(status_report_group_title_attributes) }}>{{ group.title }}</h3>
2528
{% for requirement in group.items %}
26-
<details class="system-status-report__entry" open>
29+
{% set status_report_entry_attributes = {
30+
class: 'system-status-report__entry',
31+
open: 'open',
32+
} %}
33+
<details{{ add_attributes(status_report_entry_attributes) }}>
2734
{%
2835
set summary_classes = [
2936
'system-status-report__status-title',
3037
group.type in ['warning', 'error'] ? 'system-status-report__status-icon system-status-report__status-icon--' ~ group.type
3138
]
3239
%}
33-
<summary{{ create_attribute({'class': summary_classes}) }} role="button">
40+
{% set status_report_summary_attributes = {
41+
class: summary_classes,
42+
role: 'button',
43+
} %}
44+
<summary{{ add_attributes(status_report_summary_attributes) }}>
3445
{% if requirement.severity_title %}
35-
<span class="visually-hidden">{{ requirement.severity_title }}</span>
46+
{% set status_report_severity_attributes = {
47+
class: 'visually-hidden',
48+
} %}
49+
<span{{ add_attributes(status_report_severity_attributes) }}>{{ requirement.severity_title }}</span>
3650
{% endif %}
3751
{{ requirement.title }}
3852
</summary>
39-
<div class="system-status-report__entry__value">
53+
{% set status_report_value_attributes = {
54+
class: 'system-status-report__entry__value',
55+
} %}
56+
<div{{ add_attributes(status_report_value_attributes) }}>
4057
{{ requirement.value }}
4158
{% if requirement.description %}
42-
<div class="description">{{ requirement.description }}</div>
59+
{% set status_report_description_attributes = {
60+
class: 'description',
61+
} %}
62+
<div{{ add_attributes(status_report_description_attributes) }}>{{ requirement.description }}</div>
4363
{% endif %}
4464
</div>
4565
</details>

templates/admin/status-report.html.twig

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@
1919
*/
2020
#}
2121
{% for group in grouped_requirements %}
22-
<h3 id="{{ group.type }}">{{ group.title }}</h3>
22+
{% set status_report_group_title_attributes = {
23+
id: group.type,
24+
} %}
25+
<h3{{ add_attributes(status_report_group_title_attributes) }}>{{ group.title }}</h3>
2326
{% for requirement in group.items %}
2427
<details>
25-
<summary role="button">
28+
{% set status_report_summary_attributes = {
29+
role: 'button',
30+
} %}
31+
<summary{{ add_attributes(status_report_summary_attributes) }}>
2632
{% if requirement.severity_title %}
27-
<span class="visually-hidden">{{ requirement.severity_title }}</span>
33+
{% set status_report_severity_attributes = {
34+
class: 'visually-hidden',
35+
} %}
36+
<span{{ add_attributes(status_report_severity_attributes) }}>{{ requirement.severity_title }}</span>
2837
{% endif %}
2938
{{ requirement.title }}
3039
</summary>

templates/admin/system-admin-index.html.twig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313
* @see \Drupal\system\Theme\SystemAdminThemePreprocess::preprocessSystemAdminIndex()
1414
*/
1515
#}
16-
<div class="admin clearfix">
16+
{% set system_admin_index_attributes = {
17+
class: ['admin', 'clearfix'],
18+
} %}
19+
<div{{ add_attributes(system_admin_index_attributes) }}>
1720
{{ system_compact_link }}
1821
{% for position, blocks in containers %}
19-
<div class="{{ position }} clearfix">
22+
{% set system_admin_index_container_attributes = {
23+
class: [position, 'clearfix'],
24+
} %}
25+
<div{{ add_attributes(system_admin_index_container_attributes) }}>
2026
{% for block in blocks %}
2127
{{ block }}
2228
{% endfor %}

templates/admin/system-modules-details.html.twig

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,30 @@
4242
{{ module.checkbox }}
4343
</td>
4444
<td class="module">
45-
<label id="{{ module.id }}" for="{{ module.enable_id }}" class="module-name table-filter-text-source">{{ module.name }}</label>
45+
{% set module_label_attributes = {
46+
id: module.id,
47+
for: module.enable_id,
48+
class: ['module-name', 'table-filter-text-source'],
49+
} %}
50+
<label{{ add_attributes(module_label_attributes) }}>{{ module.name }}</label>
4651
</td>
4752
<td class="description expand priority-low">
48-
<details class="js-form-wrapper form-wrapper" id="{{ module.enable_id }}-description">
49-
<summary aria-controls="{{ module.enable_id }}-description" role="button" aria-expanded="false"><span class="text module-description">{{ module.description }}</span></summary>
53+
{% set module_details_attributes = {
54+
class: ['js-form-wrapper', 'form-wrapper'],
55+
id: module.enable_id ~ '-description',
56+
} %}
57+
<details{{ add_attributes(module_details_attributes) }}>
58+
{% set module_summary_attributes = {
59+
'aria-controls': module.enable_id ~ '-description',
60+
role: 'button',
61+
'aria-expanded': 'false',
62+
} %}
63+
<summary{{ add_attributes(module_summary_attributes) }}>
64+
{% set module_summary_text_attributes = {
65+
class: ['text', 'module-description'],
66+
} %}
67+
<span{{ add_attributes(module_summary_text_attributes) }}>{{ module.description }}</span>
68+
</summary>
5069
<div class="details-wrapper">
5170
<div class="details-description">
5271
<div class="requirements">

templates/admin/system-modules-uninstall.html.twig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@
4141
{{- module.checkbox -}}
4242
</td>
4343
<td>
44-
<label for="{{ module.checkbox_id }}" class="module-name table-filter-text-source">{{ module.name }}</label>
44+
{% set module_label_attributes = {
45+
for: module.checkbox_id,
46+
class: ['module-name', 'table-filter-text-source'],
47+
} %}
48+
<label{{ add_attributes(module_label_attributes) }}>{{ module.name }}</label>
4549
</td>
4650
<td class="description">
4751
<span class="text module-description">{{ module.description }}</span>

templates/block/block--system-menu-block.html.twig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737
class: not configuration.label_display ? 'visually-hidden',
3838
id: heading_id,
3939
} %}
40-
<nav role="navigation" aria-labelledby="{{ heading_id }}"{{ attributes|without('role', 'aria-labelledby') }}>
40+
{% set system_menu_block_attributes = {
41+
role: 'navigation',
42+
'aria-labelledby': heading_id,
43+
} %}
44+
<nav{{ add_attributes(system_menu_block_attributes) }}>
4145
{# Label. If not displayed, we still provide it for screen readers. #}
4246
{{ title_prefix }}
4347
{% with { attributes: title_attributes } %}

templates/content-edit/filter-caption.html.twig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
* - string classes: The classes of the captioned HTML tag.
1313
*/
1414
#}
15-
<figure role="group"{%- if classes %} class="{{ classes }}"{%- endif %}>
15+
{% set filter_caption_attributes = {
16+
role: 'group',
17+
class: classes ?: [],
18+
} %}
19+
<figure{{ add_attributes(filter_caption_attributes) }}>
1620
{{ node }}
1721
<figcaption>{{ caption }}</figcaption>
1822
</figure>

templates/content/comment.html.twig

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@
7474
server which comments are new for the user. Rendering the final "new"
7575
indicator here would break the render cache.
7676
#}
77-
<mark class="hidden" data-comment-timestamp="{{ new_indicator_timestamp }}"></mark>
77+
{% set comment_new_indicator_attributes = {
78+
class: 'hidden',
79+
'data-comment-timestamp': new_indicator_timestamp,
80+
} %}
81+
<mark{{ add_attributes(comment_new_indicator_attributes) }}></mark>
7882

7983
<footer>
8084
{{ user_picture }}
@@ -86,7 +90,10 @@
8690
without this information.
8791
#}
8892
{% if parent %}
89-
<p class="visually-hidden">{{ parent }}</p>
93+
{% set parent_comment_attributes = {
94+
class: 'visually-hidden',
95+
} %}
96+
<p{{ add_attributes(parent_comment_attributes) }}>{{ parent }}</p>
9097
{% endif %}
9198

9299
{{ permalink }}

templates/media-library/status-messages.html.twig

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,32 @@
1919
* - class: HTML classes.
2020
*/
2121
#}
22-
<div data-drupal-messages>
22+
{% set status_message_wrapper_attributes = attributes.toArray %}
23+
{% with { attributes: create_attribute() } %}
24+
{% set status_messages_attributes = {
25+
'data-drupal-messages': true,
26+
} %}
27+
<div{{ add_attributes(status_messages_attributes) }}>
28+
{% endwith %}
2329
{% for type, messages in message_list %}
24-
<div role="contentinfo" aria-label="{{ status_headings[type] }}"{{ attributes|without('role', 'aria-label') }}>
30+
{% with { attributes: create_attribute(status_message_wrapper_attributes) } %}
31+
{% set status_message_attributes = {
32+
role: 'contentinfo',
33+
'aria-label': status_headings[type],
34+
} %}
35+
<div{{ add_attributes(status_message_attributes) }}>
36+
{% endwith %}
2537
{% if type == 'error' %}
26-
<div role="alert">
38+
{% set status_message_alert_attributes = {
39+
role: 'alert',
40+
} %}
41+
<div{{ add_attributes(status_message_alert_attributes) }}>
2742
{% endif %}
2843
{% if status_headings[type] %}
29-
<h2 class="visually-hidden">{{ status_headings[type] }}</h2>
44+
{% set status_message_heading_attributes = {
45+
class: 'visually-hidden',
46+
} %}
47+
<h2{{ add_attributes(status_message_heading_attributes) }}>{{ status_headings[type] }}</h2>
3048
{% endif %}
3149
{% if messages|length > 1 %}
3250
<ul>
@@ -40,6 +58,6 @@
4058
{% if type == 'error' %}
4159
</div>
4260
{% endif %}
43-
</div>
61+
</div>
4462
{% endfor %}
4563
</div>

templates/misc/status-messages.html.twig

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,32 @@
1212
* - attributes: HTML attributes for the message wrapper.
1313
*/
1414
#}
15-
<div data-drupal-messages>
15+
{% set status_message_wrapper_attributes = attributes.toArray %}
16+
{% with { attributes: create_attribute() } %}
17+
{% set status_messages_attributes = {
18+
'data-drupal-messages': true,
19+
} %}
20+
<div{{ add_attributes(status_messages_attributes) }}>
21+
{% endwith %}
1622
{% for type, messages in message_list %}
17-
<div role="contentinfo" aria-label="{{ status_headings[type] }}"{{ attributes|without('role', 'aria-label') }}>
23+
{% with { attributes: create_attribute(status_message_wrapper_attributes) } %}
24+
{% set status_message_attributes = {
25+
role: 'contentinfo',
26+
'aria-label': status_headings[type],
27+
} %}
28+
<div{{ add_attributes(status_message_attributes) }}>
29+
{% endwith %}
1830
{% if type == 'error' %}
19-
<div role="alert">
31+
{% set status_message_alert_attributes = {
32+
role: 'alert',
33+
} %}
34+
<div{{ add_attributes(status_message_alert_attributes) }}>
2035
{% endif %}
2136
{% if status_headings[type] %}
22-
<h2 class="visually-hidden">{{ status_headings[type] }}</h2>
37+
{% set status_message_heading_attributes = {
38+
class: 'visually-hidden',
39+
} %}
40+
<h2{{ add_attributes(status_message_heading_attributes) }}>{{ status_headings[type] }}</h2>
2341
{% endif %}
2442
{% if messages|length > 1 %}
2543
<ul>
@@ -33,6 +51,6 @@
3351
{% if type == 'error' %}
3452
</div>
3553
{% endif %}
36-
</div>
54+
</div>
3755
{% endfor %}
3856
</div>

0 commit comments

Comments
 (0)