function EntityReferenceItem::getReferenceableBundles
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::getReferenceableBundles()
- main core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::getReferenceableBundles()
Returns the referenceable entity types and bundles.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition for which to retrieve the referenceable entity types and bundles.
Return value
array An array of referenceable bundles where the array is keyed by the entity type ID, with values an array of bundle names. (It is a single-value array with the entity type ID if the entity type does not implement bundles.)
Overrides EntityReferenceItemInterface::getReferenceableBundles
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ EntityReferenceItem.php, line 781
Class
- EntityReferenceItem
- Defines the 'entity_reference' entity field type.
Namespace
Drupal\Core\Field\Plugin\Field\FieldTypeCode
public static function getReferenceableBundles(FieldDefinitionInterface $field_definition) : array {
$settings = $field_definition->getSettings();
$target_type_id = $settings['target_type'];
$handler_settings = $settings['handler_settings'];
$has_target_bundles = isset($handler_settings['target_bundles']) && !empty($handler_settings['target_bundles']);
$target_bundles = $has_target_bundles ? $handler_settings['target_bundles'] : array_keys(\Drupal::service('entity_type.bundle.info')->getBundleInfo($target_type_id));
return [
$target_type_id => $target_bundles,
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.