function QuickEditFieldForm::init

Same name in other branches
  1. 8.9.x 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 120

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->shouldCreateNewRevision());
        $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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.