commit 9b684e6fdaf600936d22e962efa1c2045400236c Author: Bart Feenstra Date: Fri Jan 3 00:20:01 2014 +0100 bar diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/field/EntityOperations.php b/core/modules/views/lib/Drupal/views/Plugin/views/field/EntityOperations.php index d38b3f9..1b153d4 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/field/EntityOperations.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/field/EntityOperations.php @@ -14,11 +14,6 @@ /** * Renders all operations links for an entity. * - * Every definition of this handler in a hook_views_data() implementation must - * contain the following two keys: - * - entity_type: the entity type's machine name. - * - id_field: the name of the field that contains the entity IDs. - * * @ingroup views_field_handlers * * @PluginID("views_entity_operations") @@ -95,9 +90,27 @@ public function buildOptionsForm(&$form, &$form_state) { * {@inheritdoc} */ public function render(ResultRow $values) { - if ($entity = $this->getEntity($values)) { - return $this->entityList->buildOperations($entity); + $entity = $this->getEntity($values); + if ($entity) { + $operations = $this->entityList->getOperations($entity); + if ($this->options['destination']) { + foreach ($operations as &$operation) { + $operation['options']['query'] += $this->drupalGetDestination(); + } + } + $build = array( + '#type' => 'operations', + '#links' => $operations, + ); + + return $build; } } + /** + * Wraps drupal_get_destination(). + */ + protected function drupalGetDestination() { + return drupal_get_destination(); + } } diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/views/field/EntityOperationsUnitTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/views/field/EntityOperationsUnitTest.php new file mode 100644 index 0000000..9337ba2 --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/views/field/EntityOperationsUnitTest.php @@ -0,0 +1,119 @@ + '', + 'name' => '\Drupal\views\Plugin\views\field\EntityOperations', + 'group' => 'Views Plugins', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + $this->entityList = $this->getMock('\Drupal\Core\Entity\EntityListControllerInterface'); + + $configuration = array(); + $plugin_id = $this->randomName(); + $plugin_definition = array(); + $this->plugin = $this->getMockBuilder('\Drupal\views\Plugin\views\field\EntityOperations') + ->setConstructorArgs(array($configuration, $plugin_id, $plugin_definition, $this->entityList)) + ->setMethods(array('drupalGetDestination', 'getEntity', 't')) + ->getMock(); + } + + /** + * Tests usesGroupBy(). + */ + public function testUsesGroupBy() { + $this->assertFalse($this->plugin->usesGroupBy()); + } + + /** + * Tests buildOptionsForm(). + */ + public function testBuildOptionsForm() { + $form = array(); + $form_state = array(); + $this->assertInternalType('array', $this->plugin->buildOptionsForm($form, $form_state)); + } + + /** + * Tests defineOptions(). + */ + public function testDefineOptions() { + $this->assertInternalType('array', $this->plugin->defineOptions()); + } + + /** + * Tests render(). + */ + public function testRenderWithDestination() { + $entity = $this->getMockBuilder('\Drupal\user\Entity\Role') + ->disableOriginalConstructor() + ->getMock(); + $this->plugin->expects($this->any()) + ->method('getEntity') + ->will($this->returnValue($entity)); + $this->plugin->expects($this->once()) + ->method('drupalGetDestination') + ->will($this->returnValue(array())); + $this->plugin->options['destination'] = TRUE; + + $result = $this->getMock('\Drupal\views\ResultRow'); + + $build = $this->plugin->render($result); + $this->assertInternalType('array', $build); + } + + /** + * Tests render(). + */ + public function testRenderWithoutDestination() { + $entity = $this->getMockBuilder('\Drupal\user\Entity\Role') + ->disableOriginalConstructor() + ->getMock(); + $this->plugin->expects($this->any()) + ->method('getEntity') + ->will($this->returnValue($entity)); + $this->plugin->expects($this->never()) + ->method('drupalGetDestination'); + $this->plugin->options['destination'] = FALSE; + + $result = $this->getMock('\Drupal\views\ResultRow'); + + $build = $this->plugin->render($result); + $this->assertInternalType('array', $build); + } +}