You are here

function bricks_field_widget_entity_reference_autocomplete_form_alter in Bricks​ 2.x

Same name and namespace in other branches
  1. 8 bricks.module \bricks_field_widget_entity_reference_autocomplete_form_alter()

Implements hook_field_widget_WIDGET_TYPE_form_alter() for `entity_reference_autocomplete`.

1 call to bricks_field_widget_entity_reference_autocomplete_form_alter()
bricks_field_widget_bricks_tree_autocomplete_form_alter in ./bricks.module
Implements hook_field_widget_WIDGET_TYPE_form_alter() for `bricks_tree_autocomplete`.

File

./bricks.module, line 228

Code

function bricks_field_widget_entity_reference_autocomplete_form_alter(&$element, FormStateInterface $form_state, $context) {
  $field_type = $context['items']
    ->getFieldDefinition()
    ->getType();

  // @TODO: Replace by 'Nested bricks' widget setting.
  if (in_array($field_type, [
    'bricks',
  ])) {

    // @TODO: Find a better way to be used in _bricks_preprocess_tabledrag_form().
    $element['#widget'] = 'entity_reference_autocomplete';

    // #default_value is en Entity or NULL.
    _bricks_form_element_alter($element, $context['items'][$context['delta']], $element['target_id']['#default_value']);
    hide($element['depth']);
  }
}