public function LayoutParagraphsWidget::buildLayoutRadios in Layout Paragraphs 1.0.x
Add theme wrappers to layout selection radios.
Theme function injects layout icons into radio buttons.
File
- src/
Plugin/ Field/ FieldWidget/ LayoutParagraphsWidget.php, line 1357
Class
- LayoutParagraphsWidget
- Entity Reference with Layout field widget.
Namespace
Drupal\layout_paragraphs\Plugin\Field\FieldWidgetCode
public function buildLayoutRadios($element) {
foreach (Element::children($element) as $key) {
$layout_name = $key;
$definition = $this->layoutPluginManager
->getDefinition($layout_name);
$icon = $definition
->getIcon(40, 60, 1, 0);
$rendered_icon = $this->renderer
->render($icon);
$title = new FormattableMarkup('<span class="layout-select__item-icon">@icon</span><span class="layout-select__item-title">@title</span>', [
'@title' => $element[$key]['#title'],
'@icon' => $rendered_icon,
]);
$element[$key]['#title'] = $title;
$element[$key]['#wrapper_attributes']['class'][] = 'layout-select__item';
}
$element['#wrapper_attributes'] = [
'class' => [
'layout-select',
],
];
return $element;
}