Issue #2027857 by YesCT, kfritsche, penyaskito: Fixed Blocks operations cannot be altered.

8.0.x
Alex Pott 2013-07-12 11:33:44 -04:00
parent e5b1973706
commit e67580b16b
2 changed files with 85 additions and 12 deletions

View File

@ -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']);
}
}
}
@ -273,6 +264,26 @@ class BlockListController extends ConfigEntityListController implements FormInte
return $form;
}
/**
* {@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().
*/

View File

@ -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);
}
}