Commit 2f872b85 authored by alexpott's avatar alexpott

Issue #2016939 by tim.plunkett, dawehner: Views listing page links are broken...

Issue #2016939 by tim.plunkett, dawehner: Views listing page links are broken for default task page displays.
parent 39cc830a
......@@ -10,6 +10,7 @@
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Plugin\PluginBag;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Component\Utility\MapArray;
/**
* A class which wraps the displays of a view so you can lazy-initialize them.
......@@ -46,7 +47,7 @@ public function __construct(ViewExecutable $view, PluginManagerInterface $manage
// Store all display IDs to access them easy and fast.
$display = $this->view->storage->get('display');
$this->instanceIDs = drupal_map_assoc(array_keys($display));
$this->instanceIDs = MapArray::copyValuesToKeys(array_keys($display));
}
/**
......
......@@ -290,34 +290,6 @@ public function &getDisplay($display_id) {
return $this->display[$display_id];
}
/**
* Gets a list of paths assigned to the view.
*
* @return array
* An array of paths for this view.
*/
public function getPaths() {
$all_paths = array();
if (empty($this->display)) {
$all_paths[] = t('Edit this view to add a display.');
}
else {
foreach ($this->display as $display) {
if (!empty($display['display_options']['path'])) {
$path = $display['display_options']['path'];
if ($this->status() && strpos($path, '%') === FALSE) {
$all_paths[] = l('/' . $path, $path);
}
else {
$all_paths[] = check_plain('/' . $path);
}
}
}
}
return array_unique($all_paths);
}
/**
* Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::getExportProperties();
*/
......
......@@ -221,14 +221,6 @@ protected function displayMethodTests() {
);
$view = $this->controller->create($config);
// Paths with a "%" shouldn't not be linked
$expected_paths = array();
$expected_paths[] = l('/test', 'test');
$expected_paths[] = l('/test.xml', 'test.xml');
$expected_paths[] = '/test/%/extra';
$this->assertEqual($view->getPaths(), $expected_paths, 'Make sure the paths in the ui are generated as expected.');
// Tests Drupal\views\Plugin\Core\Entity\View::addDisplay()
$view = $this->controller->create(array());
$random_title = $this->randomName();
......
......@@ -17,7 +17,7 @@ class DefaultViewsTest extends UITestBase {
*
* @var array
*/
public static $testViews = array('test_view_status');
public static $testViews = array('test_view_status', 'test_page_display_menu', 'test_page_display_arguments');
public static function getInfo() {
return array(
......@@ -157,6 +157,22 @@ function testSplitListing() {
$this->assertIdentical(count($elements), 1, 'After enabling a view, it is found in the enabled views table.');
}
/**
* Tests that page displays show the correct path.
*/
public function testPathDestination() {
$this->drupalGet('admin/structure/views');
// Check that links to views on default tabs are rendered correctly.
$this->assertLinkByHref('test_page_display_menu');
$this->assertNoLinkByHref('test_page_display_menu/default');
$this->assertLinkByHref('test_page_display_menu/local');
// Check that a dynamic path is shown as text.
$this->assertRaw('test_route_with_suffix/%/suffix');
$this->assertNoLinkByHref(url('test_route_with_suffix/%/suffix'));
}
/**
* Click a link to perform an operation on a view.
*
......
......@@ -2,11 +2,12 @@
/**
* @file
* Definition of Drupal\views_ui\ViewListController.
* Contains \Drupal\views_ui\ViewListController.
*/
namespace Drupal\views_ui;
use Drupal\Component\Utility\String;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Config\Entity\ConfigEntityListController;
......@@ -61,7 +62,7 @@ public function __construct($entity_type, EntityStorageControllerInterface $stor
}
/**
* Overrides Drupal\Core\Entity\EntityListController::load();
* {@inheritdoc}
*/
public function load() {
$entities = array(
......@@ -80,7 +81,7 @@ public function load() {
}
/**
* Overrides Drupal\Core\Entity\EntityListController::buildRow();
* {@inheritdoc}
*/
public function buildRow(EntityInterface $view) {
return array(
......@@ -94,18 +95,18 @@ public function buildRow(EntityInterface $view) {
),
'description' => $view->get('description'),
'tag' => $view->get('tag'),
'path' => implode(', ', $view->getPaths()),
'path' => implode(', ', $this->getDisplayPaths($view)),
'operations' => array(
'data' => $this->buildOperations($view),
),
),
'title' => t('Machine name: ') . $view->id(),
'title' => t('Machine name: @name', array('@name' => $view->id())),
'class' => array($view->status() ? 'views-ui-list-enabled' : 'views-ui-list-disabled'),
);
}
/**
* Overrides Drupal\Core\Entity\EntityListController::buildHeader();
* {@inheritdoc}
*/
public function buildHeader() {
return array(
......@@ -157,7 +158,7 @@ public function getOperations(EntityInterface $entity) {
}
/**
* Overrides Drupal\Core\Entity\EntityListController::buildOperations();
* {@inheritdoc}
*/
public function buildOperations(EntityInterface $entity) {
$build = parent::buildOperations($entity);
......@@ -173,7 +174,7 @@ public function buildOperations(EntityInterface $entity) {
}
/**
* Overrides Drupal\Core\Entity\EntityListController::render();
* {@inheritdoc}
*/
public function render() {
$entities = $this->load();
......@@ -225,4 +226,31 @@ protected function getDisplaysList(EntityInterface $view) {
return array_keys($displays);
}
/**
* Gets a list of paths assigned to the view.
*
* @param \Drupal\Core\Entity\EntityInterface $view
* The view entity.
*
* @return array
* An array of paths for this view.
*/
protected function getDisplayPaths(EntityInterface $view) {
$all_paths = array();
$executable = $view->get('executable');
$executable->initDisplay();
foreach ($executable->displayHandlers as $display) {
if ($display->hasPath()) {
$path = $display->getPath();
if ($view->status() && strpos($path, '%') === FALSE) {
$all_paths[] = l('/' . $path, $path);
}
else {
$all_paths[] = String::checkPlain('/' . $path);
}
}
}
return array_unique($all_paths);
}
}
......@@ -8,9 +8,10 @@
namespace Drupal\views_ui\Tests {
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
use Drupal\views\Plugin\Core\Entity\View;
use Drupal\views_ui\ViewListController;
use Drupal\views\ViewExecutableFactory;
class ViewListControllerTest extends UnitTestCase {
......@@ -35,6 +36,7 @@ public function testBuildRowEntityList() {
$display_manager = $this->getMockBuilder('\Drupal\views\Plugin\ViewsPluginManager')
->disableOriginalConstructor()
->getMock();
$display_manager->expects($this->any())
->method('getDefinition')
->will($this->returnValueMap(array(
......@@ -69,6 +71,38 @@ public function testBuildRowEntityList() {
)
),
)));
$default_display = $this->getMock('Drupal\views\Plugin\views\display\DefaultDisplay',
array('initDisplay'),
array(array(), 'default', $display_manager->getDefinition('default'))
);
$page_display = $this->getMock('Drupal\views\Plugin\views\display\Page',
array('initDisplay', 'getPath'),
array(array(), 'default', $display_manager->getDefinition('page'))
);
$page_display->expects($this->any())
->method('getPath')
->will($this->returnValue('test_page'));
$embed_display = $this->getMock('Drupal\views\Plugin\views\display\Embed', array('initDisplay'),
array(array(), 'default', $display_manager->getDefinition('embed'))
);
$display_manager->expects($this->any())
->method('createInstance')
->will($this->returnValueMap(array(
array('default', array(), $default_display),
array('page', array(), $page_display),
array('embed', array(), $embed_display),
)));
$container = new ContainerBuilder();
$executable_factory = new ViewExecutableFactory();
$container->set('views.executable', $executable_factory);
$container->set('plugin.manager.views.display', $display_manager);
\Drupal::setContainer($container);
$module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandler')
->disableOriginalConstructor()
->getMock();
......@@ -81,6 +115,7 @@ public function testBuildRowEntityList() {
->will($this->returnValue(array()));
$values = array();
$values['status'] = FALSE;
$values['display']['default']['id'] = 'default';
$values['display']['default']['display_title'] = 'Display';
$values['display']['default']['display_plugin'] = 'default';
......@@ -88,6 +123,7 @@ public function testBuildRowEntityList() {
$values['display']['page_1']['id'] = 'page_1';
$values['display']['page_1']['display_title'] = 'Page 1';
$values['display']['page_1']['display_plugin'] = 'page';
$values['display']['page_1']['display_options']['path'] = 'test_page';
$values['display']['embed']['id'] = 'embed';
$values['display']['embed']['display_title'] = 'Embedded';
......@@ -98,7 +134,9 @@ public function testBuildRowEntityList() {
$row = $view_list_controller->buildRow($view);
$this->assertEquals(array('Embed admin label', 'Page admin label'), $row['data']['view_name']['data']['#displays'], 'Wrong displays got added to view list');
$this->assertEquals($row['data']['path'], '/test_page', 'The path of the page display is not added.');
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment