public function HtmlElement::process in Field Group 8.3
Allows the field group formatter to manipulate the field group array and attach the formatters elements. The process method is called in the #process part of theme layer, and is currently used for forms. The preRender method is called in the #pre_render part of the theme layer, and is currently used for entity displays.
Parameters
array $element: The field group render array.
object $processed_object: The object / entity beïng processed.
Overrides FieldGroupFormatterBase::process
1 call to HtmlElement::process()
- HtmlElement::preRender in src/
Plugin/ field_group/ FieldGroupFormatter/ HtmlElement.php - Allows the field group formatter to manipulate the field group array and attach the formatters rendering element.
File
- src/
Plugin/ field_group/ FieldGroupFormatter/ HtmlElement.php, line 29
Class
- HtmlElement
- Plugin implementation of the 'html_element' formatter.
Namespace
Drupal\field_group\Plugin\field_group\FieldGroupFormatterCode
public function process(&$element, $processed_object) {
// Keep using preRender parent for BC.
parent::preRender($element, $processed_object);
$element_attributes = new Attribute();
if ($this
->getSetting('attributes')) {
// This regex split the attributes string so that we can pass that
// later to drupal_attributes().
preg_match_all('/([^\\s=]+)="([^"]+)"/', $this
->getSetting('attributes'), $matches);
// Put the attribute and the value together.
foreach ($matches[1] as $key => $attribute) {
$element_attributes[$attribute] = $matches[2][$key];
}
}
// Add the id to the attributes array.
if ($this
->getSetting('id')) {
$element_attributes['id'] = Html::getUniqueId($this
->getSetting('id'));
}
// Add the classes to the attributes array.
$classes = $this
->getClasses();
if (!empty($classes)) {
if (!isset($element_attributes['class'])) {
$element_attributes['class'] = [];
}
else {
$element_attributes['class'] = [
$element_attributes['class'],
];
}
$element_attributes['class'] = array_merge($classes, $element_attributes['class']
->value());
}
$element['#effect'] = $this
->getSetting('effect');
$element['#speed'] = $this
->getSetting('speed');
$element['#type'] = 'field_group_html_element';
$element['#wrapper_element'] = $this
->getSetting('element');
$element['#attributes'] = $element_attributes;
if ($this
->getSetting('show_label')) {
$element['#title_element'] = $this
->getSetting('label_element');
$element['#title'] = $this
->getLabel();
// Prevent \Drupal\content_translation\ContentTranslationHandler::addTranslatabilityClue()
// from adding an incorrect suffix to the field group title.
$element['#multilingual'] = TRUE;
$element['#title_attributes'] = new Attribute();
if (!empty($this
->getSetting('label_element_classes'))) {
$element['#title_attributes']
->addClass(explode(' ', $this
->getSetting('label_element_classes')));
}
if (!empty($this
->getSetting('effect')) && $this
->getSetting('effect') !== 'none') {
$element['#title_attributes']
->addClass('field-group-toggler');
}
}
if ($this
->getSetting('required_fields')) {
$element['#attributes']['class'][] = 'field-group-html-element';
$element['#attached']['library'][] = 'field_group/formatter.html_element';
$element['#attached']['library'][] = 'field_group/core';
}
}