You are here

public function Entity::buildOptionsForm in Drupal 10

Same name in this branch
  1. 10 core/modules/views/src/Plugin/views/area/Entity.php \Drupal\views\Plugin\views\area\Entity::buildOptionsForm()
  2. 10 core/modules/views/src/Plugin/views/argument_validator/Entity.php \Drupal\views\Plugin\views\argument_validator\Entity::buildOptionsForm()
Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/area/Entity.php \Drupal\views\Plugin\views\area\Entity::buildOptionsForm()
  2. 9 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 (strpos($this->options['target'], '{{') === FALSE) {

    // @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']),
  ];
}