function _bricks_form_element_alter in Bricks 8
Same name and namespace in other branches
- 2.x bricks.module \_bricks_form_element_alter()
Helper function for widget's formElement().
5 calls to _bricks_form_element_alter()
- BricksTreeDynamicInlineWidget::formElement in modules/
bricks_dynamic/ src/ Plugin/ Field/ FieldWidget/ BricksTreeDynamicInlineWidget.php - Returns the form for a single field widget.
- BricksTreeDynamicWidget::formElement in modules/
bricks_dynamic/ src/ Plugin/ Field/ FieldWidget/ BricksTreeDynamicWidget.php - BricksTreeInlineWidget::formElement in modules/
bricks_inline/ src/ Plugin/ Field/ FieldWidget/ BricksTreeInlineWidget.php - Returns the form for a single field widget.
- bricks_field_widget_entity_reference_autocomplete_form_alter in ./
bricks.module - Implements hook_field_widget_WIDGET_TYPE_form_alter() for `entity_reference_autocomplete`.
- bricks_field_widget_paragraphs_form_alter in ./
bricks.module - Implements hook_field_widget_WIDGET_TYPE_form_alter() for `paragraphs`.
File
- ./
bricks.module, line 243
Code
function _bricks_form_element_alter(&$element, $item, $entity) {
$element['depth'] = [
// @TODO: Other types break the correct indentations.
'#type' => 'hidden',
'#default_value' => !empty($item->depth) ? $item->depth : 0,
'#weight' => 10,
'#attributes' => [
'class' => [
'bricks-depth',
],
],
];
$element['options'] = [
'#type' => 'container',
'#weight' => 100,
'#attributes' => [
'class' => [
'container-inline',
],
],
];
if ($entity) {
if ($entity
->bundle() == 'layout' && \Drupal::service('module_handler')
->moduleExists('layout_discovery')) {
$element['options']['layout'] = [
'#type' => 'select',
'#options' => \Drupal::service('plugin.manager.core.layout')
->getLayoutOptions(),
'#default_value' => !empty($item->options['layout']) ? $item->options['layout'] : NULL,
];
}
if ($entity
->bundle() != 'layout') {
$element['options']['view_mode'] = [
'#type' => 'select',
'#options' => \Drupal::service('entity_display.repository')
->getViewModeOptionsByBundle($entity
->getEntityTypeId(), $entity
->bundle()),
'#default_value' => !empty($item->options['view_mode']) ? $item->options['view_mode'] : NULL,
];
}
}
$element['options']['css_class'] = [
'#type' => 'textfield',
'#default_value' => !empty($item->options['css_class']) ? $item->options['css_class'] : '',
'#size' => 10,
'#attributes' => [
'placeholder' => t('CSS class(-es)'),
],
];
}