Issue #2021063 by Berdir, kiamlaluno, YesCT: Use hook_entity_operation_alter() for manage fields and manage display links.
parent
6aa975ca5f
commit
703e9e476c
|
@ -52,7 +52,7 @@ class ConfigEntityListController extends EntityListController {
|
|||
'title' => t('Disable'),
|
||||
'href' => $uri['path'] . '/disable',
|
||||
'options' => $uri['options'],
|
||||
'weight' => 20,
|
||||
'weight' => 40,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,6 +154,17 @@ class EntityType extends Plugin {
|
|||
*/
|
||||
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
|
||||
* objects of this entity type:
|
||||
|
|
|
@ -20,26 +20,10 @@ class CustomBlockTypeListController extends ConfigEntityListController {
|
|||
*/
|
||||
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' => 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,
|
||||
);
|
||||
// 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;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ use Drupal\custom_block\CustomBlockTypeInterface;
|
|||
* "list" = "Drupal\custom_block\CustomBlockTypeListController"
|
||||
* },
|
||||
* config_prefix = "custom_block.type",
|
||||
* bundle_of = "custom_block",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label",
|
||||
|
|
|
@ -63,7 +63,7 @@ class ConfigEntityListTest extends WebTestBase {
|
|||
'title' => t('Disable'),
|
||||
'href' => $uri['path'] . '/disable',
|
||||
'options' => $uri['options'],
|
||||
'weight' => 20,
|
||||
'weight' => 40,
|
||||
),
|
||||
'delete' => array (
|
||||
'title' => t('Delete'),
|
||||
|
|
|
@ -14,35 +14,6 @@ use Drupal\Core\Entity\EntityInterface;
|
|||
*/
|
||||
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().
|
||||
*/
|
||||
|
|
|
@ -32,6 +32,7 @@ use Drupal\contact\CategoryInterface;
|
|||
* },
|
||||
* uri_callback = "contact_category_uri",
|
||||
* config_prefix = "contact.category",
|
||||
* bundle_of = "contact_message",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label",
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* Allows administrators to attach custom fields to fieldable types.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -31,6 +31,7 @@ use Drupal\Core\Annotation\Translation;
|
|||
* "list" = "Drupal\node\NodeTypeListController",
|
||||
* },
|
||||
* config_prefix = "node.type",
|
||||
* bundle_of = "node",
|
||||
* entity_keys = {
|
||||
* "id" = "type",
|
||||
* "label" = "name",
|
||||
|
|
|
@ -88,33 +88,10 @@ class NodeTypeListController extends ConfigEntityListController implements Entit
|
|||
*/
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ use Drupal\taxonomy\VocabularyInterface;
|
|||
* }
|
||||
* },
|
||||
* config_prefix = "taxonomy.vocabulary",
|
||||
* bundle_of = "taxonomy_term",
|
||||
* entity_keys = {
|
||||
* "id" = "vid",
|
||||
* "label" = "name",
|
||||
|
|
|
@ -45,7 +45,7 @@ class VocabularyListController extends ConfigEntityListController implements For
|
|||
'title' => t('add terms'),
|
||||
'href' => $uri['path'] . '/add',
|
||||
'options' => $uri['options'],
|
||||
'weight' => 30,
|
||||
'weight' => 10,
|
||||
);
|
||||
unset($operations['delete']);
|
||||
|
||||
|
|
Loading…
Reference in New Issue