diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index cac0e79..e62c255 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -203,14 +203,14 @@ class EntityType implements EntityTypeInterface { protected $field_ui_base_route; /** - * Indicates whether this entity type is often used as a reference target. + * 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 $frequent_reference = FALSE; + protected $common_reference = FALSE; /** * The list cache tags for this entity type. @@ -722,8 +722,8 @@ public function getConfigDependencyKey() { /** * {@inheritdoc} */ - public function isFrequentReference() { - return $this->frequent_reference; + public function isCommonReference() { + return $this->common_reference; } } diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php index b1e8fc5..0dde653 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -678,8 +678,8 @@ public function getConfigDependencyKey(); * Indicates whether this entity type is commonly used as a reference target. * * @return bool - * TRUE if the entity type is a frequent reference; FALSE otherwise. + * TRUE if the entity type is a common reference; FALSE otherwise. */ - public function isFrequentReference(); + public function isCommonReference(); } diff --git a/core/lib/Drupal/Core/Field/FieldTypePluginManager.php b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php index 1c7a7fa..000e3fe 100644 --- a/core/lib/Drupal/Core/Field/FieldTypePluginManager.php +++ b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php @@ -140,9 +140,6 @@ public function getUiDefinitions() { // Add preconfigured definitions. foreach ($definitions as $id => $definition) { if (is_subclass_of($definition['class'], '\Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface')) { - // Remove the original definition from the list. - unset($definitions[$id]); - foreach ($definition['class']::getPreconfiguredOptions() as $key => $option) { $definitions['field_ui:' . $id . ':' . $key] = [ 'label' => $option['label'], diff --git a/core/lib/Drupal/Core/Field/PreconfiguredFieldUiOptionsInterface.php b/core/lib/Drupal/Core/Field/PreconfiguredFieldUiOptionsInterface.php index 6692681..2507f38 100644 --- a/core/lib/Drupal/Core/Field/PreconfiguredFieldUiOptionsInterface.php +++ b/core/lib/Drupal/Core/Field/PreconfiguredFieldUiOptionsInterface.php @@ -8,15 +8,10 @@ namespace Drupal\Core\Field; /** - * Defines an interface for exposing 'preconfigured' Field UI definitions. + * Defines an interface for exposing "preconfigured" Field UI definitions. * - * These field definitions will be exposed as additional options in the - * 'Add field' form in Field UI, together with individual field types. - * - * Note that field types implementing this interface will no longer have the - * usual $field_type['id'] => $field_type['label'] option exposed in Field UI's - * 'Add field' form, so they need to take care of including an 'unconfigured' - * definition as part of the return value of getPreconfiguredDefinitions(). + * 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() @@ -27,8 +22,7 @@ * Returns preconfigured field options for a field type. * * @return mixed[][] - * A multi-dimensional array with non-numeric keys and the following - * structure: + * 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. diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index 8d78c81..891e440 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -101,13 +101,13 @@ function entity_reference_field_storage_config_update(FieldStorageConfigInterfac } /** - * Implements hook_form_FORM_ID_alter() for field_ui_field_storage_add_form. + * 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 'Other' reference option at the end of the list. - $other = $form['add']['new_storage_type']['#options'][t('Reference')]['field_ui:entity_reference:_other']; - unset($form['add']['new_storage_type']['#options'][t('Reference')]['field_ui:entity_reference:_other']); - $form['add']['new_storage_type']['#options'][t('Reference')]['field_ui:entity_reference:_other'] = $other; + // 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…'); } /** diff --git a/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php b/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php index 912282e..9a55c2b 100644 --- a/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php +++ b/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php @@ -224,15 +224,15 @@ public static function fieldSettingsFormValidate(array $form, FormStateInterface public static function getPreconfiguredOptions() { $options = array(); - // Add all the frequently referenced entity types as distinct pre-configured + // Add all the commonly referenced entity types as distinct pre-configured // options. $entity_types = \Drupal::entityManager()->getDefinitions(); - $frequent_references = array_filter($entity_types, function (EntityTypeInterface $entity_type) { - return $entity_type->isFrequentReference(); + $common_references = array_filter($entity_types, function (EntityTypeInterface $entity_type) { + return $entity_type->isCommonReference(); }); /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */ - foreach ($frequent_references as $entity_type) { + foreach ($common_references as $entity_type) { $options[$entity_type->id()] = [ 'label' => $entity_type->getLabel(), 'field_storage_config' => [ @@ -243,11 +243,6 @@ public static function getPreconfiguredOptions() { ]; } - // Also include an 'unconfigured' option. - $options['_other'] = [ - 'label' => t('Other…'), - ]; - return $options; } diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php index 95d84d5..6395b4d 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php @@ -62,10 +62,16 @@ public function testFieldAdminHandler() { $bundle_path = 'admin/structure/types/manage/' . $this->type; // First step: 'Add new field' on the 'Manage fields' page. - $this->drupalPostForm($bundle_path . '/fields/add-field', array( + $this->drupalGet($bundle_path . '/fields/add-field'); + + // Check if the commonly referenced entity types appear in the list. + $this->assertOption('edit-new-storage-type', 'field_ui:entity_reference:node'); + $this->assertOption('edit-new-storage-type', 'field_ui:entity_reference:user'); + + $this->drupalPostForm(NULL, array( 'label' => 'Test label', 'field_name' => 'test', - 'new_storage_type' => 'field_ui:entity_reference:_other', + 'new_storage_type' => 'entity_reference', ), t('Save and continue')); // Node should be selected by default. @@ -239,7 +245,7 @@ public function createEntityReferenceField($target_type, $bundle = NULL) { $field_edit['field[settings][handler_settings][target_bundles][' . $bundle . ']'] = TRUE; } - $this->fieldUIAddNewField($bundle_path, $field_name, NULL, 'field_ui:entity_reference:_other', $storage_edit, $field_edit); + $this->fieldUIAddNewField($bundle_path, $field_name, NULL, 'entity_reference', $storage_edit, $field_edit); // Returns the generated field name. return $field_name; diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItemWithPreconfiguredOptions.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItemWithPreconfiguredOptions.php index 155daa4..baf5387 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItemWithPreconfiguredOptions.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItemWithPreconfiguredOptions.php @@ -28,7 +28,7 @@ class TestItemWithPreconfiguredOptions extends TestItem implements Preconfigured */ public static function getPreconfiguredOptions() { return [ - 'all_custom_options' => [ + 'custom_options' => [ 'label' => t('All custom options'), 'category' => t('Custom category'), 'field_storage_config' => [ @@ -50,9 +50,6 @@ public static function getPreconfiguredOptions() { 'type' => 'field_test_multiple', ], ], - 'no_custom_options' => [ - 'label' => t('No custom options'), - ], ]; } diff --git a/core/modules/field_ui/src/Form/FieldStorageAddForm.php b/core/modules/field_ui/src/Form/FieldStorageAddForm.php index 7342572..068ce92 100644 --- a/core/modules/field_ui/src/Form/FieldStorageAddForm.php +++ b/core/modules/field_ui/src/Form/FieldStorageAddForm.php @@ -431,7 +431,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { * * @param string $field_name * The field name. - * @param bool $widget_id + * @param bool|null $widget_id * (optional) The plugin ID of the widget. Defaults to NULL. */ protected function configureEntityFormDisplay($field_name, $widget_id = NULL) { @@ -449,7 +449,7 @@ protected function configureEntityFormDisplay($field_name, $widget_id = NULL) { * * @param string $field_name * The field name. - * @param bool $formatter_id + * @param bool|null $formatter_id * (optional) The plugin ID of the formatter. Defaults to NULL. */ protected function configureEntityViewDisplay($field_name, $formatter_id = NULL) { diff --git a/core/modules/field_ui/src/Tests/ManageFieldsTest.php b/core/modules/field_ui/src/Tests/ManageFieldsTest.php index e735bdb..e874ce7 100644 --- a/core/modules/field_ui/src/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/src/Tests/ManageFieldsTest.php @@ -557,7 +557,7 @@ function testHiddenFields() { // Check that non-configurable fields are not available. $field_types = \Drupal::service('plugin.manager.field.field_type')->getDefinitions(); foreach ($field_types as $field_type => $definition) { - if (empty($definition['no_ui']) && !is_subclass_of($definition['class'], '\Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface')) { + if (empty($definition['no_ui'])) { $this->assertTrue($this->xpath('//select[@id="edit-new-storage-type"]//option[@value=:field_type]', array(':field_type' => $field_type)), String::format('Configurable field type @field_type is available.', array('@field_type' => $field_type))); } else { @@ -672,41 +672,25 @@ function fieldListAdminPage() { public function testPreconfiguredFields() { $this->drupalGet('admin/structure/types/manage/article/fields/add-field'); - // Check that the two preconfigured options exist and the regular field type - // does not exist. - $this->assertOption('edit-new-storage-type', 'field_ui:test_field_with_preconfigured_options:all_custom_options'); - $this->assertOption('edit-new-storage-type', 'field_ui:test_field_with_preconfigured_options:no_custom_options'); - $this->assertNoOption('edit-new-storage-type', 'test_field_with_preconfigured_options'); + // Check that the preconfigured field option exist alongside the regular + // field type option. + $this->assertOption('edit-new-storage-type', 'field_ui:test_field_with_preconfigured_options:custom_options'); + $this->assertOption('edit-new-storage-type', 'test_field_with_preconfigured_options'); // Add a field with every possible preconfigured value. - $this->fieldUIAddNewField(NULL, 'test_all_custom_options', 'Test label', 'field_ui:test_field_with_preconfigured_options:all_custom_options'); - $field_storage = FieldStorageConfig::loadByName('node', 'field_test_all_custom_options'); + $this->fieldUIAddNewField(NULL, 'test_custom_options', 'Test label', 'field_ui:test_field_with_preconfigured_options:custom_options'); + $field_storage = FieldStorageConfig::loadByName('node', 'field_test_custom_options'); $this->assertEqual($field_storage->getCardinality(), FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); $this->assertEqual($field_storage->getSetting('test_field_storage_setting'), 'preconfigured_storage_setting'); - $field = FieldConfig::loadByName('node', 'article', 'field_test_all_custom_options'); + $field = FieldConfig::loadByName('node', 'article', 'field_test_custom_options'); $this->assertTrue($field->isRequired()); $this->assertEqual($field->getSetting('test_field_setting'), 'preconfigured_field_setting'); $form_display = entity_get_form_display('node', 'article', 'default'); - $this->assertEqual($form_display->getComponent('field_test_all_custom_options')['type'], 'test_field_widget_multiple'); + $this->assertEqual($form_display->getComponent('field_test_custom_options')['type'], 'test_field_widget_multiple'); $view_display = entity_get_display('node', 'article', 'default'); - $this->assertEqual($view_display->getComponent('field_test_all_custom_options')['type'], 'field_test_multiple'); - - // Add a field without any preconfigured options. - $this->fieldUIAddNewField('admin/structure/types/manage/article', 'test_no_custom_options', 'Test label', 'field_ui:test_field_with_preconfigured_options:no_custom_options'); - $field_storage = FieldStorageConfig::loadByName('node', 'field_test_no_custom_options'); - $this->assertEqual($field_storage->getCardinality(), 1); - $this->assertEqual($field_storage->getSetting('test_field_storage_setting'), 'dummy test string'); - - $field = FieldConfig::loadByName('node', 'article', 'field_test_no_custom_options'); - $this->assertFalse($field->isRequired()); - $this->assertEqual($field->getSetting('test_field_setting'), 'dummy test string'); - - $form_display = entity_get_form_display('node', 'article', 'default'); - $this->assertEqual($form_display->getComponent('field_test_no_custom_options')['type'], 'test_field_widget'); - $view_display = entity_get_display('node', 'article', 'default'); - $this->assertEqual($view_display->getComponent('field_test_no_custom_options')['type'], 'field_test_default'); + $this->assertEqual($view_display->getComponent('field_test_custom_options')['type'], 'field_test_multiple'); } } diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index 98b11eb..e3a58e5 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -55,7 +55,7 @@ * }, * bundle_entity_type = "node_type", * field_ui_base_route = "entity.node_type.edit_form", - * frequent_reference = TRUE, + * common_reference = TRUE, * permission_granularity = "bundle", * links = { * "canonical" = "/node/{node}", diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php index 6527223..6b41ae4 100644 --- a/core/modules/user/src/Entity/User.php +++ b/core/modules/user/src/Entity/User.php @@ -58,7 +58,7 @@ * "collection" = "/admin/people", * }, * field_ui_base_route = "entity.user.admin_form", - * frequent_reference = TRUE + * common_reference = TRUE * ) */ class User extends ContentEntityBase implements UserInterface {