Skip to content

Commit

Permalink
Use aria labelled by on blocks to help with association.
Browse files Browse the repository at this point in the history
  • Loading branch information
emarchak committed Sep 26, 2016
1 parent a6f2ed3 commit 84d4693
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions templates/block.html.twig
@@ -0,0 +1,55 @@
{#
/**
* @file
* Theme override to display a block.
*
* Available variables:
* - plugin_id: The ID of the block implementation.
* - label: The configured label of the block if visible.
* - configuration: A list of the block's configuration values.
* - label: The configured label for the block.
* - label_display: The display settings for the label.
* - provider: The module or other provider that provided this block plugin.
* - Block plugin specific settings will also be stored here.
* - content: The content of this block.
* - attributes: array of HTML attributes populated by modules, intended to
* be added to the main container tag of this template.
* - id: A valid HTML ID and guaranteed unique.
* - title_attributes: Same as attributes, except applied to the main title
* tag that appears in the template.
* - title_prefix: Additional output populated by modules, intended to be
* displayed in front of the main title tag that appears in the template.
* - title_suffix: Additional output populated by modules, intended to be
* displayed after the main title tag that appears in the template.
*
* @see template_preprocess_block()
*/
#}
{% set heading_id = attributes.id ~ '-heading'|clean_id %}
{% set cta_id = attributes.id ~ '-cta'|clean_id %}

<section{{ attributes }}>
{{ title_prefix }}
{% if label %}
<h2{{ title_attributes.setAttribute('id', heading_id) }}>{{ label }}</h2>
{% endif %}
{{ title_suffix }}

<div{{ content_attributes }}>
{% block content %}
{{ content|without('field_call_to_action') }}
{% endblock %}
</div>

{% if content.field_call_to_action %}{% spaceless %}
<a
id="{{ cta_id }}"
class="btn btn-default"
href="{{ content.field_call_to_action[0]['#url'] }}"
aria-labelledby="{{ cta_id }} {{ heading_id }}">

{{ content.field_call_to_action[0]['#title'] }}
</a>
{% endspaceless %}{% endif %}

</section>

0 comments on commit 84d4693

Please sign in to comment.