Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Entity.php

function Entity::buildOptionsForm

Same name in this branch
  1. 11.1.x core/modules/views/src/Plugin/views/argument_validator/Entity.php \Drupal\views\Plugin\views\argument_validator\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']),
    ];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal