You are here

public static function TextFormat::preRenderFixTextFormatStates in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElement/TextFormat.php \Drupal\webform\Plugin\WebformElement\TextFormat::preRenderFixTextFormatStates()

Fix state .js-webform-states-hidden wrapper for text format element.

Adds .js-webform-states-hidden to wrapper to text format because text format's wrapper is hard-coded.

Parameters

array $element: An element.

Return value

array An element with .js-webform-states-hidden added to the #prefix and #suffix.

See also

\Drupal\webform\Utility\WebformElementHelper::fixStatesWrapper

text-format-wrapper.html.twig

File

src/Plugin/WebformElement/TextFormat.php, line 179

Class

TextFormat
Provides a 'text_format' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public static function preRenderFixTextFormatStates(array $element) {
  if (isset($element['#attributes']) && isset($element['#attributes']['class'])) {
    $index = array_search('js-webform-states-hidden', $element['#attributes']['class']);
    if ($index !== FALSE) {
      unset($element['#attributes']['class'][$index]);
      $element += [
        '#prefix' => '',
        '#suffix' => '',
      ];
      $element['#prefix'] = '<div class="js-webform-text-format-hidden">';
      $element['#suffix'] = $element['#suffix'] . '</div>';
    }
  }

  // Do not allow format value to be cleared when the text form is hidden
  // via #states.
  // @see \Drupal\webform\Element\WebformHtmlEditor::processWebformHtmlEditor
  $element['format']['#attributes']['data-webform-states-no-clear'] = TRUE;
  return $element;
}