You are here

function _bricks_form_element_alter in Bricks​ 2.x

Same name and namespace in other branches
  1. 8 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
BricksTreeDynamicWidget::formElement in modules/bricks_dynamic/src/Plugin/Field/FieldWidget/BricksTreeDynamicWidget.php
BricksTreeInlineWidget::formElement in modules/bricks_inline/src/Plugin/Field/FieldWidget/BricksTreeInlineWidget.php
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 352

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)'),
    ],
  ];
}