You are here

public function DefaultSelection::validateReferenceableNewEntities in Drupal 9

Same name and namespace in other branches
  1. 8 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

6 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.
MediaSelection::validateReferenceableNewEntities in core/modules/media/src/Plugin/EntityReferenceSelection/MediaSelection.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.
TermSelection::validateReferenceableNewEntities in core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php
Validates which newly created entities can be referenced.

... See full list

6 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.
MediaSelection::validateReferenceableNewEntities in core/modules/media/src/Plugin/EntityReferenceSelection/MediaSelection.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.
TermSelection::validateReferenceableNewEntities in core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php
Validates which newly created entities can be referenced.

... See full list

File

core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php, line 414

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) {
    $target_bundles = $this
      ->getConfiguration()['target_bundles'];
    if (isset($target_bundles)) {
      return in_array($entity
        ->bundle(), $target_bundles);
    }
    return TRUE;
  });
}