Issue #2021063 by Berdir, kiamlaluno, YesCT: Use hook_entity_operation_alter() for manage fields and manage display links.

8.0.x
Alex Pott 2013-08-25 11:41:10 +01:00
parent 6aa975ca5f
commit 703e9e476c
12 changed files with 64 additions and 79 deletions

View File

@ -52,7 +52,7 @@ class ConfigEntityListController extends EntityListController {
'title' => t('Disable'), 'title' => t('Disable'),
'href' => $uri['path'] . '/disable', 'href' => $uri['path'] . '/disable',
'options' => $uri['options'], 'options' => $uri['options'],
'weight' => 20, 'weight' => 40,
); );
} }
} }

View File

@ -154,6 +154,17 @@ class EntityType extends Plugin {
*/ */
public $translation = array(); public $translation = array();
/**
* The name of the entity type for which bundles are provided.
*
* It can be used by other modules to act accordingly; for example,
* the Field UI module 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 * An array describing how the Field API can extract certain information from
* objects of this entity type: * objects of this entity type:

View File

@ -20,26 +20,10 @@ class CustomBlockTypeListController extends ConfigEntityListController {
*/ */
public function getOperations(EntityInterface $entity) { public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity); $operations = parent::getOperations($entity);
if (module_exists('field_ui')) { // Place the edit operation after the operations added by field_ui.module
$uri = $entity->uri(); // which have the weights 15, 20, 25.
$operations['manage-fields'] = array( if (isset($operations['edit'])) {
'title' => t('Manage fields'), $operations['edit']['weight'] = 30;
'href' => $uri['path'] . '/fields',
'options' => $uri['options'],
'weight' => 0,
);
$operations['manage-form-display'] = array(
'title' => t('Manage form display'),
'href' => $uri['path'] . '/form-display',
'options' => $uri['options'],
'weight' => 5,
);
$operations['manage-display'] = array(
'title' => t('Manage display'),
'href' => $uri['path'] . '/display',
'options' => $uri['options'],
'weight' => 10,
);
} }
return $operations; return $operations;
} }

View File

@ -32,6 +32,7 @@ use Drupal\custom_block\CustomBlockTypeInterface;
* "list" = "Drupal\custom_block\CustomBlockTypeListController" * "list" = "Drupal\custom_block\CustomBlockTypeListController"
* }, * },
* config_prefix = "custom_block.type", * config_prefix = "custom_block.type",
* bundle_of = "custom_block",
* entity_keys = { * entity_keys = {
* "id" = "id", * "id" = "id",
* "label" = "label", * "label" = "label",

View File

@ -63,7 +63,7 @@ class ConfigEntityListTest extends WebTestBase {
'title' => t('Disable'), 'title' => t('Disable'),
'href' => $uri['path'] . '/disable', 'href' => $uri['path'] . '/disable',
'options' => $uri['options'], 'options' => $uri['options'],
'weight' => 20, 'weight' => 40,
), ),
'delete' => array ( 'delete' => array (
'title' => t('Delete'), 'title' => t('Delete'),

View File

@ -14,35 +14,6 @@ use Drupal\Core\Entity\EntityInterface;
*/ */
class CategoryListController extends ConfigEntityListController { 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(). * Overrides Drupal\Core\Entity\EntityListController::buildHeader().
*/ */

View File

@ -32,6 +32,7 @@ use Drupal\contact\CategoryInterface;
* }, * },
* uri_callback = "contact_category_uri", * uri_callback = "contact_category_uri",
* config_prefix = "contact.category", * config_prefix = "contact.category",
* bundle_of = "contact_message",
* entity_keys = { * entity_keys = {
* "id" = "id", * "id" = "id",
* "label" = "label", * "label" = "label",

View File

@ -5,6 +5,7 @@
* Allows administrators to attach custom fields to fieldable types. * Allows administrators to attach custom fields to fieldable types.
*/ */
use Drupal\Core\Entity\EntityInterface;
use Drupal\entity\EntityViewModeInterface; use Drupal\entity\EntityViewModeInterface;
/** /**
@ -293,6 +294,43 @@ 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) {
$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. * Form submission handler for the 'Save and manage fields' button.
* *

View File

@ -31,6 +31,7 @@ use Drupal\Core\Annotation\Translation;
* "list" = "Drupal\node\NodeTypeListController", * "list" = "Drupal\node\NodeTypeListController",
* }, * },
* config_prefix = "node.type", * config_prefix = "node.type",
* bundle_of = "node",
* entity_keys = { * entity_keys = {
* "id" = "type", * "id" = "type",
* "label" = "name", * "label" = "name",

View File

@ -88,33 +88,10 @@ class NodeTypeListController extends ConfigEntityListController implements Entit
*/ */
public function getOperations(EntityInterface $entity) { public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity); $operations = parent::getOperations($entity);
$uri = $entity->uri(); // Place the edit operation after the operations added by field_ui.module
if ($this->moduleHandler->moduleExists('field_ui') && user_access('administer node fields')) { // which have the weights 15, 20, 25.
$operations['manage-fields'] = array( if (isset($operations['edit'])) {
'title' => t('Manage fields'), $operations['edit']['weight'] = 30;
'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']);
} }
return $operations; return $operations;
} }

View File

@ -31,6 +31,7 @@ use Drupal\taxonomy\VocabularyInterface;
* } * }
* }, * },
* config_prefix = "taxonomy.vocabulary", * config_prefix = "taxonomy.vocabulary",
* bundle_of = "taxonomy_term",
* entity_keys = { * entity_keys = {
* "id" = "vid", * "id" = "vid",
* "label" = "name", * "label" = "name",

View File

@ -45,7 +45,7 @@ class VocabularyListController extends ConfigEntityListController implements For
'title' => t('add terms'), 'title' => t('add terms'),
'href' => $uri['path'] . '/add', 'href' => $uri['path'] . '/add',
'options' => $uri['options'], 'options' => $uri['options'],
'weight' => 30, 'weight' => 10,
); );
unset($operations['delete']); unset($operations['delete']);