You are here

function entity_browser_form_entity_embed_dialog_alter in Entity Browser 8.2

Same name and namespace in other branches
  1. 8 entity_browser.module \entity_browser_form_entity_embed_dialog_alter()

Implements hook_form_BASE_FORM_ID_alter().

File

./entity_browser.module, line 178
Allows to flexibly create, browse and select entities.

Code

function entity_browser_form_entity_embed_dialog_alter(&$form, FormStateInterface $form_state) {

  // Add contextual information to entity browser's widget context array.
  if (!empty($form['entity_browser']['#entity_browser'])) {
    $embed_button = $form_state
      ->get('embed_button');
    $type_settings = $embed_button
      ->getTypeSettings();

    // Cardinality is always 1 with entity embed.
    $context = [
      'embed_button_id' => $embed_button
        ->id(),
      'cardinality' => 1,
    ];
    if (!empty($type_settings['entity_type'])) {
      $context['target_entity_type'] = $type_settings['entity_type'];
    }
    if (!empty($type_settings['bundles'])) {
      $context['target_bundles'] = $type_settings['bundles'];
    }
    $form['entity_browser']['#widget_context'] = $context;
  }
}