diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php index 41c3ba6..0eb187a 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php @@ -52,7 +52,7 @@ public function getOperations(EntityInterface $entity) { 'title' => t('Disable'), 'href' => $uri['path'] . '/disable', 'options' => $uri['options'], - 'weight' => 20, + 'weight' => 40, ); } } diff --git a/core/lib/Drupal/Core/Entity/Annotation/EntityType.php b/core/lib/Drupal/Core/Entity/Annotation/EntityType.php index b8e4061..4984b6a 100644 --- a/core/lib/Drupal/Core/Entity/Annotation/EntityType.php +++ b/core/lib/Drupal/Core/Entity/Annotation/EntityType.php @@ -155,6 +155,16 @@ class EntityType extends Plugin { public $translation = array(); /** + * The name of the entity type this entity type provides bundles for. + * + * This can be used by other modules to act accordingly, e.g. field_ui uses + * it to add operation links to manage fields and displays. + * + * @var string + */ + public $bundle_of; + + /** * An array describing how the Field API can extract certain information from * objects of this entity type: * - id: The name of the property that contains the primary ID of the entity. diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php index 346cdff..48dfa65 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php @@ -16,35 +16,6 @@ class CustomBlockTypeListController extends ConfigEntityListController { /** - * {@inheritdoc} - */ - public function getOperations(EntityInterface $entity) { - $operations = parent::getOperations($entity); - if (module_exists('field_ui')) { - $uri = $entity->uri(); - $operations['manage-fields'] = array( - 'title' => t('Manage fields'), - 'href' => $uri['path'] . '/fields', - 'options' => $uri['options'], - 'weight' => 15, - ); - $operations['manage-form-display'] = array( - 'title' => t('Manage form display'), - 'href' => $uri['path'] . '/form-display', - 'options' => $uri['options'], - 'weight' => 20, - ); - $operations['manage-display'] = array( - 'title' => t('Manage display'), - 'href' => $uri['path'] . '/display', - 'options' => $uri['options'], - 'weight' => 25, - ); - } - return $operations; - } - - /** * Overrides \Drupal\Core\Entity\EntityListController::buildHeader(). */ public function buildHeader() { diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php index 0ceabd5..c544aa1 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php @@ -30,6 +30,7 @@ * "list" = "Drupal\custom_block\CustomBlockTypeListController" * }, * config_prefix = "custom_block.type", + * bundle_of = "custom_block", * entity_keys = { * "id" = "id", * "label" = "label", diff --git a/core/modules/contact/lib/Drupal/contact/CategoryListController.php b/core/modules/contact/lib/Drupal/contact/CategoryListController.php index 820010f..52f303b 100644 --- a/core/modules/contact/lib/Drupal/contact/CategoryListController.php +++ b/core/modules/contact/lib/Drupal/contact/CategoryListController.php @@ -15,35 +15,6 @@ class CategoryListController extends ConfigEntityListController { /** - * Overrides Drupal\Core\Entity\EntityListController::getOperations(). - */ - public function getOperations(EntityInterface $entity) { - $operations = parent::getOperations($entity); - if ($this->moduleHandler->moduleExists('field_ui')) { - $uri = $entity->uri(); - $operations['manage-fields'] = array( - 'title' => t('Manage fields'), - 'href' => $uri['path'] . '/fields', - 'options' => $uri['options'], - 'weight' => 11, - ); - $operations['manage-form-display'] = array( - 'title' => t('Manage form display'), - 'href' => $uri['path'] . '/form-display', - 'options' => $uri['options'], - 'weight' => 12, - ); - $operations['manage-display'] = array( - 'title' => t('Manage display'), - 'href' => $uri['path'] . '/display', - 'options' => $uri['options'], - 'weight' => 13, - ); - } - return $operations; - } - - /** * Overrides Drupal\Core\Entity\EntityListController::buildHeader(). */ public function buildHeader() { diff --git a/core/modules/contact/lib/Drupal/contact/Plugin/Core/Entity/Category.php b/core/modules/contact/lib/Drupal/contact/Plugin/Core/Entity/Category.php index 0b3323f..cf4bad2 100644 --- a/core/modules/contact/lib/Drupal/contact/Plugin/Core/Entity/Category.php +++ b/core/modules/contact/lib/Drupal/contact/Plugin/Core/Entity/Category.php @@ -32,6 +32,7 @@ * }, * uri_callback = "contact_category_uri", * config_prefix = "contact.category", + * bundle_of = "contact_message", * entity_keys = { * "id" = "id", * "label" = "label", diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 2040df2..a70dc51 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -6,6 +6,7 @@ */ use Drupal\entity\EntityViewModeInterface; +use Drupal\Core\Entity\EntityInterface; /** * Implements hook_help(). @@ -294,6 +295,44 @@ function field_ui_form_node_type_form_alter(&$form, $form_state) { } /** + * Implements hook_entity_operation_alter(). + */ +function field_ui_entity_operation_alter(array &$operations, EntityInterface $entity) { + global $user; + $info = $entity->entityInfo(); + // Add manage fields and display links if this entity type is the bundle + // of another. + if (!empty($info['bundle_of'])) { + $bundle_of = $info['bundle_of']; + $uri = $entity->uri(); + if (user_access('administer '. $bundle_of . ' fields')) { + $operations['manage-fields'] = array( + 'title' => t('Manage fields'), + 'href' => $uri['path'] . '/fields', + 'options' => $uri['options'], + 'weight' => 15, + ); + } + if (user_access('administer '. $bundle_of . ' form display')) { + $operations['manage-form-display'] = array( + 'title' => t('Manage form display'), + 'href' => $uri['path'] . '/form-display', + 'options' => $uri['options'], + 'weight' => 20, + ); + } + if (user_access('administer '. $bundle_of . ' display')) { + $operations['manage-display'] = array( + 'title' => t('Manage display'), + 'href' => $uri['path'] . '/display', + 'options' => $uri['options'], + 'weight' => 25, + ); + } + } +} + +/** * Form submission handler for the 'Save and manage fields' button. * * @see field_ui_form_node_type_form_alter() diff --git a/core/modules/node/lib/Drupal/node/NodeTypeListController.php b/core/modules/node/lib/Drupal/node/NodeTypeListController.php index d6be67d..953ceca 100644 --- a/core/modules/node/lib/Drupal/node/NodeTypeListController.php +++ b/core/modules/node/lib/Drupal/node/NodeTypeListController.php @@ -90,33 +90,10 @@ public function buildRow(EntityInterface $entity) { */ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); - $uri = $entity->uri(); - if ($this->moduleHandler->moduleExists('field_ui') && user_access('administer node fields')) { - $operations['manage-fields'] = array( - 'title' => t('Manage fields'), - 'href' => $uri['path'] . '/fields', - 'options' => $uri['options'], - 'weight' => 0, - ); - } - if ($this->moduleHandler->moduleExists('field_ui') && user_access('administer node form display')) { - $operations['manage-form-display'] = array( - 'title' => t('Manage form display'), - 'href' => $uri['path'] . '/form-display', - 'options' => $uri['options'], - 'weight' => 5, - ); - } - if ($this->moduleHandler->moduleExists('field_ui') && user_access('administer node display')) { - $operations['manage-display'] = array( - 'title' => t('Manage display'), - 'href' => $uri['path'] . '/display', - 'options' => $uri['options'], - 'weight' => 10, - ); - } - if ($entity->isLocked()) { - unset($operations['delete']); + // Place the edit operation after the operations added by field_ui.module + // which have the weights 15, 20, 25. + if (isset($operations['edit'])) { + $operations['edit']['weight'] = 30; } return $operations; } diff --git a/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/NodeType.php b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/NodeType.php index 464fbe0..727a025 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/NodeType.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/NodeType.php @@ -31,6 +31,7 @@ * "list" = "Drupal\node\NodeTypeListController", * }, * config_prefix = "node.type", + * bundle_of = "node", * entity_keys = { * "id" = "type", * "label" = "name", diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php index 9d55435..9a01954 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php @@ -29,6 +29,7 @@ * } * }, * config_prefix = "taxonomy.vocabulary", + * bundle_of = "taxonomy_term", * entity_keys = { * "id" = "vid", * "label" = "name", diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php index edd0b8d..0aef6f4 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php @@ -45,7 +45,7 @@ public function getOperations(EntityInterface $entity) { 'title' => t('add terms'), 'href' => $uri['path'] . '/add', 'options' => $uri['options'], - 'weight' => 30, + 'weight' => 10, ); unset($operations['delete']);