summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-07-12 15:33:44 (GMT)
committer Alex Pott2013-07-12 15:52:33 (GMT)
commite67580b16b10929e59f4034f747650180d2aac3e (patch)
tree473012fa9e4f67866f5953dec37f90f48266feea
parente5b197370604e193d9d7ce9bfaa493601343cd5b (diff)
Issue #2027857 by YesCT, kfritsche, penyaskito: Fixed Blocks operations cannot be altered.
-rw-r--r--core/modules/block/lib/Drupal/block/BlockListController.php35
-rw-r--r--core/modules/block/lib/Drupal/block/Tests/BlockHookOperationTest.php62
2 files changed, 85 insertions, 12 deletions
diff --git a/core/modules/block/lib/Drupal/block/BlockListController.php b/core/modules/block/lib/Drupal/block/BlockListController.php
index b150206..66774a7 100644
--- a/core/modules/block/lib/Drupal/block/BlockListController.php
+++ b/core/modules/block/lib/Drupal/block/BlockListController.php
@@ -9,6 +9,7 @@ namespace Drupal\block;
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 @@ class BlockListController extends ConfigEntityListController implements FormInte
'admin_label' => $definition['admin_label'],
'entity_id' => $entity_id,
'weight' => $entity->get('weight'),
+ 'entity' => $entity,
);
}
@@ -240,18 +242,7 @@ class BlockListController extends ConfigEntityListController implements FormInte
'class' => array('block-weight', 'block-weight-' . $region),
),
);
- $links['configure'] = array(
- 'title' => t('configure'),
- 'href' => 'admin/structure/block/manage/' . $entity_id,
- );
- $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,26 @@ class BlockListController extends ConfigEntityListController implements FormInte
}
/**
+ * {@inheritdoc}
+ */
+ public function getOperations(EntityInterface $entity) {
+ $uri = $entity->uri();
+ $operations = array();
+ $operations['configure'] = array(
+ 'title' => t('configure'),
+ 'href' => $uri['path'],
+ '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 @@
+<?php
+
+/**
+ * @file
+ * Tests for Block module regarding hook_entity_operations_alter().
+ */
+
+namespace Drupal\block\Tests;
+
+use Drupal\Component\Utility\Unicode;
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Functional tests for the hook_entity_operations_alter().
+ */
+class BlockHookOperationTest extends WebTestBase {
+
+ /**
+ * Modules to enable.
+ *
+ * @var array
+ */
+ public static $modules = array('block', 'entity_test');
+
+ public static function getInfo() {
+ return array(
+ 'name' => '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);
+ }
+
+}