protected static function EntityReferenceItem::getRandomBundle in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::getRandomBundle()
- 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::getRandomBundle()
Gets a bundle for a given entity type and selection options.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type.
array $selection_settings: An array of selection settings.
Return value
string|null Either the bundle string, or NULL if there is no bundle.
1 call to EntityReferenceItem::getRandomBundle()
- EntityReferenceItem::generateSampleValue in core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ EntityReferenceItem.php - Generates placeholder field values.
File
- core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ EntityReferenceItem.php, line 340
Class
- EntityReferenceItem
- Defines the 'entity_reference' entity field type.
Namespace
Drupal\Core\Field\Plugin\Field\FieldTypeCode
protected static function getRandomBundle(EntityTypeInterface $entity_type, array $selection_settings) {
if ($bundle_key = $entity_type
->getKey('bundle')) {
if (!empty($selection_settings['target_bundles'])) {
$bundle_ids = $selection_settings['target_bundles'];
}
else {
$bundle_ids = \Drupal::service('entity_type.bundle.info')
->getBundleInfo($entity_type
->id());
}
return array_rand($bundle_ids);
}
}