You are here

public function EntityForm::getForm in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 modules/entity_form/src/Plugin/EntityBrowser/Widget/EntityForm.php \Drupal\entity_browser_entity_form\Plugin\EntityBrowser\Widget\EntityForm::getForm()

Returns widget form.

Parameters

array $original_form: Entire form bult up to this point. Form elements for widget should generally not be added directly to it but returned from funciton as a separated unit.

\Drupal\Core\Form\FormStateInterface $form_state: Form state object.

array $additional_widget_parameters: Additional parameters that we want to pass to the widget.

Return value

array Form structure.

Overrides WidgetBase::getForm

File

modules/entity_form/src/Plugin/EntityBrowser/Widget/EntityForm.php, line 101

Class

EntityForm
Provides entity form widget.

Namespace

Drupal\entity_browser_entity_form\Plugin\EntityBrowser\Widget

Code

public function getForm(array &$original_form, FormStateInterface $form_state, array $additional_widget_parameters) {
  if (empty($this->configuration['entity_type']) || empty($this->configuration['bundle']) || empty($this->configuration['form_mode'])) {
    return [
      '#markup' => $this
        ->t('The settings for this widget (Entity type, Bundle or Form mode) are not configured correctly.'),
    ];
  }
  $form = parent::getForm($original_form, $form_state, $additional_widget_parameters);

  // Pretend to be IEFs submit button.
  $form['#submit'] = [
    [
      'Drupal\\inline_entity_form\\ElementSubmit',
      'trigger',
    ],
  ];
  $form['actions']['submit']['#ief_submit_trigger'] = TRUE;
  $form['actions']['submit']['#ief_submit_trigger_all'] = TRUE;
  $form['inline_entity_form'] = [
    '#type' => 'inline_entity_form',
    '#op' => 'add',
    '#entity_type' => $this->configuration['entity_type'],
    '#bundle' => $this->configuration['bundle'],
    '#form_mode' => $this->configuration['form_mode'],
  ];
  return $form;
}