public static function TextFormat::afterBuild in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElement/TextFormat.php \Drupal\webform\Plugin\WebformElement\TextFormat::afterBuild()
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/ WebformElement/ TextFormat.php, line 122
Class
- TextFormat
- Provides a 'text_format' element.
Namespace
Drupal\webform\Plugin\WebformElementCode
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';
}
else {
// Display tips in a modal.
$element['format']['help']['about']['#attributes']['class'][] = 'use-ajax';
$element['format']['help']['about']['#attributes'] += [
'data-dialog-type' => 'dialog',
'data-dialog-options' => Json::encode([
'dialogClass' => 'webform-text-format-help-dialog',
'width' => 800,
]),
];
}
// Hide filter format if the select menu and help is hidden.
if (!empty($element['#hide_help']) && !Element::isVisibleElement($element['format']['format'])) {
// Can't hide the format via #access but we can use CSS.
$element['format']['#attributes']['style'] = 'display: none';
}
return $element;
}