diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityOperationsTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityOperationsTest.php new file mode 100644 index 0000000..a9c5319 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityOperationsTest.php @@ -0,0 +1,55 @@ + 'Entity Operations', + 'description' => 'Check that operations can be injected from the hook.', + 'group' => 'Entity API', + ); + } + + public function setUp() { + parent::setUp(); + + // Create and login user. + $this->web_user = $this->drupalCreateUser(array( + 'administer permissions', + )); + $this->drupalLogin($this->web_user); + } + + /** + * Check hook_entity_operation_alter hook is executed. + */ + public function testEntityOperationAlter() { + // Check that role listing contain our test_operation operation. + $this->drupalGet('admin/people/roles'); + $roles = user_roles(); + foreach ($roles as $role) { + $uri = $role->uri(); + $this->assertLinkByHref($uri['path'] . '/test_operation'); + $this->assertLink('Test Operation: ' . $role->label()); + } + } +} diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 3ba9e09..4a39f90 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -381,7 +381,7 @@ function entity_test_entity_form_display_alter(EntityFormDisplay $form_display, } /** - * Implements hook_entity_presave() + * Implements hook_entity_presave(). */ function entity_test_entity_presave(EntityInterface $entity) { if (isset($GLOBALS['entity_test_throw_exception'])) { @@ -390,10 +390,22 @@ function entity_test_entity_presave(EntityInterface $entity) { } /** - * Implements hook_entity_predelete() + * Implements hook_entity_predelete(). */ function entity_test_entity_predelete(EntityInterface $entity) { if (isset($GLOBALS['entity_test_throw_exception'])) { throw new Exception('Entity predelete exception', 2); } } + +/** + * Implements hook_entity_operation_alter(). + */ +function entity_test_entity_operation_alter(array &$operations, EntityInterface $entity) { + $uri = $entity->uri(); + $operations['test_operation'] = array( + 'title' => 'Test Operation: ' . $entity->label(), + 'href' => $uri['path'] . '/test_operation', + 'weight' => 50, + ); +} \ No newline at end of file