You are here

public function ParagraphSelection::validateReferenceableNewEntities in Paragraphs 8

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 DefaultSelection::validateReferenceableNewEntities

File

src/Plugin/EntityReferenceSelection/ParagraphSelection.php, line 235

Class

ParagraphSelection
Default plugin implementation of the Entity Reference Selection plugin.

Namespace

Drupal\paragraphs\Plugin\EntityReferenceSelection

Code

public function validateReferenceableNewEntities(array $entities) {
  $bundles = array_keys($this
    ->getSortedAllowedTypes());
  return array_filter($entities, function ($entity) {
    if (isset($bundles)) {
      return in_array($entity
        ->bundle(), $bundles);
    }
    return TRUE;
  });
}