You are here

public function EntityFormProxy::getForm in Varbase Media 9.0.x

Same name and namespace in other branches
  1. 8.7 modules/entity_browser_generic_embed/src/Plugin/EntityBrowser/Widget/EntityFormProxy.php \Drupal\entity_browser_generic_embed\Plugin\EntityBrowser\Widget\EntityFormProxy::getForm()
  2. 8.5 modules/entity_browser_generic_embed/src/Plugin/EntityBrowser/Widget/EntityFormProxy.php \Drupal\entity_browser_generic_embed\Plugin\EntityBrowser\Widget\EntityFormProxy::getForm()
  3. 8.6 modules/entity_browser_generic_embed/src/Plugin/EntityBrowser/Widget/EntityFormProxy.php \Drupal\entity_browser_generic_embed\Plugin\EntityBrowser\Widget\EntityFormProxy::getForm()
1 call to EntityFormProxy::getForm()
EmbedCode::getForm in modules/entity_browser_generic_embed/src/Plugin/EntityBrowser/Widget/EmbedCode.php
1 method overrides EntityFormProxy::getForm()
EmbedCode::getForm in modules/entity_browser_generic_embed/src/Plugin/EntityBrowser/Widget/EmbedCode.php

File

modules/entity_browser_generic_embed/src/Plugin/EntityBrowser/Widget/EntityFormProxy.php, line 85

Class

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

Namespace

Drupal\entity_browser_generic_embed\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;
  }
  $form['entity'] = [
    '#prefix' => '<div id="entity" class="entity-browser-generic-embed">',
    '#suffix' => '</div>',
    '#weight' => 99,
  ];
  $value = $this
    ->getInputValue($form_state);
  if (empty($value)) {
    $form['entity']['#markup'] = NULL;
    return $form;
  }
  try {
    $entity = $this->helper
      ->createFromInput($value, $this
      ->getAllowedBundles($form_state));
  } catch (IndeterminateBundleException $e) {
    return $form;
  }
  $form['entity'] += [
    '#type' => 'inline_entity_form',
    '#entity_type' => $entity
      ->getEntityTypeId(),
    '#bundle' => $entity
      ->bundle(),
    '#default_value' => $entity,
    '#form_mode' => $this->configuration['form_mode'],
  ];

  // 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;
}