commit 4a7e9e367814e2a9061766ac07b35b42bb0ea6d3 Author: Bart Feenstra Date: Sun Jun 8 17:48:03 2014 -0500 Comment 60 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 deleted file mode 100644 index 79f6f19..0000000 --- a/core/modules/views/lib/Drupal/views/Plugin/views/field/EntityOperations.php +++ /dev/null @@ -1,117 +0,0 @@ -entityManager = $entity_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity.manager')); - } - - /** - * {@inheritdoc} - */ - public function usesGroupBy() { - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function defineOptions() { - $options = parent::defineOptions(); - - $options['destination'] = array( - 'default' => TRUE, - 'bool' => TRUE, - ); - - return $options; - } - - /** - * {@inheritdoc} - */ - public function buildOptionsForm(&$form, &$form_state) { - parent::buildOptionsForm($form, $form_state); - - $form['destination'] = array( - '#type' => 'checkbox', - '#title' => $this->t('Include destination'), - '#description' => $this->t('Include a destination parameter in the link to return the user to the original view upon completing the link action.'), - '#default_value' => $this->options['destination'], - ); - } - - /** - * {@inheritdoc} - */ - public function render(ResultRow $values) { - $entity = $this->getEntity($values); - $operations = $this->entityManager->getListBuilder($entity->getEntityTypeId())->getOperations($entity); - if ($this->options['destination']) { - foreach ($operations as &$operation) { - if (!isset($operation['options']['query'])) { - $operation['options']['query'] = array(); - } - $operation['options']['query'] += drupal_get_destination(); - } - } - $build = array( - '#type' => 'operations', - '#links' => $operations, - ); - - return $build; - } - - /** - * {@inheritdoc} - */ - public function query() { - } - -} 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 deleted file mode 100644 index 39b7b93..0000000 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/views/field/EntityOperationsUnitTest.php +++ /dev/null @@ -1,180 +0,0 @@ - '', - 'name' => '\Drupal\views\Plugin\views\field\EntityOperations', - 'group' => 'Views Plugins', - ); - } - - /** - * {@inheritdoc} - * - * @covers ::__construct - */ - public function setUp() { - $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); - - $configuration = array(); - $plugin_id = $this->randomName(); - $plugin_definition = array( - 'title' => $this->randomName(), - ); - $this->plugin = new EntityOperations($configuration, $plugin_id, $plugin_definition, $this->entityManager); - $view = $this->getMockBuilder('\Drupal\views\ViewExecutable') - ->disableOriginalConstructor() - ->getMock(); - $display = $this->getMockBuilder('\Drupal\views\Plugin\views\display\DisplayPluginBase') - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - $view->display_handler = $display; - $this->plugin->init($view, $display); - } - - /** - * @covers ::usesGroupBy - */ - public function testUsesGroupBy() { - $this->assertFalse($this->plugin->usesGroupBy()); - } - - /** - * @covers ::defineOptions - */ - public function testDefineOptions() { - $options = $this->plugin->defineOptions(); - $this->assertInternalType('array', $options); - $this->assertArrayHasKey('destination', $options); - } - - /** - * @covers ::render - */ - public function testRenderWithDestination() { - $entity_type_id = $this->randomName(); - $entity = $this->getMockBuilder('\Drupal\user\Entity\Role') - ->disableOriginalConstructor() - ->getMock(); - $entity->expects($this->any()) - ->method('getEntityTypeId') - ->will($this->returnValue($entity_type_id)); - - $operations = array( - 'foo' => array( - 'title' => $this->randomName(), - ), - ); - $list_builder = $this->getMock('\Drupal\Core\Entity\EntityListBuilderInterface'); - $list_builder->expects($this->once()) - ->method('getOperations') - ->with($entity) - ->will($this->returnValue($operations)); - - $this->entityManager->expects($this->once()) - ->method('getListBuilder') - ->with($entity_type_id) - ->will($this->returnValue($list_builder)); - - $this->plugin->options['destination'] = TRUE; - - $result = new ResultRow(); - $result->_entity = $entity; - - $expected_build = array( - '#type' => 'operations', - '#links' => $operations - ); - $expected_build['#links']['foo']['options']['query'] = drupal_get_destination(); - $build = $this->plugin->render($result); - $this->assertSame($expected_build, $build); - } - - /** - * @covers ::render - */ - public function testRenderWithoutDestination() { - $entity_type_id = $this->randomName(); - $entity = $this->getMockBuilder('\Drupal\user\Entity\Role') - ->disableOriginalConstructor() - ->getMock(); - $entity->expects($this->any()) - ->method('getEntityTypeId') - ->will($this->returnValue($entity_type_id)); - - $operations = array( - 'foo' => array( - 'title' => $this->randomName(), - ), - ); - $list_builder = $this->getMock('\Drupal\Core\Entity\EntityListBuilderInterface'); - $list_builder->expects($this->once()) - ->method('getOperations') - ->with($entity) - ->will($this->returnValue($operations)); - - $this->entityManager->expects($this->once()) - ->method('getListBuilder') - ->with($entity_type_id) - ->will($this->returnValue($list_builder)); - - $this->plugin->options['destination'] = FALSE; - - $result = new ResultRow(); - $result->_entity = $entity; - - $expected_build = array( - '#type' => 'operations', - '#links' => $operations - ); - $build = $this->plugin->render($result); - $this->assertSame($expected_build, $build); - } -} - -} - -namespace { - -if (!function_exists('drupal_get_destination')) { - function drupal_get_destination() { - return array( - 'destination' => 'foobar', - ); - } -} - -} diff --git a/core/modules/views/src/Plugin/views/field/EntityOperations.php b/core/modules/views/src/Plugin/views/field/EntityOperations.php new file mode 100644 index 0000000..79f6f19 --- /dev/null +++ b/core/modules/views/src/Plugin/views/field/EntityOperations.php @@ -0,0 +1,117 @@ +entityManager = $entity_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity.manager')); + } + + /** + * {@inheritdoc} + */ + public function usesGroupBy() { + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function defineOptions() { + $options = parent::defineOptions(); + + $options['destination'] = array( + 'default' => TRUE, + 'bool' => TRUE, + ); + + return $options; + } + + /** + * {@inheritdoc} + */ + public function buildOptionsForm(&$form, &$form_state) { + parent::buildOptionsForm($form, $form_state); + + $form['destination'] = array( + '#type' => 'checkbox', + '#title' => $this->t('Include destination'), + '#description' => $this->t('Include a destination parameter in the link to return the user to the original view upon completing the link action.'), + '#default_value' => $this->options['destination'], + ); + } + + /** + * {@inheritdoc} + */ + public function render(ResultRow $values) { + $entity = $this->getEntity($values); + $operations = $this->entityManager->getListBuilder($entity->getEntityTypeId())->getOperations($entity); + if ($this->options['destination']) { + foreach ($operations as &$operation) { + if (!isset($operation['options']['query'])) { + $operation['options']['query'] = array(); + } + $operation['options']['query'] += drupal_get_destination(); + } + } + $build = array( + '#type' => 'operations', + '#links' => $operations, + ); + + return $build; + } + + /** + * {@inheritdoc} + */ + public function query() { + } + +} diff --git a/core/modules/views/src/Tests/Plugin/views/field/EntityOperationsUnitTest.php b/core/modules/views/src/Tests/Plugin/views/field/EntityOperationsUnitTest.php new file mode 100644 index 0000000..39b7b93 --- /dev/null +++ b/core/modules/views/src/Tests/Plugin/views/field/EntityOperationsUnitTest.php @@ -0,0 +1,180 @@ + '', + 'name' => '\Drupal\views\Plugin\views\field\EntityOperations', + 'group' => 'Views Plugins', + ); + } + + /** + * {@inheritdoc} + * + * @covers ::__construct + */ + public function setUp() { + $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + + $configuration = array(); + $plugin_id = $this->randomName(); + $plugin_definition = array( + 'title' => $this->randomName(), + ); + $this->plugin = new EntityOperations($configuration, $plugin_id, $plugin_definition, $this->entityManager); + $view = $this->getMockBuilder('\Drupal\views\ViewExecutable') + ->disableOriginalConstructor() + ->getMock(); + $display = $this->getMockBuilder('\Drupal\views\Plugin\views\display\DisplayPluginBase') + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $view->display_handler = $display; + $this->plugin->init($view, $display); + } + + /** + * @covers ::usesGroupBy + */ + public function testUsesGroupBy() { + $this->assertFalse($this->plugin->usesGroupBy()); + } + + /** + * @covers ::defineOptions + */ + public function testDefineOptions() { + $options = $this->plugin->defineOptions(); + $this->assertInternalType('array', $options); + $this->assertArrayHasKey('destination', $options); + } + + /** + * @covers ::render + */ + public function testRenderWithDestination() { + $entity_type_id = $this->randomName(); + $entity = $this->getMockBuilder('\Drupal\user\Entity\Role') + ->disableOriginalConstructor() + ->getMock(); + $entity->expects($this->any()) + ->method('getEntityTypeId') + ->will($this->returnValue($entity_type_id)); + + $operations = array( + 'foo' => array( + 'title' => $this->randomName(), + ), + ); + $list_builder = $this->getMock('\Drupal\Core\Entity\EntityListBuilderInterface'); + $list_builder->expects($this->once()) + ->method('getOperations') + ->with($entity) + ->will($this->returnValue($operations)); + + $this->entityManager->expects($this->once()) + ->method('getListBuilder') + ->with($entity_type_id) + ->will($this->returnValue($list_builder)); + + $this->plugin->options['destination'] = TRUE; + + $result = new ResultRow(); + $result->_entity = $entity; + + $expected_build = array( + '#type' => 'operations', + '#links' => $operations + ); + $expected_build['#links']['foo']['options']['query'] = drupal_get_destination(); + $build = $this->plugin->render($result); + $this->assertSame($expected_build, $build); + } + + /** + * @covers ::render + */ + public function testRenderWithoutDestination() { + $entity_type_id = $this->randomName(); + $entity = $this->getMockBuilder('\Drupal\user\Entity\Role') + ->disableOriginalConstructor() + ->getMock(); + $entity->expects($this->any()) + ->method('getEntityTypeId') + ->will($this->returnValue($entity_type_id)); + + $operations = array( + 'foo' => array( + 'title' => $this->randomName(), + ), + ); + $list_builder = $this->getMock('\Drupal\Core\Entity\EntityListBuilderInterface'); + $list_builder->expects($this->once()) + ->method('getOperations') + ->with($entity) + ->will($this->returnValue($operations)); + + $this->entityManager->expects($this->once()) + ->method('getListBuilder') + ->with($entity_type_id) + ->will($this->returnValue($list_builder)); + + $this->plugin->options['destination'] = FALSE; + + $result = new ResultRow(); + $result->_entity = $entity; + + $expected_build = array( + '#type' => 'operations', + '#links' => $operations + ); + $build = $this->plugin->render($result); + $this->assertSame($expected_build, $build); + } +} + +} + +namespace { + +if (!function_exists('drupal_get_destination')) { + function drupal_get_destination() { + return array( + 'destination' => 'foobar', + ); + } +} + +}