function entity_reference_layout_merge_attributes in Entity Reference with Layout 8
Merges $layout_options into an $attributes array.
Returned attributes are passed to a rendered layout, typically with custom classes to be applied although can include other data useful to rendering.
Leverages even dispatcher pattern so other modules can add data to attributes.
1 call to entity_reference_layout_merge_attributes()
- theme_entity_reference_layout_widget in ./
entity_reference_layout.module - Themes the "ERL" field widget.
File
- ./
entity_reference_layout.module, line 117 - Contains entity_reference_layout.module.
Code
function entity_reference_layout_merge_attributes(array $attributes, array $layout_options) {
if (!empty($layout_options)) {
if (!empty($layout_options['options']['container_classes'])) {
$attributes['class'][] = $layout_options['options']['container_classes'];
}
if (!empty($layout_options['options']['bg_color'])) {
$attributes['style'] = [
'background-color: ' . $layout_options['options']['bg_color'],
];
}
}
$event = new ErlMergeAttributesEvent($attributes, $layout_options);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher
->dispatch(ErlMergeAttributesEvent::EVENT_NAME, $event);
return $attributes;
}