function EntityReferenceItem::getReferenceableBundles

Same name and namespace in other branches
  1. 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::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\FieldType

Code

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.