You are here

public function RelationType::getBundles in Relation 8

Same name and namespace in other branches
  1. 8.2 src/Entity/RelationType.php \Drupal\relation\Entity\RelationType::getBundles()

Get valid entity/bundle pairs that can be associated with this type of Relation.

Parameters

NULL|string $direction: Bundle direction. Leave as NULL to get all.

Return value

array An array containing bundles as key/value pairs, keyed by entity type.

Overrides RelationTypeInterface::getBundles

File

src/Entity/RelationType.php, line 164

Class

RelationType
Defines relation type entity.

Namespace

Drupal\relation\Entity

Code

public function getBundles($direction = NULL) {
  $pairs = array();
  if ((!$direction || $direction == 'source') && is_array($this->source_bundles)) {
    $pairs += $this->source_bundles;
  }
  if ((!$direction || $direction == 'target') && is_array($this->target_bundles)) {
    $pairs += $this->target_bundles;
  }
  $bundles = array();
  foreach ($pairs as $pair) {
    list($entity_type_id, $bundle) = explode(':', $pair, 2);
    $bundles[$entity_type_id][$bundle] = $bundle;
  }
  return $bundles;
}