Commit 7c61f7ba authored by alexpott's avatar alexpott

Issue #2227601 by mparker17, cs_shadow, swentel, lanchez, mgifford: Added a...

Issue #2227601 by mparker17, cs_shadow, swentel, lanchez, mgifford: Added a "Visually-hidden" field label formatter.
parent bbbe3fdc
......@@ -2372,6 +2372,11 @@ function template_preprocess_field(&$variables, $hook) {
$variables['attributes']['class'][] = 'clearfix';
}
// Hide labels visually, but display them to screenreaders if applicable.
if ($element['#label_display'] == 'visually-hidden') {
$variables['title_attributes']['class'][] = 'visually-hidden';
}
static $default_attributes;
if (!isset($default_attributes)) {
$default_attributes = new Attribute;
......
......@@ -135,7 +135,7 @@ function testFieldItemListView() {
$this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
}
// Check that explicit display settings are used.
// Display settings: Check hidden field.
$display = array(
'label' => 'hidden',
'type' => 'field_test_multiple',
......@@ -156,6 +156,27 @@ function testFieldItemListView() {
}
$this->assertText($setting . '|' . implode('|', $array), 'Values were displayed with expected setting.');
// Display settings: Check visually-hidden field.
$display = array(
'label' => 'visually-hidden',
'type' => 'field_test_multiple',
'settings' => array(
'test_formatter_setting_multiple' => $this->randomName(),
'alter' => TRUE,
),
);
$output = $items->view($display);
$this->content = drupal_render($output);
$setting = $display['settings']['test_formatter_setting_multiple'];
$this->assertRaw('visually-hidden', 'Label was visually hidden.');
$this->assertText('field_test_entity_display_build_alter', 'Alter fired, display passed.');
$this->assertText('entity language is ' . LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Language is placed onto the context.');
$array = array();
foreach ($this->values as $delta => $value) {
$array[] = $delta . ':' . $value['value'];
}
$this->assertText($setting . '|' . implode('|', $array), 'Values were displayed with expected setting.');
// Check the prepare_view steps are invoked.
$display = array(
'label' => 'hidden',
......
......@@ -226,6 +226,7 @@ protected function getFieldLabelOptions() {
'above' => $this->t('Above'),
'inline' => $this->t('Inline'),
'hidden' => '- ' . $this->t('Hidden') . ' -',
'visually-hidden' => '- ' . $this->t('Visually Hidden') . ' -',
);
}
......
......@@ -31,7 +31,7 @@
#}
<div{{ attributes }}>
{% if not label_hidden %}
<div class="field-label"{{ title_attributes }}>{{ label }}:&nbsp;</div>
<div class="field-label{% if title_attributes.class %} {{ title_attributes.class }}{% endif %}"{{ title_attributes|without('class') }}>{{ label }}:&nbsp;</div>
{% endif %}
<div class="field-items"{{ content_attributes }}>
{% for delta, item in items %}
......
......@@ -159,14 +159,10 @@ function bartik_menu_tree__shortcut_default($variables) {
function bartik_preprocess_field(&$variables) {
$element = $variables['element'];
if ($element['#field_type'] == 'taxonomy_term_reference') {
$label_attributes['class'] = array('field-label');
if ($variables['label_hidden']) {
$label_attributes['class'][] = 'visually-hidden';
}
$variables['title_attributes']['class'][] = array('field-label');
if ($variables['element']['#label_display'] == 'inline') {
$label_attributes['class'][] = 'inline';
$variables['title_attributes']['class'][] = 'inline';
}
$variables['label_attributes'] = new Attribute($label_attributes);
}
}
......
......@@ -17,7 +17,9 @@
*/
#}
<div class="{{ attributes.class }} clearfix"{{ attributes|without('class') }}>
<h3{{ label_attributes }}>{{ label }}: </h3>
{% if not label_hidden %}
<h3{{ label_attributes }}>{{ label }}: </h3>
{% endif %}
<ul class="links">
{% for delta, item in items %}
<li class="taxonomy-term-reference-{{ delta }}"{{ item_attributes[delta] }}>{{ item }}</li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment