Commit 24526aed authored by catch's avatar catch
Browse files

Revert "Issue #2165725 by Xano: Introduce hook_entity_operation()."

This reverts commit 2cf87103.
parent 2fe3785c
......@@ -30,9 +30,8 @@ public function load() {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
$operations = parent::getDefaultOperations($entity);
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
if ($this->entityType->hasKey('status')) {
if (!$entity->status() && $entity->hasLinkTemplate('enable')) {
......
......@@ -93,25 +93,6 @@ protected function getLabel(EntityInterface $entity) {
* {@inheritdoc}
*/
public function getOperations(EntityInterface $entity) {
$operations = $this->getDefaultOperations($entity);
$operations += $this->moduleHandler()->invokeAll('entity_operation', array($entity));
$this->moduleHandler->alter('entity_operation', $operations, $entity);
uasort($operations, '\Drupal\Component\Utility\SortArray::sortByWeightElement');
return $operations;
}
/**
* Gets this list's default operations.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity the operations are for.
*
* @return array
* The array structure is identical to the return value of
* self::getOperations().
*/
protected function getDefaultOperations(EntityInterface $entity) {
$operations = array();
if ($entity->access('update') && $entity->hasLinkTemplate('edit-form')) {
$operations['edit'] = array(
......@@ -170,11 +151,14 @@ public function buildRow(EntityInterface $entity) {
* @see \Drupal\Core\Entity\EntityListBuilder::buildRow()
*/
public function buildOperations(EntityInterface $entity) {
// Retrieve and sort operations.
$operations = $this->getOperations($entity);
$this->moduleHandler()->alter('entity_operation', $operations, $entity);
uasort($operations, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
$build = array(
'#type' => 'operations',
'#links' => $this->getOperations($entity),
'#links' => $operations,
);
return $build;
}
......
......@@ -101,8 +101,8 @@ public function buildHeader() {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = $entity->isConfigurable() ? parent::getDefaultOperations($entity) : array();
public function getOperations(EntityInterface $entity) {
$operations = $entity->isConfigurable() ? parent::getOperations($entity) : array();
if (isset($operations['edit'])) {
$operations['edit']['title'] = t('Configure');
}
......
......@@ -36,8 +36,8 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
if (isset($operations['edit'])) {
$operations['edit']['query']['destination'] = 'admin/structure/block/custom-blocks';
}
......
......@@ -20,8 +20,8 @@ class CustomBlockTypeListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
// Place the edit operation after the operations added by field_ui.module
// which have the weights 15, 20, 25.
if (isset($operations['edit'])) {
......
......@@ -378,8 +378,8 @@ public function buildForm(array $form, array &$form_state) {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
if (isset($operations['edit'])) {
$operations['edit']['title'] = t('Configure');
......
......@@ -159,18 +159,15 @@ function config_translation_config_translation_info(&$info) {
}
/**
* Implements hook_entity_operation().
* Implements hook_entity_operation_alter().
*/
function config_translation_entity_operation(EntityInterface $entity) {
$operations = array();
function config_translation_entity_operation_alter(array &$operations, EntityInterface $entity) {
if (\Drupal::currentUser()->hasPermission('translate configuration')) {
$operations['translate'] = array(
'title' => t('Translate'),
'weight' => 50,
) + $entity->urlInfo('drupal:config-translation-overview');
}
return $operations;
}
/**
......
......@@ -83,13 +83,13 @@ public function buildHeader() {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
foreach (array_keys($operations) as $operation) {
public function buildOperations(EntityInterface $entity) {
$operations = parent::buildOperations($entity);
foreach (array_keys($operations['#links']) as $operation) {
// This is a translation UI for translators. Show the translation
// operation only.
if (!($operation == 'translate')) {
unset($operations[$operation]);
unset($operations['#links'][$operation]);
}
}
return $operations;
......
......@@ -23,7 +23,6 @@
* id = "field_instance_config",
* label = @Translation("Field instance"),
* controllers = {
* "list_builder" = "\Drupal\Core\Config\Entity\ConfigEntityListBuilder",
* "storage" = "Drupal\field\FieldInstanceConfigStorageController"
* },
* config_prefix = "instance",
......
......@@ -172,10 +172,9 @@ function field_ui_form_node_type_form_alter(&$form, $form_state) {
}
/**
* Implements hook_entity_operation().
* Implements hook_entity_operation_alter().
*/
function field_ui_entity_operation(EntityInterface $entity) {
$operations = array();
function field_ui_entity_operation_alter(array &$operations, EntityInterface $entity) {
$info = $entity->getEntityType();
// Add manage fields and display links if this entity type is the bundle
// of another.
......@@ -199,8 +198,6 @@ function field_ui_entity_operation(EntityInterface $entity) {
) + $entity->urlInfo('field_ui-display');
}
}
return $operations;
}
/**
......
......@@ -7,7 +7,6 @@
namespace Drupal\field_ui;
use Drupal\Core\Entity\EntityListBuilderInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
......@@ -27,6 +26,13 @@ class FieldOverview extends OverviewBase {
*/
protected $fieldTypeManager;
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a new FieldOverview.
*
......@@ -34,10 +40,13 @@ class FieldOverview extends OverviewBase {
* The entity manager.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
* The field type manager
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke hooks on.
*/
public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager) {
public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, ModuleHandlerInterface $module_handler) {
parent::__construct($entity_manager);
$this->fieldTypeManager = $field_type_manager;
$this->moduleHandler = $module_handler;
}
/**
......@@ -46,7 +55,8 @@ public function __construct(EntityManagerInterface $entity_manager, FieldTypePlu
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('plugin.manager.field.field_type')
$container->get('plugin.manager.field.field_type'),
$container->get('module_handler')
);
}
......@@ -154,9 +164,11 @@ public function buildForm(array $form, array &$form_state, $entity_type_id = NUL
'route_parameters' => $route_parameters,
'attributes' => array('title' => $this->t('Delete instance.')),
);
// Allow altering the operations on this entity listing.
$this->moduleHandler->alter('entity_operation', $links, $instance);
$table[$name]['operations']['data'] = array(
'#type' => 'operations',
'#links' => $this->entityManager->getListBuilder('field_instance_config')->getOperations($instance),
'#links' => $links,
);
if (!empty($field->locked)) {
......
......@@ -118,8 +118,8 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
if (isset($operations['edit'])) {
$operations['edit']['title'] = t('Configure');
......
......@@ -74,13 +74,13 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
public function getOperations(EntityInterface $entity) {
$flush = array(
'title' => t('Flush'),
'weight' => 200,
) + $entity->urlInfo('flush-form');
return parent::getDefaultOperations($entity) + array('flush' => $flush);
return parent::getOperations($entity) + array('flush' => $flush);
}
/**
......
......@@ -44,8 +44,8 @@ public function getFormId() {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
$default = language_default();
// Deleting the site default language is not allowed.
......
......@@ -45,8 +45,8 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
if (isset($operations['edit'])) {
$operations['edit']['title'] = t('Edit menu');
......
......@@ -124,8 +124,8 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
protected function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
$destination = drupal_get_destination();
foreach ($operations as $key => $operation) {
......
......@@ -83,8 +83,8 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
// Place the edit operation after the operations added by field_ui.module
// which have the weights 15, 20, 25.
if (isset($operations['edit'])) {
......
......@@ -36,8 +36,8 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
$operations['duplicate'] = array(
'title' => t('Duplicate'),
'weight' => 15,
......
......@@ -260,9 +260,9 @@ public function buildForm(array $form, array &$form_state) {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
public function getOperations(EntityInterface $entity) {
/** @var $entity \Drupal\search\SearchPageInterface */
$operations = parent::getDefaultOperations($entity);
$operations = parent::getOperations($entity);
// Prevent the default search from being disabled or deleted.
if ($entity->isDefaultSearch()) {
......
......@@ -28,8 +28,8 @@ public function buildHeader() {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
if (isset($operations['edit'])) {
$operations['edit']['title'] = t('Edit shortcut set');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment