You are here

public function EntityDataDefinition::setBundles in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php \Drupal\Core\Entity\TypedData\EntityDataDefinition::setBundles()

Sets the array of possible entity bundles.

Parameters

array|null $bundles: The array of possible bundles, or NULL for any.

Return value

$this

Overrides EntityDataDefinitionInterface::setBundles

File

core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php, line 144

Class

EntityDataDefinition
A typed data definition class for describing entities.

Namespace

Drupal\Core\Entity\TypedData

Code

public function setBundles(array $bundles = NULL) {
  if (isset($bundles)) {
    $this
      ->addConstraint('Bundle', $bundles);
  }
  else {

    // Remove the constraint.
    unset($this->definition['constraints']['Bundle']);
  }
  return $this;
}