public static function DynamicEntityReferenceItem::generateSampleValue in Dynamic Entity Reference 8.2
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldType/DynamicEntityReferenceItem.php \Drupal\dynamic_entity_reference\Plugin\Field\FieldType\DynamicEntityReferenceItem::generateSampleValue()
Generates placeholder field values.
Useful when populating site with placeholder content during site building or profiling.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.
Return value
array An associative array of values.
Overrides EntityReferenceItem::generateSampleValue
File
- src/
Plugin/ Field/ FieldType/ DynamicEntityReferenceItem.php, line 506
Class
- DynamicEntityReferenceItem
- Defines the 'dynamic_entity_reference' entity field type.
Namespace
Drupal\dynamic_entity_reference\Plugin\Field\FieldTypeCode
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
/** @var \Drupal\dynamic_entity_reference\SelectionPluginManager $manager */
$manager = \Drupal::service('plugin.manager.dynamic_entity_reference_selection');
$settings = $field_definition
->getSettings();
foreach (static::getTargetTypes($settings) as $target_type) {
$values['target_type'] = $target_type;
if ($referenceable = $manager
->getSelectionHandler($field_definition, NULL, $target_type)
->getReferenceableEntities()) {
$group = array_rand($referenceable);
$values['target_id'] = array_rand($referenceable[$group]);
return $values;
}
}
}