You are here

public function EntityFormProxy::getForm in Lightning Media 8.3

Same name and namespace in other branches
  1. 8.4 src/Plugin/EntityBrowser/Widget/EntityFormProxy.php \Drupal\lightning_media\Plugin\EntityBrowser\Widget\EntityFormProxy::getForm()
  2. 8 src/Plugin/EntityBrowser/Widget/EntityFormProxy.php \Drupal\lightning_media\Plugin\EntityBrowser\Widget\EntityFormProxy::getForm()
  3. 8.2 src/Plugin/EntityBrowser/Widget/EntityFormProxy.php \Drupal\lightning_media\Plugin\EntityBrowser\Widget\EntityFormProxy::getForm()
2 calls to EntityFormProxy::getForm()
EmbedCode::getForm in src/Plugin/EntityBrowser/Widget/EmbedCode.php
FileUpload::getForm in src/Plugin/EntityBrowser/Widget/FileUpload.php
2 methods override EntityFormProxy::getForm()
EmbedCode::getForm in src/Plugin/EntityBrowser/Widget/EmbedCode.php
FileUpload::getForm in src/Plugin/EntityBrowser/Widget/FileUpload.php

File

src/Plugin/EntityBrowser/Widget/EntityFormProxy.php, line 24

Class

EntityFormProxy
Base class for EB widgets which wrap around an (inline) entity form.

Namespace

Drupal\lightning_media\Plugin\EntityBrowser\Widget

Code

public function getForm(array &$original_form, FormStateInterface $form_state, array $additional_widget_parameters) {
  $form = parent::getForm($original_form, $form_state, $additional_widget_parameters);
  if (isset($form['actions'])) {
    $form['actions']['#weight'] = 100;

    // Allow the form to be rebuilt without using AJAX interactions. This
    // means we can do a lot of testing without JavaScript, which is WAY
    // easier.
    $form['actions']['update'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Update'),
      '#attributes' => [
        'class' => [
          'js-hide',
        ],
      ],
      '#submit' => [
        [
          static::class,
          'update',
        ],
      ],
    ];
  }
  $form['#type'] = 'container';
  $form['#attributes']['id'] = 'entity-form';
  $form['bundle'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Bundle'),
    '#required' => TRUE,
    '#options' => [],
    '#ajax' => [
      'callback' => [
        static::class,
        'ajax',
      ],
    ],
    '#access' => (bool) $this
      ->getCurrentValue($form_state),
    '#weight' => 80,
  ];
  foreach ($this
    ->getCurrentTypes($form_state) as $id => $type) {
    $form['bundle']['#options'][$id] = $type
      ->label();
  }
  $entity = $this
    ->getCurrentEntity($form_state);
  if ($entity) {
    $form['entity'] = [
      '#type' => 'inline_entity_form',
      '#entity_type' => 'media',
      '#default_value' => $entity,
      '#form_mode' => $this->configuration['form_mode'],
      '#weight' => 90,
    ];
    $form['bundle']['#access'] = FALSE;
    $form['entity']['#bundle'] = $form['entity']['#default_value']
      ->bundle();

    // Without this, IEF won't know where to hook into the widget. Don't pass
    // $original_form as the second argument to addCallback(), because it's
    // not just the entity browser part of the form, not the actual complete
    // form.
    ElementSubmit::addCallback($form['actions']['submit'], $form_state
      ->getCompleteForm());
  }
  return $form;
}