You are here

protected function QuickEditFieldForm::init in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/quickedit/src/Form/QuickEditFieldForm.php \Drupal\quickedit\Form\QuickEditFieldForm::init()

Initialize the form state and the entity before the first form build.

1 call to QuickEditFieldForm::init()
QuickEditFieldForm::buildForm in core/modules/quickedit/src/Form/QuickEditFieldForm.php
Builds a form for a single entity field.

File

core/modules/quickedit/src/Form/QuickEditFieldForm.php, line 131
Contains \Drupal\quickedit\Form\QuickEditFieldForm.

Class

QuickEditFieldForm
Builds and process a form for editing a single entity field.

Namespace

Drupal\quickedit\Form

Code

protected function init(FormStateInterface $form_state, EntityInterface $entity, $field_name) {

  // @todo Rather than special-casing $node->revision, invoke prepareEdit()
  //   once https://www.drupal.org/node/1863258 lands.
  if ($entity
    ->getEntityTypeId() == 'node') {
    $node_type = $this->nodeTypeStorage
      ->load($entity
      ->bundle());
    $entity
      ->setNewRevision($node_type
      ->isNewRevision());
    $entity->revision_log = NULL;
  }
  $form_state
    ->set('entity', $entity);
  $form_state
    ->set('field_name', $field_name);

  // Fetch the display used by the form. It is the display for the 'default'
  // form mode, with only the current field visible.
  $display = EntityFormDisplay::collectRenderDisplay($entity, 'default');
  foreach ($display
    ->getComponents() as $name => $options) {
    if ($name != $field_name) {
      $display
        ->removeComponent($name);
    }
  }
  $form_state
    ->set('form_display', $display);
}