function Entity::buildOptionsForm

Same name in this branch
  1. 10 core/modules/views/src/Plugin/views/argument_validator/Entity.php \Drupal\views\Plugin\views\argument_validator\Entity::buildOptionsForm()
Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/argument_validator/Entity.php \Drupal\views\Plugin\views\argument_validator\Entity::buildOptionsForm()
  2. 9 core/modules/views/src/Plugin/views/area/Entity.php \Drupal\views\Plugin\views\area\Entity::buildOptionsForm()
  3. 8.9.x core/modules/views/src/Plugin/views/argument_validator/Entity.php \Drupal\views\Plugin\views\argument_validator\Entity::buildOptionsForm()
  4. 8.9.x core/modules/views/src/Plugin/views/area/Entity.php \Drupal\views\Plugin\views\area\Entity::buildOptionsForm()
  5. 11.x core/modules/views/src/Plugin/views/argument_validator/Entity.php \Drupal\views\Plugin\views\argument_validator\Entity::buildOptionsForm()
  6. 11.x core/modules/views/src/Plugin/views/area/Entity.php \Drupal\views\Plugin\views\area\Entity::buildOptionsForm()

Overrides TokenizeAreaPluginBase::buildOptionsForm

File

core/modules/views/src/Plugin/views/area/Entity.php, line 117

Class

Entity
Provides an area handler which renders an entity in a certain view mode.

Namespace

Drupal\views\Plugin\views\area

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    $form['view_mode'] = [
        '#type' => 'select',
        '#options' => $this->entityDisplayRepository
            ->getViewModeOptions($this->entityType),
        '#title' => $this->t('View mode'),
        '#default_value' => $this->options['view_mode'],
    ];
    $label = $this->entityTypeManager
        ->getDefinition($this->entityType)
        ->getLabel();
    $target = $this->options['target'];
    // If the target does not contain tokens, try to load the entity and
    // display the entity ID to the admin form user.
    // @todo Use a method to check for tokens in
    //   https://www.drupal.org/node/2396607.
    if (!str_contains($this->options['target'], '{{')) {
        // @todo If the entity does not exist, this will show the config target
        //   identifier. Decide if this is the correct behavior in
        //   https://www.drupal.org/node/2415391.
        if ($target_entity = $this->entityRepository
            ->loadEntityByConfigTarget($this->entityType, $this->options['target'])) {
            $target = $target_entity->id();
        }
    }
    $form['target'] = [
        '#title' => $this->t('@entity_type_label ID', [
            '@entity_type_label' => $label,
        ]),
        '#type' => 'textfield',
        '#default_value' => $target,
    ];
    $form['bypass_access'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Bypass access checks'),
        '#description' => $this->t('If enabled, access permissions for rendering the entity are not checked.'),
        '#default_value' => !empty($this->options['bypass_access']),
    ];
}

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