You are here

class WebformAccessibilityHelper in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Utility/WebformAccessibilityHelper.php \Drupal\webform\Utility\WebformAccessibilityHelper

Helper class webform accessibility methods.

Hierarchy

Expanded class hierarchy of WebformAccessibilityHelper

5 files declare their use of WebformAccessibilityHelper
webform.theme.inc in includes/webform.theme.inc
Theme hooks, preprocessor, and suggestions.
WebformElementStates.php in src/Element/WebformElementStates.php
WebformLikert.php in src/Element/WebformLikert.php
WebformLikert.php in src/Plugin/WebformElement/WebformLikert.php
WebformMultiple.php in src/Element/WebformMultiple.php

File

src/Utility/WebformAccessibilityHelper.php, line 8

Namespace

Drupal\webform\Utility
View source
class WebformAccessibilityHelper {

  /**
   * Visually hide text using .visually-hidden class.
   *
   * The .visually-hidden class is used to render invisible content just for
   * screen reader users.
   *
   * @param string|array $title
   *   Text or #markup that should be visually hidden.
   *
   * @return array
   *   A renderable array with the text wrapped in
   *   <span class="visually-hidden">
   *
   * @see https://webaim.org/techniques/css/invisiblecontent/
   */
  public static function buildVisuallyHidden($title) {
    if (is_array($title)) {
      return $title + [
        '#prefix' => '<span class="visually-hidden">',
        '#suffix' => '</span>',
      ];
    }
    else {
      return [
        '#markup' => $title,
        '#prefix' => '<span class="visually-hidden">',
        '#suffix' => '</span>',
      ];
    }
  }

  /**
   * Aria hide text using aria-hidden attribute.
   *
   * The aria-hidden property tells screen-readers if they
   * should ignore the element.
   *
   * @param string|array $title
   *   Text or #markup that should be aria-hidden.
   *
   * @return array
   *   A renderable array with the text wrapped in
   *   <span aria-hidden="true">
   *
   * @see https://www.w3.org/TR/wai-aria-1.1/#aria-hidden
   */
  public static function buildAriaHidden($title) {
    if (is_array($title)) {
      return $title + [
        '#prefix' => '<span aria-hidden="true">',
        '#suffix' => '</span>',
      ];
    }
    else {
      return [
        '#markup' => $title,
        '#prefix' => '<span aria-hidden="true">',
        '#suffix' => '</span>',
      ];
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
WebformAccessibilityHelper::buildAriaHidden public static function Aria hide text using aria-hidden attribute.
WebformAccessibilityHelper::buildVisuallyHidden public static function Visually hide text using .visually-hidden class.