You are here

public function ParagraphEntityForm::getForm in Paragraphs Inline Entity Form 8

Same name and namespace in other branches
  1. 2.x src/Plugin/EntityBrowser/Widget/ParagraphEntityForm.php \Drupal\paragraphs_inline_entity_form\Plugin\EntityBrowser\Widget\ParagraphEntityForm::getForm()
  2. 2.0.x src/Plugin/EntityBrowser/Widget/ParagraphEntityForm.php \Drupal\paragraphs_inline_entity_form\Plugin\EntityBrowser\Widget\ParagraphEntityForm::getForm()

@todo fix the edit form

File

src/Plugin/EntityBrowser/Widget/ParagraphEntityForm.php, line 51

Class

ParagraphEntityForm
A wrapper for EntityForm to provide a two step form where on the first step the user can select the Entity type and on the second step, to create content

Namespace

Drupal\paragraphs_inline_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['form_mode'])) {
    return [
      '#markup' => $this
        ->t('The settings for %label widget are not configured correctly.', [
        '%label' => $this
          ->label(),
      ]),
    ];
  }

  // Check if we need to show the content type selector form or the entity create form
  if (!empty($form_state
    ->getUserInput()['selected_bundle'])) {
    $this->configuration['bundle'] = $form_state
      ->getUserInput()['selected_bundle'];
  }
  if ($this->configuration['bundle'] == '0') {
    $form = $this
      ->entitySelectorForm($original_form, $form_state, $additional_widget_parameters);
    return $form;
  }
  if ($form_state
    ->has([
    'entity_browser',
    'widget_context',
  ])) {
    $this
      ->handleWidgetContext($form_state
      ->get([
      'entity_browser',
      'widget_context',
    ]));
  }
  $form = parent::getForm($original_form, $form_state, $additional_widget_parameters);
  $form['#submit'] = [
    [
      'Drupal\\inline_entity_form\\ElementSubmit',
      'trigger',
    ],
  ];
  $form['actions'] = [
    '#type' => 'actions',
    'submit' => [
      '#type' => 'submit',
      '#value' => $this->configuration['submit_text'],
      '#eb_widget_main_submit' => empty($form_state
        ->getValues()) ? FALSE : TRUE,
      '#attributes' => [
        'class' => [
          'is-entity-browser-submit',
        ],
      ],
      '#button_type' => 'primary',
    ],
  ];
  $form['actions']['submit']['#ief_submit_trigger'] = TRUE;
  $form['actions']['submit']['#ief_submit_trigger_all'] = TRUE;
  $form['#attached']['drupalSettings']['entity_browser_widget']['auto_select'] = 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;
}