You are here

public function EntityEmbedDialog::buildEmbedStep in Lightning Media 8.4

Same name and namespace in other branches
  1. 8 src/Form/EntityEmbedDialog.php \Drupal\lightning_media\Form\EntityEmbedDialog::buildEmbedStep()
  2. 8.2 src/Form/EntityEmbedDialog.php \Drupal\lightning_media\Form\EntityEmbedDialog::buildEmbedStep()
  3. 8.3 src/Form/EntityEmbedDialog.php \Drupal\lightning_media\Form\EntityEmbedDialog::buildEmbedStep()

Form constructor for the entity embedding step.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides EntityEmbedDialog::buildEmbedStep

File

src/Form/EntityEmbedDialog.php, line 17

Class

EntityEmbedDialog
Overrides the entity embed dialog with specialized logic.

Namespace

Drupal\lightning_media\Form

Code

public function buildEmbedStep(array $form, FormStateInterface $form_state) {
  $entity = $form_state
    ->get('entity');
  $element = $form_state
    ->get('entity_element');
  $input = $form_state
    ->getUserInput();

  // If we're working with an existing embed, $input['editor_object'] will be
  // set, in which case we don't want to change anything (see ::buildForm()).
  // Otherwise, if the entity being embedded is a media item, see if its type
  // plugin has a preference regarding which display plugin to use.
  if (empty($input['editor_object']) && $entity instanceof MediaInterface) {
    $plugin_definition = $entity
      ->getSource()
      ->getPluginDefinition();
    if (isset($plugin_definition['entity_embed_display'])) {
      $element['data-entity-embed-display'] = $plugin_definition['entity_embed_display'];
      $form_state
        ->set('entity_element', $element);
    }
  }
  $form = parent::buildEmbedStep($form, $form_state);

  // If the user can choose the display plugin, allow Lightning Media's
  // settings to override that access.
  $element =& $form['attributes']['data-entity-embed-display'];
  if ($element['#access']) {
    $element['#access'] = $this
      ->config('lightning_media.settings')
      ->get('entity_embed.choose_display');
  }
  return $form;
}