You are here

public function ParagraphCloneForm::form in Paragraphs table 8

Gets the actual form array to be built.

Overrides ContentEntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/ParagraphCloneForm.php, line 41

Class

ParagraphCloneForm
Paragraph Clone Form class.

Namespace

Drupal\paragraphs_table\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $entity = $this->entity;
  $host = $entity
    ->getParentEntity();
  $entity_type = $host
    ->getEntityTypeId();
  $bundle = $host
    ->bundle();
  $parent = $host
    ->id();
  $field = $entity
    ->get('parent_field_name')->value;
  $entityFieldManager = \Drupal::service('entity_field.manager')
    ->getFieldDefinitions($entity_type, $bundle);
  $form['#title'] = $this
    ->t('Clone %type item %id', [
    '%type' => $entityFieldManager[$field]
      ->getLabel(),
    '%id' => $entity
      ->id(),
  ]);
  $form['entity_type'] = [
    '#type' => 'hidden',
    '#value' => $entity_type,
  ];
  $form['bundle'] = [
    '#type' => 'hidden',
    '#value' => $bundle,
  ];
  $form['parent'] = [
    '#type' => 'hidden',
    '#value' => $parent,
  ];
  $form['field'] = [
    '#type' => 'hidden',
    '#value' => $field,
  ];
  return $form;
}