diff --git a/core/modules/block/lib/Drupal/block/BlockListController.php b/core/modules/block/lib/Drupal/block/BlockListController.php index 6a5a2ed..8d87de1 100644 --- a/core/modules/block/lib/Drupal/block/BlockListController.php +++ b/core/modules/block/lib/Drupal/block/BlockListController.php @@ -9,6 +9,7 @@ use Drupal\Core\Config\Entity\ConfigEntityListController; use Drupal\block\Plugin\Core\Entity\Block; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormInterface; /** @@ -148,6 +149,7 @@ public function buildForm(array $form, array &$form_state) { 'admin_label' => $definition['admin_label'], 'entity_id' => $entity_id, 'weight' => $entity->get('weight'), + 'entity' => $entity, ); } @@ -240,18 +242,7 @@ public function buildForm(array $form, array &$form_state) { 'class' => array('block-weight', 'block-weight-' . $region), ), ); - $links['configure'] = array( - 'title' => t('configure'), - 'href' => 'admin/structure/block/manage/' . $entity_id . '/configure', - ); - $links['delete'] = array( - 'title' => t('delete'), - 'href' => 'admin/structure/block/manage/' . $entity_id . '/delete', - ); - $form['blocks'][$entity_id]['operations'] = array( - '#type' => 'operations', - '#links' => $links, - ); + $form['blocks'][$entity_id]['operations'] = $this->buildOperations($info['entity']); } } } @@ -274,6 +265,25 @@ public function buildForm(array $form, array &$form_state) { } /** + * {@inheritdoc} + */ + public function getOperations(EntityInterface $entity) { + $uri = $entity->uri(); + $operations = array(); + $operations['configure'] = array( + 'title' => t('configure'), + 'href' => $uri['path'] . '/configure', + 'options' => $uri['options'], + ); + $operations['delete'] = array( + 'title' => t('delete'), + 'href' => $uri['path'] . '/delete', + 'options' => $uri['options'], + ); + return $operations; + } + + /** * Implements \Drupal\Core\Form\FormInterface::validateForm(). */ public function validateForm(array &$form, array &$form_state) { diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockHookOperationTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockHookOperationTest.php new file mode 100644 index 0000000..3621f26 --- /dev/null +++ b/core/modules/block/lib/Drupal/block/Tests/BlockHookOperationTest.php @@ -0,0 +1,62 @@ + 'Block operations hook', + 'description' => 'Implement hook entity operations alter.', + 'group' => 'Block', + ); + } + + public function setUp() { + parent::setUp(); + + $permissions = array( + 'administer blocks', + ); + + // Create and log in user. + $admin_user = $this->drupalCreateUser($permissions); + $this->drupalLogin($admin_user); + } + + /* + * Tests the block list to see if the test_operation link is added. + */ + public function testBlockOperationAlter() { + // Add a test block, any block will do. + // Set the machine name so the test_operation link can be built later. + $block_machine_name = Unicode::strtolower($this->randomName(16)); + $this->drupalPlaceBlock('system_powered_by_block', array('machine_name' => $block_machine_name)); + + // Get the Block listing. + $this->drupalGet('admin/structure/block'); + + $test_operation_link = 'admin/structure/block/manage/stark.' . $block_machine_name . '/test_operation'; + // Test if the test_operation link is on the page. + $this->assertLinkByHref($test_operation_link); + } + +}