Commit a544e13f authored by alexpott's avatar alexpott

Issue #2012882 by damiankloip, dawehner: Move getDisplaysList() out of View...

Issue #2012882 by damiankloip, dawehner: Move getDisplaysList() out of View storage class to ViewListController.
parent 42c1a7c0
......@@ -289,26 +289,6 @@ public function &getDisplay($display_id) {
return $this->display[$display_id];
}
/**
* Gets a list of displays included in the view.
*
* @return array
* An array of display types that this view includes.
*/
function getDisplaysList() {
$manager = Views::pluginManager('display');
$displays = array();
foreach ($this->display as $display) {
$definition = $manager->getDefinition($display['display_plugin']);
if (!empty($definition['admin'])) {
$displays[$definition['admin']] = TRUE;
}
}
ksort($displays);
return array_keys($displays);
}
/**
* Gets a list of paths assigned to the view.
*
......
......@@ -219,8 +219,6 @@ protected function displayMethodTests() {
);
$view = $this->controller->create($config);
$this->assertEqual($view->getDisplaysList(), array('Feed', 'Page'), 'Make sure the display admin names are returns in alphabetic order.');
// Paths with a "%" shouldn't not be linked
$expected_paths = array();
$expected_paths[] = l('/test', 'test');
......
......@@ -7,13 +7,55 @@
namespace Drupal\views_ui;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Config\Entity\ConfigEntityListController;
use Drupal\Core\Entity\EntityControllerInterface;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a listing of Views.
*/
class ViewListController extends ConfigEntityListController {
class ViewListController extends ConfigEntityListController implements EntityControllerInterface {
/**
* The views display plugin manager to use.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected $displayManager;
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
return new static(
$entity_type,
$container->get('plugin.manager.entity')->getStorageController($entity_type),
$entity_info,
$container->get('plugin.manager.views.display')
);
}
/**
* Constructs a new EntityListController object.
*
* @param string $entity_type.
* The type of entity to be listed.
* @param \Drupal\Core\Entity\EntityStorageControllerInterface $storage.
* The entity storage controller class.
* @param array $entity_info
* An array of entity info for this entity type.
* @param \Drupal\Component\Plugin\PluginManagerInterface $display_manager
* The views display plugin manager to use.
*/
public function __construct($entity_type, EntityStorageControllerInterface $storage, $entity_info, PluginManagerInterface $display_manager) {
$this->entityType = $entity_type;
$this->storage = $storage;
$this->entityInfo = $entity_info;
$this->displayManager = $display_manager;
}
/**
* Overrides Drupal\Core\Entity\EntityListController::load();
......@@ -40,7 +82,13 @@ public function load() {
public function buildRow(EntityInterface $view) {
return array(
'data' => array(
'view_name' => theme('views_ui_view_info', array('view' => $view)),
'view_name' => array(
'data' => array(
'#theme' => 'views_ui_view_info',
'#view' => $view,
'#displays' => $this->getDisplaysList($view)
),
),
'description' => $view->get('description'),
'tag' => $view->get('tag'),
'path' => implode(', ', $view->getPaths()),
......@@ -156,4 +204,26 @@ public function render() {
return $list;
}
/**
* Gets a list of displays included in the view.
*
* @param \Drupal\Core\Entity\EntityInterface $view
* The view entity instance to get a list of displays for.
*
* @return array
* An array of display types that this view includes.
*/
protected function getDisplaysList(EntityInterface $view) {
$displays = array();
foreach ($view->get('display') as $display) {
$definition = $this->displayManager->getDefinition($display['display_plugin']);
if (!empty($definition['admin'])) {
$displays[$definition['admin']] = TRUE;
}
}
ksort($displays);
return array_keys($displays);
}
}
<?php
/**
* @file
* Contains \Drupal\views_ui\Tests\ViewListControllerTest
*/
namespace Drupal\views_ui\Tests {
use Drupal\Tests\UnitTestCase;
use Drupal\views\Plugin\Core\Entity\View;
use Drupal\views_ui\ViewListController;
class ViewListControllerTest extends UnitTestCase {
public static function getInfo() {
return array(
'name' => 'Views List Controller Unit Test',
'description' => 'Unit tests the views list controller',
'group' => 'Views UI',
);
}
/**
* Tests the listing of displays on a views list.
*
* @see \Drupal\views_ui\ViewListController::getDisplaysList().
*/
public function testBuildRowEntityList() {
$storage_controller = $this->getMockBuilder('Drupal\views\ViewStorageController')
->disableOriginalConstructor()
->getMock();
$entity_info = array();
$display_manager = $this->getMockBuilder('\Drupal\views\Plugin\ViewsPluginManager')
->disableOriginalConstructor()
->getMock();
$display_manager->expects($this->any())
->method('getDefinition')
->will($this->returnValueMap(array(
array(
'default',
array(
'id' => 'default',
'title' => 'Master',
'theme' => 'views_view',
'no_ui' => TRUE,
)
),
array(
'page',
array(
'id' => 'page',
'title' => 'Page',
'uses_hook_menu' => TRUE,
'uses_route' => TRUE,
'contextual_links_locations' => array('page'),
'theme' => 'views_view',
'admin' => 'Page admin label',
)
),
array(
'embed',
array(
'id' => 'embed',
'title' => 'embed',
'theme' => 'views_view',
'admin' => 'Embed admin label',
)
),
)));
// Setup a view list controller with a mocked buildOperations method,
// because t() is called on there.
$view_list_controller = $this->getMock('Drupal\views_ui\ViewListController', array('buildOperations'), array('view', $storage_controller, $entity_info, $display_manager));
$view_list_controller->expects($this->any())
->method('buildOperations')
->will($this->returnValue(array()));
$values = array();
$values['display']['default']['id'] = 'default';
$values['display']['default']['display_title'] = 'Display';
$values['display']['default']['display_plugin'] = 'default';
$values['display']['page_1']['id'] = 'page_1';
$values['display']['page_1']['display_title'] = 'Page 1';
$values['display']['page_1']['display_plugin'] = 'page';
$values['display']['embed']['id'] = 'embed';
$values['display']['embed']['display_title'] = 'Embedded';
$values['display']['embed']['display_plugin'] = 'embed';
$view = new View($values, 'view');
$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');
}
}
}
// @todo Remove this once t() is converted to a service.
namespace {
if (!function_exists('t')) {
function t($string) {
return $string;
}
}
}
......@@ -154,7 +154,7 @@ function views_ui_theme() {
// list views
'views_ui_view_info' => array(
'variables' => array('view' => NULL, 'base' => NULL),
'variables' => array('view' => NULL, 'displays' => NULL),
'file' => 'views_ui.theme.inc',
),
......
......@@ -93,9 +93,7 @@ function template_preprocess_views_ui_display_tab_bucket(&$variables) {
*/
function template_preprocess_views_ui_view_info(&$variables) {
$variables['title'] = $variables['view']->label();
$displays = $variables['view']->getDisplaysList();
$variables['displays'] = empty($displays) ? t('None') : format_plural(count($displays), 'Display', 'Displays') . ': ' . '<em>' . implode(', ', $displays) . '</em>';
$variables['displays'] = empty($variables['displays']) ? t('None') : format_plural(count($variables['displays']), 'Display', 'Displays') . ': ' . '<em>' . implode(', ', $variables['displays']) . '</em>';
}
/**
......
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