Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
301
Merge Requests
301
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
2cf87103
Commit
2cf87103
authored
Mar 26, 2014
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2165725
by Xano: Introduce hook_entity_operation().
parent
7f616204
Changes
25
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
191 additions
and
71 deletions
+191
-71
core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php
...lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php
+3
-2
core/lib/Drupal/Core/Entity/EntityListBuilder.php
core/lib/Drupal/Core/Entity/EntityListBuilder.php
+21
-5
core/modules/action/lib/Drupal/action/ActionListBuilder.php
core/modules/action/lib/Drupal/action/ActionListBuilder.php
+2
-2
core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListBuilder.php
..._block/lib/Drupal/custom_block/CustomBlockListBuilder.php
+2
-2
core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListBuilder.php
...ck/lib/Drupal/custom_block/CustomBlockTypeListBuilder.php
+2
-2
core/modules/block/lib/Drupal/block/BlockListBuilder.php
core/modules/block/lib/Drupal/block/BlockListBuilder.php
+2
-2
core/modules/config_translation/config_translation.module
core/modules/config_translation/config_translation.module
+5
-2
core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationEntityListBuilder.php
...slation/Controller/ConfigTranslationEntityListBuilder.php
+4
-4
core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php
...les/field/lib/Drupal/field/Entity/FieldInstanceConfig.php
+1
-0
core/modules/field_ui/field_ui.module
core/modules/field_ui/field_ui.module
+5
-2
core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
+4
-16
core/modules/filter/lib/Drupal/filter/FilterFormatListBuilder.php
...ules/filter/lib/Drupal/filter/FilterFormatListBuilder.php
+2
-2
core/modules/image/lib/Drupal/image/ImageStyleListBuilder.php
.../modules/image/lib/Drupal/image/ImageStyleListBuilder.php
+2
-2
core/modules/language/lib/Drupal/language/LanguageListBuilder.php
...ules/language/lib/Drupal/language/LanguageListBuilder.php
+2
-2
core/modules/menu/lib/Drupal/menu/MenuListBuilder.php
core/modules/menu/lib/Drupal/menu/MenuListBuilder.php
+2
-2
core/modules/node/lib/Drupal/node/NodeListBuilder.php
core/modules/node/lib/Drupal/node/NodeListBuilder.php
+2
-2
core/modules/node/lib/Drupal/node/NodeTypeListBuilder.php
core/modules/node/lib/Drupal/node/NodeTypeListBuilder.php
+2
-2
core/modules/responsive_image/lib/Drupal/responsive_image/ResponsiveImageMappingListBuilder.php
...al/responsive_image/ResponsiveImageMappingListBuilder.php
+2
-2
core/modules/search/lib/Drupal/search/SearchPageListBuilder.php
...odules/search/lib/Drupal/search/SearchPageListBuilder.php
+2
-2
core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetListBuilder.php
...s/shortcut/lib/Drupal/shortcut/ShortcutSetListBuilder.php
+2
-2
core/modules/system/entity.api.php
core/modules/system/entity.api.php
+26
-4
core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListBuilder.php
...es/taxonomy/lib/Drupal/taxonomy/VocabularyListBuilder.php
+2
-2
core/modules/user/lib/Drupal/user/RoleListBuilder.php
core/modules/user/lib/Drupal/user/RoleListBuilder.php
+2
-2
core/modules/views_ui/lib/Drupal/views_ui/ViewListBuilder.php
.../modules/views_ui/lib/Drupal/views_ui/ViewListBuilder.php
+2
-2
core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php
.../tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php
+90
-4
No files found.
core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php
View file @
2cf87103
...
...
@@ -30,8 +30,9 @@ public function load() {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
public
function
getDefaultOperations
(
EntityInterface
$entity
)
{
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
$operations
=
parent
::
getDefaultOperations
(
$entity
);
if
(
$this
->
entityType
->
hasKey
(
'status'
))
{
if
(
!
$entity
->
status
()
&&
$entity
->
hasLinkTemplate
(
'enable'
))
{
...
...
core/lib/Drupal/Core/Entity/EntityListBuilder.php
View file @
2cf87103
...
...
@@ -93,6 +93,25 @@ 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
(
...
...
@@ -151,14 +170,11 @@ 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'
=>
$
operations
,
'#links'
=>
$
this
->
getOperations
(
$entity
)
,
);
return
$build
;
}
...
...
core/modules/action/lib/Drupal/action/ActionListBuilder.php
View file @
2cf87103
...
...
@@ -101,8 +101,8 @@ public function buildHeader() {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
$entity
->
isConfigurable
()
?
parent
::
getOperations
(
$entity
)
:
array
();
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
$operations
=
$entity
->
isConfigurable
()
?
parent
::
get
Default
Operations
(
$entity
)
:
array
();
if
(
isset
(
$operations
[
'edit'
]))
{
$operations
[
'edit'
][
'title'
]
=
t
(
'Configure'
);
}
...
...
core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListBuilder.php
View file @
2cf87103
...
...
@@ -36,8 +36,8 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
get
Default
Operations
(
$entity
);
if
(
isset
(
$operations
[
'edit'
]))
{
$operations
[
'edit'
][
'query'
][
'destination'
]
=
'admin/structure/block/custom-blocks'
;
}
...
...
core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListBuilder.php
View file @
2cf87103
...
...
@@ -20,8 +20,8 @@ class CustomBlockTypeListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
get
Default
Operations
(
$entity
);
// Place the edit operation after the operations added by field_ui.module
// which have the weights 15, 20, 25.
if
(
isset
(
$operations
[
'edit'
]))
{
...
...
core/modules/block/lib/Drupal/block/BlockListBuilder.php
View file @
2cf87103
...
...
@@ -378,8 +378,8 @@ public function buildForm(array $form, array &$form_state) {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
get
Default
Operations
(
$entity
);
if
(
isset
(
$operations
[
'edit'
]))
{
$operations
[
'edit'
][
'title'
]
=
t
(
'Configure'
);
...
...
core/modules/config_translation/config_translation.module
View file @
2cf87103
...
...
@@ -159,15 +159,18 @@ function config_translation_config_translation_info(&$info) {
}
/**
* Implements hook_entity_operation
_alter
().
* Implements hook_entity_operation().
*/
function
config_translation_entity_operation_alter
(
array
&
$operations
,
EntityInterface
$entity
)
{
function
config_translation_entity_operation
(
EntityInterface
$entity
)
{
$operations
=
array
();
if
(
\
Drupal
::
currentUser
()
->
hasPermission
(
'translate configuration'
))
{
$operations
[
'translate'
]
=
array
(
'title'
=>
t
(
'Translate'
),
'weight'
=>
50
,
)
+
$entity
->
urlInfo
(
'drupal:config-translation-overview'
);
}
return
$operations
;
}
/**
...
...
core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationEntityListBuilder.php
View file @
2cf87103
...
...
@@ -83,13 +83,13 @@ public function buildHeader() {
/**
* {@inheritdoc}
*/
public
function
build
Operations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
build
Operations
(
$entity
);
foreach
(
array_keys
(
$operations
[
'#links'
]
)
as
$operation
)
{
public
function
getDefault
Operations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getDefault
Operations
(
$entity
);
foreach
(
array_keys
(
$operations
)
as
$operation
)
{
// This is a translation UI for translators. Show the translation
// operation only.
if
(
!
(
$operation
==
'translate'
))
{
unset
(
$operations
[
'#links'
][
$operation
]);
unset
(
$operations
[
$operation
]);
}
}
return
$operations
;
...
...
core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php
View file @
2cf87103
...
...
@@ -23,6 +23,7 @@
* id = "field_instance_config",
* label = @Translation("Field instance"),
* controllers = {
* "list_builder" = "\Drupal\Core\Config\Entity\ConfigEntityListBuilder",
* "storage" = "Drupal\field\FieldInstanceConfigStorageController"
* },
* config_prefix = "instance",
...
...
core/modules/field_ui/field_ui.module
View file @
2cf87103
...
...
@@ -172,9 +172,10 @@ function field_ui_form_node_type_form_alter(&$form, $form_state) {
}
/**
* Implements hook_entity_operation
_alter
().
* Implements hook_entity_operation().
*/
function
field_ui_entity_operation_alter
(
array
&
$operations
,
EntityInterface
$entity
)
{
function
field_ui_entity_operation
(
EntityInterface
$entity
)
{
$operations
=
array
();
$info
=
$entity
->
getEntityType
();
// Add manage fields and display links if this entity type is the bundle
// of another.
...
...
@@ -198,6 +199,8 @@ function field_ui_entity_operation_alter(array &$operations, EntityInterface $en
)
+
$entity
->
urlInfo
(
'field_ui-display'
);
}
}
return
$operations
;
}
/**
...
...
core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
View file @
2cf87103
...
...
@@ -7,6 +7,7 @@
namespace
Drupal\field_ui
;
use
Drupal\Core\Entity\EntityListBuilderInterface
;
use
Drupal\Core\Entity\EntityManagerInterface
;
use
Drupal\Core\Extension\ModuleHandlerInterface
;
use
Drupal\Core\Field\FieldTypePluginManagerInterface
;
...
...
@@ -26,13 +27,6 @@ class FieldOverview extends OverviewBase {
*/
protected
$fieldTypeManager
;
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected
$moduleHandler
;
/**
* Constructs a new FieldOverview.
*
...
...
@@ -40,13 +34,10 @@ 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
,
ModuleHandlerInterface
$module_handler
)
{
public
function
__construct
(
EntityManagerInterface
$entity_manager
,
FieldTypePluginManagerInterface
$field_type_manager
)
{
parent
::
__construct
(
$entity_manager
);
$this
->
fieldTypeManager
=
$field_type_manager
;
$this
->
moduleHandler
=
$module_handler
;
}
/**
...
...
@@ -55,8 +46,7 @@ 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
(
'module_handler'
)
$container
->
get
(
'plugin.manager.field.field_type'
)
);
}
...
...
@@ -164,11 +154,9 @@ 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'
=>
$
links
,
'#links'
=>
$
this
->
entityManager
->
getListBuilder
(
'field_instance_config'
)
->
getOperations
(
$instance
)
,
);
if
(
!
empty
(
$field
->
locked
))
{
...
...
core/modules/filter/lib/Drupal/filter/FilterFormatListBuilder.php
View file @
2cf87103
...
...
@@ -118,8 +118,8 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
get
Default
Operations
(
$entity
);
if
(
isset
(
$operations
[
'edit'
]))
{
$operations
[
'edit'
][
'title'
]
=
t
(
'Configure'
);
...
...
core/modules/image/lib/Drupal/image/ImageStyleListBuilder.php
View file @
2cf87103
...
...
@@ -74,13 +74,13 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
$flush
=
array
(
'title'
=>
t
(
'Flush'
),
'weight'
=>
200
,
)
+
$entity
->
urlInfo
(
'flush-form'
);
return
parent
::
getOperations
(
$entity
)
+
array
(
'flush'
=>
$flush
);
return
parent
::
get
Default
Operations
(
$entity
)
+
array
(
'flush'
=>
$flush
);
}
/**
...
...
core/modules/language/lib/Drupal/language/LanguageListBuilder.php
View file @
2cf87103
...
...
@@ -44,8 +44,8 @@ public function getFormId() {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
get
Default
Operations
(
$entity
);
$default
=
language_default
();
// Deleting the site default language is not allowed.
...
...
core/modules/menu/lib/Drupal/menu/MenuListBuilder.php
View file @
2cf87103
...
...
@@ -45,8 +45,8 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
get
Default
Operations
(
$entity
);
if
(
isset
(
$operations
[
'edit'
]))
{
$operations
[
'edit'
][
'title'
]
=
t
(
'Edit menu'
);
...
...
core/modules/node/lib/Drupal/node/NodeListBuilder.php
View file @
2cf87103
...
...
@@ -124,8 +124,8 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
p
ublic
function
ge
tOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
p
rotected
function
getDefaul
tOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
get
Default
Operations
(
$entity
);
$destination
=
drupal_get_destination
();
foreach
(
$operations
as
$key
=>
$operation
)
{
...
...
core/modules/node/lib/Drupal/node/NodeTypeListBuilder.php
View file @
2cf87103
...
...
@@ -83,8 +83,8 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
get
Default
Operations
(
$entity
);
// Place the edit operation after the operations added by field_ui.module
// which have the weights 15, 20, 25.
if
(
isset
(
$operations
[
'edit'
]))
{
...
...
core/modules/responsive_image/lib/Drupal/responsive_image/ResponsiveImageMappingListBuilder.php
View file @
2cf87103
...
...
@@ -36,8 +36,8 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
get
Default
Operations
(
$entity
);
$operations
[
'duplicate'
]
=
array
(
'title'
=>
t
(
'Duplicate'
),
'weight'
=>
15
,
...
...
core/modules/search/lib/Drupal/search/SearchPageListBuilder.php
View file @
2cf87103
...
...
@@ -260,9 +260,9 @@ public function buildForm(array $form, array &$form_state) {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
/** @var $entity \Drupal\search\SearchPageInterface */
$operations
=
parent
::
getOperations
(
$entity
);
$operations
=
parent
::
get
Default
Operations
(
$entity
);
// Prevent the default search from being disabled or deleted.
if
(
$entity
->
isDefaultSearch
())
{
...
...
core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetListBuilder.php
View file @
2cf87103
...
...
@@ -28,8 +28,8 @@ public function buildHeader() {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
get
Default
Operations
(
$entity
);
if
(
isset
(
$operations
[
'edit'
]))
{
$operations
[
'edit'
][
'title'
]
=
t
(
'Edit shortcut set'
);
...
...
core/modules/system/entity.api.php
View file @
2cf87103
...
...
@@ -754,6 +754,27 @@ function hook_entity_bundle_field_info_alter(&$fields, \Drupal\Core\Entity\Entit
}
}
/**
* Declares entity operations.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity on which the linked operations will be performed.
*
* @return array
* An operations array as returned by
* \Drupal\Core\Entity\EntityListBuilderInterface::getOperations().
*/
function
hook_entity_operation
(
\
Drupal\Core\Entity\EntityInterface
$entity
)
{
$operations
=
array
();
$operations
[
'translate'
]
=
array
(
'title'
=>
t
(
'Translate'
),
'route_name'
=>
'foo_module.entity.translate'
,
'weight'
=>
50
,
);
return
$operations
;
}
/**
* Alter entity operations.
*
...
...
@@ -764,10 +785,11 @@ function hook_entity_bundle_field_info_alter(&$fields, \Drupal\Core\Entity\Entit
* The entity on which the linked operations will be performed.
*/
function
hook_entity_operation_alter
(
array
&
$operations
,
\
Drupal\Core\Entity\EntityInterface
$entity
)
{
$operations
[
'translate'
]
=
array
(
'title'
=>
t
(
'Translate'
),
'weight'
=>
50
,
)
+
$entity
->
urlInfo
(
'my-custom-link-template'
);
// Alter the title and weight.
$operations
[
'translate'
][
'title'
]
=
t
(
'Translate @entity_type'
,
array
(
'@entity_type'
=>
$entity
->
getEntityTypeId
(),
));
$operations
[
'translate'
][
'weight'
]
=
99
;
}
/**
...
...
core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListBuilder.php
View file @
2cf87103
...
...
@@ -32,8 +32,8 @@ public function getFormId() {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
get
Default
Operations
(
$entity
);
if
(
isset
(
$operations
[
'edit'
]))
{
$operations
[
'edit'
][
'title'
]
=
t
(
'edit vocabulary'
);
...
...
core/modules/user/lib/Drupal/user/RoleListBuilder.php
View file @
2cf87103
...
...
@@ -43,8 +43,8 @@ public function buildRow(EntityInterface $entity) {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
get
Default
Operations
(
$entity
);
if
(
$entity
->
hasLinkTemplate
(
'edit-permissions-form'
))
{
$operations
[
'permissions'
]
=
array
(
...
...
core/modules/views_ui/lib/Drupal/views_ui/ViewListBuilder.php
View file @
2cf87103
...
...
@@ -135,8 +135,8 @@ public function buildHeader() {
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
public
function
get
Default
Operations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
get
Default
Operations
(
$entity
);
if
(
$entity
->
hasLinkTemplate
(
'clone'
))
{
$operations
[
'clone'
]
=
array
(
...
...
core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php
View file @
2cf87103
...
...
@@ -7,7 +7,9 @@
namespace
Drupal\Tests\Core\Entity
;
use
Drupal\Core\DependencyInjection\ContainerBuilder
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\EntityListBuilder
;
use
Drupal\entity_test
\
EntityTestListBuilder
;
use
Drupal\Tests\UnitTestCase
;
...
...
@@ -20,6 +22,41 @@
*/
class
EntityListBuilderTest
extends
UnitTestCase
{
/**
* The entity type used for testing.
*
* @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected
$entityType
;
/**
* The module handler used for testing.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected
$moduleHandler
;
/**
* The translation manager used for testing.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface
*/
protected
$translationManager
;
/**
* The role storage used for testing.
*
* @var \Drupal\user\RoleStorageControllerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected
$roleStorage
;
/**
* The service container used for testing.
*
* @var \Drupal\Core\DependencyInjection\ContainerBuilder
*/
protected
$container
;
/**
* The entity used to construct the EntityListBuilder.
*
...
...
@@ -49,10 +86,59 @@ protected function setUp() {
parent
::
setUp
();
$this
->
role
=
$this
->
getMock
(
'Drupal\user\RoleInterface'
);
$role_storage_controller
=
$this
->
getMock
(
'Drupal\user\RoleStorageControllerInterface'
);
$module_handler
=
$this
->
getMock
(
'Drupal\Core\Extension\ModuleHandlerInterface'
);
$entity_type
=
$this
->
getMock
(
'Drupal\Core\Entity\EntityTypeInterface'
);
$this
->
entityListBuilder
=
new
TestEntityListBuilder
(
$entity_type
,
$role_storage_controller
,
$module_handler
);
$this
->
roleStorage
=
$this
->
getMock
(
'\Drupal\user\RoleStorageControllerInterface'
);
$this
->
moduleHandler
=
$this
->
getMock
(
'\Drupal\Core\Extension\ModuleHandlerInterface'
);
$this
->
entityType
=
$this
->
getMock
(
'\Drupal\Core\Entity\EntityTypeInterface'
);
$this
->
translationManager
=
$this
->
getMock
(
'\Drupal\Core\StringTranslation\TranslationInterface'
);
$this
->
entityListBuilder
=
new
TestEntityListBuilder
(
$this
->
entityType
,
$this
->
roleStorage
,
$this
->
moduleHandler
);
$this
->
container
=
new
ContainerBuilder
();
\
Drupal
::
setContainer
(
$this
->
container
);
}
/**
* @covers \Drupal\Core\Entity\EntityListBuilder::getOperations
*/
public
function
testGetOperations
()
{
$operation_name
=
$this
->
randomName
();
$operations
=
array
(
$operation_name
=>
array
(
'title'
=>
$this
->
randomName
(),
),
);
$this
->
moduleHandler
->
expects
(
$this
->
once
())
->
method
(
'invokeAll'
)
->
with
(
'entity_operation'
,
array
(
$this
->
role
))
->
will
(
$this
->
returnValue
(
$operations
));
$this
->
moduleHandler
->
expects
(
$this
->
once
())
->
method
(
'alter'
)
->
with
(
'entity_operation'
);
$this
->
container
->
set
(
'module_handler'
,
$this
->
moduleHandler
);
$this
->
role
->
expects
(
$this
->
any
())
->
method
(
'access'
)
->
will
(
$this
->
returnValue
(
TRUE
));
$this
->
role
->
expects
(
$this
->
any
())
->
method
(
'hasLinkTemplate'
)
->
will
(
$this
->
returnValue
(
TRUE
));
$this
->
role
->
expects
(
$this
->
any
())
->
method
(
'urlInfo'
)
->
will
(
$this
->
returnValue
(
array
()));
$list
=
new
EntityListBuilder
(
$this
->
entityType
,
$this
->
roleStorage
,
$this
->
moduleHandler
);
$list
->
setTranslationManager
(
$this
->
translationManager
);
$operations
=
$list
->
getOperations
(
$this
->
role
);
$this
->
assertInternalType
(
'array'
,
$operations
);
$this
->
assertArrayHasKey
(
'edit'
,
$operations
);
$this
->
assertInternalType
(
'array'
,
$operations
[
'edit'
]);
$this
->
assertArrayHasKey
(
'title'
,
$operations
[
'edit'
]);
$this
->
assertArrayHasKey
(
'delete'
,
$operations
);
$this
->
assertInternalType
(
'array'
,
$operations
[
'delete'
]);
$this
->
assertArrayHasKey
(
'title'
,
$operations
[
'delete'
]);
$this
->
assertArrayHasKey
(
$operation_name
,
$operations
);
$this
->
assertInternalType
(
'array'
,
$operations
[
$operation_name
]);
$this
->
assertArrayHasKey
(
'title'
,
$operations
[
$operation_name
]);
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment