Loading core/lib/Drupal/Core/Entity/EntityType.php +17 Changes for core/lib/Drupal/Core/Entity/EntityType.php: 17 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -202,6 +202,16 @@ class EntityType implements EntityTypeInterface { */ protected $field_ui_base_route; /** * Indicates whether this entity type is commonly used as a reference target. * * This is used by the Entity reference field to promote an entity type in the * add new field select list in Field UI. * * @var bool */ protected $common_reference_target = FALSE; /** * The list cache contexts for this entity type. * Loading Loading @@ -724,4 +734,11 @@ public function getConfigDependencyKey() { return 'content'; } /** * {@inheritdoc} */ public function isCommonReferenceTarget() { return $this->common_reference_target; } } core/lib/Drupal/Core/Entity/EntityTypeInterface.php +8 Changes for core/lib/Drupal/Core/Entity/EntityTypeInterface.php: 8 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -685,4 +685,12 @@ public function getListCacheTags(); */ public function getConfigDependencyKey(); /** * Indicates whether this entity type is commonly used as a reference target. * * @return bool * TRUE if the entity type is a common reference; FALSE otherwise. */ public function isCommonReferenceTarget(); } core/lib/Drupal/Core/Field/FieldTypePluginManager.php +20 −1 Changes for core/lib/Drupal/Core/Field/FieldTypePluginManager.php: 20 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -131,9 +131,28 @@ public function getDefaultFieldSettings($type) { */ public function getUiDefinitions() { $definitions = $this->getDefinitions(); return array_filter($definitions, function ($definition) { // Filter out definitions that can not be configured in Field UI. $definitions = array_filter($definitions, function ($definition) { return empty($definition['no_ui']); }); // Add preconfigured definitions. foreach ($definitions as $id => $definition) { if (is_subclass_of($definition['class'], '\Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface')) { foreach ($definition['class']::getPreconfiguredOptions() as $key => $option) { $definitions['field_ui:' . $id . ':' . $key] = [ 'label' => $option['label'], ] + $definition; if (isset($option['category'])) { $definitions['field_ui:' . $id . ':' . $key]['category'] = $option['category']; } } } } return $definitions; } /** Loading core/lib/Drupal/Core/Field/PreconfiguredFieldUiOptionsInterface.php +46 Changes for core/lib/Drupal/Core/Field/PreconfiguredFieldUiOptionsInterface.php: 46 added lines, 0 removed lines. Original line number Diff line number Diff line <?php /** * @file * Contains \Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface. */ namespace Drupal\Core\Field; /** * Defines an interface for exposing "preconfigured" field definitions. * * These field definitions will be exposed as additional options in the 'Add * field' form in Field UI, together with individual field types. * * @see \Drupal\Core\Field\FieldTypePluginManager::getUiDefinitions() * @see \Drupal\field_ui\Form\FieldStorageAddForm::submitForm() */ interface PreconfiguredFieldUiOptionsInterface { /** * Returns preconfigured field options for a field type. * * @return 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. * * @see \Drupal\field\Entity\FieldStorageConfig * @see \Drupal\field\Entity\FieldConfig * @see \Drupal\Core\Entity\Display\EntityDisplayInterface::setComponent() */ public static function getPreconfiguredOptions(); } core/modules/entity_reference/entity_reference.module +10 Changes for core/modules/entity_reference/entity_reference.module: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -114,6 +114,16 @@ function entity_reference_field_config_presave(FieldConfigInterface $field) { $field->settings['handler'] = $selection_manager->getPluginId($target_type, $current_handler); } /** * Implements hook_form_FORM_ID_alter() for 'field_ui_field_storage_add_form'. */ function entity_reference_form_field_ui_field_storage_add_form_alter(array &$form) { // Move the "Entity reference" option to the end of the list and rename it to // "Other". unset($form['add']['new_storage_type']['#options'][t('Reference')]['entity_reference']); $form['add']['new_storage_type']['#options'][t('Reference')]['entity_reference'] = t('Other…'); } /** * Render API callback: Processes the field settings form and allows access to * the form state. Loading Loading
core/lib/Drupal/Core/Entity/EntityType.php +17 Changes for core/lib/Drupal/Core/Entity/EntityType.php: 17 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -202,6 +202,16 @@ class EntityType implements EntityTypeInterface { */ protected $field_ui_base_route; /** * Indicates whether this entity type is commonly used as a reference target. * * This is used by the Entity reference field to promote an entity type in the * add new field select list in Field UI. * * @var bool */ protected $common_reference_target = FALSE; /** * The list cache contexts for this entity type. * Loading Loading @@ -724,4 +734,11 @@ public function getConfigDependencyKey() { return 'content'; } /** * {@inheritdoc} */ public function isCommonReferenceTarget() { return $this->common_reference_target; } }
core/lib/Drupal/Core/Entity/EntityTypeInterface.php +8 Changes for core/lib/Drupal/Core/Entity/EntityTypeInterface.php: 8 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -685,4 +685,12 @@ public function getListCacheTags(); */ public function getConfigDependencyKey(); /** * Indicates whether this entity type is commonly used as a reference target. * * @return bool * TRUE if the entity type is a common reference; FALSE otherwise. */ public function isCommonReferenceTarget(); }
core/lib/Drupal/Core/Field/FieldTypePluginManager.php +20 −1 Changes for core/lib/Drupal/Core/Field/FieldTypePluginManager.php: 20 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -131,9 +131,28 @@ public function getDefaultFieldSettings($type) { */ public function getUiDefinitions() { $definitions = $this->getDefinitions(); return array_filter($definitions, function ($definition) { // Filter out definitions that can not be configured in Field UI. $definitions = array_filter($definitions, function ($definition) { return empty($definition['no_ui']); }); // Add preconfigured definitions. foreach ($definitions as $id => $definition) { if (is_subclass_of($definition['class'], '\Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface')) { foreach ($definition['class']::getPreconfiguredOptions() as $key => $option) { $definitions['field_ui:' . $id . ':' . $key] = [ 'label' => $option['label'], ] + $definition; if (isset($option['category'])) { $definitions['field_ui:' . $id . ':' . $key]['category'] = $option['category']; } } } } return $definitions; } /** Loading
core/lib/Drupal/Core/Field/PreconfiguredFieldUiOptionsInterface.php +46 Changes for core/lib/Drupal/Core/Field/PreconfiguredFieldUiOptionsInterface.php: 46 added lines, 0 removed lines. Original line number Diff line number Diff line <?php /** * @file * Contains \Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface. */ namespace Drupal\Core\Field; /** * Defines an interface for exposing "preconfigured" field definitions. * * These field definitions will be exposed as additional options in the 'Add * field' form in Field UI, together with individual field types. * * @see \Drupal\Core\Field\FieldTypePluginManager::getUiDefinitions() * @see \Drupal\field_ui\Form\FieldStorageAddForm::submitForm() */ interface PreconfiguredFieldUiOptionsInterface { /** * Returns preconfigured field options for a field type. * * @return 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. * * @see \Drupal\field\Entity\FieldStorageConfig * @see \Drupal\field\Entity\FieldConfig * @see \Drupal\Core\Entity\Display\EntityDisplayInterface::setComponent() */ public static function getPreconfiguredOptions(); }
core/modules/entity_reference/entity_reference.module +10 Changes for core/modules/entity_reference/entity_reference.module: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -114,6 +114,16 @@ function entity_reference_field_config_presave(FieldConfigInterface $field) { $field->settings['handler'] = $selection_manager->getPluginId($target_type, $current_handler); } /** * Implements hook_form_FORM_ID_alter() for 'field_ui_field_storage_add_form'. */ function entity_reference_form_field_ui_field_storage_add_form_alter(array &$form) { // Move the "Entity reference" option to the end of the list and rename it to // "Other". unset($form['add']['new_storage_type']['#options'][t('Reference')]['entity_reference']); $form['add']['new_storage_type']['#options'][t('Reference')]['entity_reference'] = t('Other…'); } /** * Render API callback: Processes the field settings form and allows access to * the form state. Loading