You are here

public function Entity::validateArgument in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 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
UserName::validateArgument in core/modules/user/src/Plugin/views/argument_validator/UserName.php

File

core/modules/views/src/Plugin/views/argument_validator/Entity.php, line 161
Contains \Drupal\views\Plugin\views\argument_validator\Entity.

Class

Entity
Defines a 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 = array(
      $argument,
    );
  }
  else {
    return FALSE;
  }
  $entities = $this->entityManager
    ->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;
}