You are here

public function DefaultSelection::validateReferenceableNewEntities in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::validateReferenceableNewEntities()

Validates which newly created entities can be referenced.

This method should replicate the logic implemented by \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface::validateReferenceableEntities(), but applied to newly created entities that have not been saved yet.

Parameters

\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities to check.

Return value

\Drupal\Core\Entity\EntityInterface[] The incoming $entities parameter, filtered for valid entities. Array keys are preserved.

Overrides SelectionWithAutocreateInterface::validateReferenceableNewEntities

4 calls to DefaultSelection::validateReferenceableNewEntities()
CommentSelection::validateReferenceableNewEntities in core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php
Validates which newly created entities can be referenced.
FileSelection::validateReferenceableNewEntities in core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php
Validates which newly created entities can be referenced.
NodeSelection::validateReferenceableNewEntities in core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php
Validates which newly created entities can be referenced.
UserSelection::validateReferenceableNewEntities in core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php
Validates which newly created entities can be referenced.
4 methods override DefaultSelection::validateReferenceableNewEntities()
CommentSelection::validateReferenceableNewEntities in core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php
Validates which newly created entities can be referenced.
FileSelection::validateReferenceableNewEntities in core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php
Validates which newly created entities can be referenced.
NodeSelection::validateReferenceableNewEntities in core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php
Validates which newly created entities can be referenced.
UserSelection::validateReferenceableNewEntities in core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php
Validates which newly created entities can be referenced.

File

core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php, line 316
Contains \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection.

Class

DefaultSelection
Default plugin implementation of the Entity Reference Selection plugin.

Namespace

Drupal\Core\Entity\Plugin\EntityReferenceSelection

Code

public function validateReferenceableNewEntities(array $entities) {
  return array_filter($entities, function ($entity) {
    if (isset($this->configuration['handler_settings']['target_bundles'])) {
      return in_array($entity
        ->bundle(), $this->configuration['handler_settings']['target_bundles']);
    }
    return TRUE;
  });
}