function Entity::validateArgument

Same name in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/argument_validator/Entity.php \Drupal\views\Plugin\views\argument_validator\Entity::validateArgument()
  2. 10 core/modules/views/src/Plugin/views/argument_validator/Entity.php \Drupal\views\Plugin\views\argument_validator\Entity::validateArgument()
  3. 11.x core/modules/views/src/Plugin/views/argument_validator/Entity.php \Drupal\views\Plugin\views\argument_validator\Entity::validateArgument()

Overrides ArgumentValidatorPluginBase::validateArgument

2 methods override Entity::validateArgument()
TermName::validateArgument in core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php
Performs validation for a given argument.
UserName::validateArgument in core/modules/user/src/Plugin/views/argument_validator/UserName.php
Performs validation for a given argument.

File

core/modules/views/src/Plugin/views/argument_validator/Entity.php, line 177

Class

Entity
Defines an argument validator plugin for each entity type.

Namespace

Drupal\views\Plugin\views\argument_validator

Code

public function validateArgument($argument) {
    $entity_type = $this->definition['entity_type'];
    if ($this->multipleCapable && $this->options['multiple']) {
        // At this point only interested in individual IDs no matter what type,
        // just splitting by the allowed delimiters.
        $ids = array_filter(preg_split('/[,+ ]/', $argument));
    }
    elseif ($argument) {
        $ids = [
            $argument,
        ];
    }
    else {
        return FALSE;
    }
    $entities = $this->entityTypeManager
        ->getStorage($entity_type)
        ->loadMultiple($ids);
    // Validate each id => entity. If any fails break out and return false.
    foreach ($ids as $id) {
        // There is no entity for this ID.
        if (!isset($entities[$id])) {
            return FALSE;
        }
        if (!$this->validateEntity($entities[$id])) {
            return FALSE;
        }
    }
    return TRUE;
}

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