public static function EntityReferenceItem::getPreconfiguredOptions in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::getPreconfiguredOptions()
Returns preconfigured field options for a field type.
Return value
mixed[][] A multi-dimensional array with string keys and the following structure:
- label: The label to show in the field type selection list.
- category: (optional) The category in which to put the field label. Defaults to the category of the field type.
- field_storage_config: An array with the following supported keys:
- cardinality: The field cardinality.
- settings: Field-type specific storage settings.
- field_config: An array with the following supported keys:
- required: Indicates whether the field is required.
- settings: Field-type specific settings.
- entity_form_display: An array with the following supported keys:
- type: The widget to be used in the 'default' form mode.
- entity_view_display: An array with the following supported keys:
- type: The formatter to be used in the 'default' view mode.
Overrides PreconfiguredFieldUiOptionsInterface::getPreconfiguredOptions
See also
\Drupal\field\Entity\FieldStorageConfig
\Drupal\field\Entity\FieldConfig
\Drupal\Core\Entity\Display\EntityDisplayInterface::setComponent()
1 method overrides EntityReferenceItem::getPreconfiguredOptions()
- FileItem::getPreconfiguredOptions in core/
modules/ file/ src/ Plugin/ Field/ FieldType/ FileItem.php - Returns preconfigured field options for a field type.
File
- core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ EntityReferenceItem.php, line 617 - Contains \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem.
Class
- EntityReferenceItem
- Defines the 'entity_reference' entity field type.
Namespace
Drupal\Core\Field\Plugin\Field\FieldTypeCode
public static function getPreconfiguredOptions() {
$options = array();
// Add all the commonly referenced entity types as distinct pre-configured
// options.
$entity_types = \Drupal::entityManager()
->getDefinitions();
$common_references = array_filter($entity_types, function (EntityTypeInterface $entity_type) {
return $entity_type
->isCommonReferenceTarget();
});
/** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
foreach ($common_references as $entity_type) {
$options[$entity_type
->id()] = [
'label' => $entity_type
->getLabel(),
'field_storage_config' => [
'settings' => [
'target_type' => $entity_type
->id(),
],
],
];
}
return $options;
}