You are here

public static function TextFormat::afterBuild in YAML Form 8

Alter the 'text_format' element after it has been built.

Parameters

array $element: An element.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The element.

File

src/Plugin/YamlFormElement/TextFormat.php, line 63

Class

TextFormat
Provides a 'text_format' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public static function afterBuild(array $element, FormStateInterface $form_state) {
  if (empty($element['format'])) {
    return $element;
  }

  // Hide tips.
  if (!empty($element['#hide_help']) && isset($element['format']['help'])) {
    $element['format']['help']['#attributes']['style'] = 'display: none';
  }

  // Hide filter format if the select menu and help is hidden.
  if (!empty($element['#hide_help']) && isset($element['format']['format']['#access']) && $element['format']['format']['#access'] === FALSE) {

    // Can't hide the format via #access but we can use CSS.
    $element['format']['#attributes']['style'] = 'display: none';
  }
  return $element;
}