Commit efbaa69a authored by alexpott's avatar alexpott

Issue #2030667 by filijonka, tim.plunkett, adci_contributor, Thomas...

Issue #2030667 by filijonka, tim.plunkett, adci_contributor, Thomas Brekelmans: Refactoring ViewStorageInterface to ViewEntityInterface
parent a549c01b
......@@ -62,7 +62,7 @@ public function testConstructor() {
$container->set('views.views_data', $views_data);
\Drupal::setContainer($container);
$storage = $this->getMock('Drupal\views\ViewStorageInterface');
$storage = $this->getMock('Drupal\views\ViewEntityInterface');
$storage->expects($this->any())
->method('get')
->with('base_table')
......
......@@ -9,7 +9,6 @@
use Drupal\user\Plugin\views\access\Role;
use Drupal\views\Views;
use Drupal\views\ViewStorageInterface;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -31,7 +30,7 @@ class AccessRoleTest extends AccessTestBase {
* Tests role access plugin.
*/
function testAccessRole() {
/** @var \Drupal\views\ViewStorageInterface $view */
/** @var \Drupal\views\ViewentityInterface $view */
$view = \Drupal::entityManager()->getStorage('view')->load('test_access_role');
$display = &$view->getDisplay('default');
$display['display_options']['access']['options']['role'] = array(
......
......@@ -62,7 +62,7 @@ public function testConstructor() {
$container->set('views.views_data', $views_data);
\Drupal::setContainer($container);
$storage = $this->getMock('Drupal\views\ViewStorageInterface');
$storage = $this->getMock('Drupal\views\ViewEntityInterface');
$storage->expects($this->any())
->method('get')
->with('base_table')
......
......@@ -11,8 +11,7 @@
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\views\Views;
use Drupal\views_ui\ViewUI;
use Drupal\views\ViewStorageInterface;
use Drupal\views\ViewEntityInterface;
/**
* Defines a View configuration entity class.
......@@ -31,7 +30,7 @@
* }
* )
*/
class View extends ConfigEntityBase implements ViewStorageInterface {
class View extends ConfigEntityBase implements ViewEntityInterface {
/**
* The name of the base table this view will use.
......@@ -45,7 +44,7 @@ class View extends ConfigEntityBase implements ViewStorageInterface {
*
* @var string
*/
public $id = NULL;
protected $id = NULL;
/**
* The label of the view.
......@@ -72,7 +71,7 @@ class View extends ConfigEntityBase implements ViewStorageInterface {
/**
* The core version the view was created for.
*
* @var int
* @var string
*/
protected $core = \Drupal::CORE_COMPATIBILITY;
......@@ -108,10 +107,7 @@ class View extends ConfigEntityBase implements ViewStorageInterface {
protected $module = 'views';
/**
* Gets an executable instance for this view.
*
* @return \Drupal\views\ViewExecutable
* A view executable instance.
* {@inheritdoc}
*/
public function getExecutable() {
// Ensure that an executable View is available.
......@@ -123,7 +119,7 @@ public function getExecutable() {
}
/**
* Overrides Drupal\Core\Config\Entity\ConfigEntityBase::createDuplicate().
* {@inheritdoc}
*/
public function createDuplicate() {
$duplicate = parent::createDuplicate();
......@@ -132,9 +128,7 @@ public function createDuplicate() {
}
/**
* Overrides \Drupal\Core\Entity\Entity::label().
*
* When a certain view doesn't have a label return the ID.
* {@inheritdoc}
*/
public function label() {
if (!$label = $this->get('label')) {
......@@ -144,20 +138,7 @@ public function label() {
}
/**
* Adds a new display handler to the view, automatically creating an ID.
*
* @param string $plugin_id
* (optional) The plugin type from the Views plugin annotation. Defaults to
* 'page'.
* @param string $title
* (optional) The title of the display. Defaults to NULL.
* @param string $id
* (optional) The ID to use, e.g., 'default', 'page_1', 'block_2'. Defaults
* to NULL.
*
* @return string|false
* The key to the display in $view->display, or FALSE if no plugin ID was
* provided.
* {@inheritdoc}
*/
public function addDisplay($plugin_id = 'page', $title = NULL, $id = NULL) {
if (empty($plugin_id)) {
......@@ -213,6 +194,8 @@ public function addDisplay($plugin_id = 'page', $title = NULL, $id = NULL) {
*
* @param string $plugin_id
* Which plugin should be used for the new display ID.
*
* @return string
*/
protected function generateDisplayId($plugin_id) {
// 'default' is singular and is unique, so just go with 'default'
......@@ -420,7 +403,7 @@ public static function preDelete(EntityStorageInterface $storage, array $entitie
parent::preDelete($storage, $entities);
// Call the remove() hook on the individual displays.
/** @var \Drupal\views\ViewStorageInterface $entity */
/** @var \Drupal\views\ViewEntityInterface $entity */
foreach ($entities as $entity) {
$executable = Views::executableFactory()->get($entity);
foreach ($entity->get('display') as $display_id => $display) {
......@@ -460,5 +443,4 @@ public function mergeDefaultDisplaysOptions() {
}
$this->set('display', $displays);
}
}
......@@ -54,7 +54,7 @@ public function validateView(array $form, FormStateInterface $form_state);
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the wizard form.
*
* @return \Drupal\views\ViewStorageInterface
* @return \Drupal\views\ViewEntityInterface
* The created view object.
*
* @throws \Drupal\views\Plugin\views\wizard\WizardException
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\views\ViewStorageInterface.
* Definition of Drupal\views\ViewEntityInterface.
*/
namespace Drupal\views;
......@@ -12,7 +12,7 @@
/**
* Defines an interface for View storage classes.
*/
interface ViewStorageInterface extends ConfigEntityInterface {
interface ViewEntityInterface extends ConfigEntityInterface {
/**
* Gets an executable instance for this view.
......@@ -53,4 +53,23 @@ public function mergeDefaultDisplaysOptions();
*/
public function duplicateDisplayAsType($old_display_id, $new_display_type);
/**
* Adds a new display handler to the view, automatically creating an ID.
*
* @param string $plugin_id
* (optional) The plugin type from the Views plugin annotation. Defaults to
* 'page'.
* @param string $title
* (optional) The title of the display. Defaults to NULL.
* @param string $id
* (optional) The ID to use, e.g., 'default', 'page_1', 'block_2'. Defaults
* to NULL.
*
* @return string|bool
* The key to the display in $view->display, or FALSE if no plugin ID was
* provided.
*/
public function addDisplay($plugin_id = 'page', $title = NULL, $id = NULL);
}
......@@ -12,7 +12,7 @@
use Drupal\Core\Form\FormState;
use Drupal\Core\Session\AccountInterface;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\ViewStorageInterface;
use Drupal\views\ViewEntityInterface;
use Drupal\Component\Utility\Tags;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
......@@ -427,14 +427,14 @@ class ViewExecutable {
/**
* Constructs a new ViewExecutable object.
*
* @param \Drupal\views\ViewStorageInterface $storage
* @param \Drupal\views\ViewEntityInterface $storage
* The view config entity the actual information is stored on.
* @param \Drupal\Core\Session\AccountInterface $user
* The current user.
* @param \Drupal\views\ViewsData $views_data
* The views data.
*/
public function __construct(ViewStorageInterface $storage, AccountInterface $user, ViewsData $views_data) {
public function __construct(ViewEntityInterface $storage, AccountInterface $user, ViewsData $views_data) {
// Reference the storage and the executable to each other.
$this->storage = $storage;
$this->storage->set('executable', $this);
......
......@@ -8,7 +8,7 @@
namespace Drupal\views;
use Drupal\Core\Session\AccountInterface;
use Drupal\views\ViewStorageInterface;
use Drupal\views\ViewEntityInterface;
use Symfony\Component\HttpFoundation\RequestStack;
/**
......@@ -56,13 +56,13 @@ public function __construct(AccountInterface $user, RequestStack $request_stack,
/**
* Instantiates a ViewExecutable class.
*
* @param \Drupal\views\ViewStorageInterface $view
* @param \Drupal\views\ViewEntityInterface $view
* A view entity instance.
*
* @return \Drupal\views\ViewExecutable
* A ViewExecutable instance.
*/
public function get(ViewStorageInterface $view) {
public function get(ViewEntityInterface $view) {
$view = new ViewExecutable($view, $this->user, $this->viewsData);
$view->setRequest($this->requestStack->getCurrentRequest());
return $view;
......
......@@ -7,7 +7,6 @@
use Drupal\field\FieldStorageConfigInterface;
use Drupal\views\ViewExecutable;
use Drupal\views\ViewStorageInterface;
/**
* Implements hook_views_query_substitutions().
......
......@@ -39,7 +39,7 @@ class ViewsBlockTest extends UnitTestCase {
/**
* The view entity.
*
* @var \Drupal\views\ViewStorageInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Drupal\views\ViewEntityInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $view;
......
......@@ -58,7 +58,7 @@ protected function setUp() {
* Tests the page controller.
*/
public function testPageController() {
$view = $this->getMock('Drupal\views\ViewStorageInterface');
$view = $this->getMock('Drupal\views\ViewEntityInterface');
$this->storage->expects($this->once())
->method('load')
......@@ -112,7 +112,7 @@ public function testPageController() {
* Tests the page controller with arguments on a non overridden page view.
*/
public function testHandleWithArgumentsWithoutOverridden() {
$view = $this->getMock('Drupal\views\ViewStorageInterface');
$view = $this->getMock('Drupal\views\ViewEntityInterface');
$this->storage->expects($this->once())
->method('load')
......@@ -168,7 +168,7 @@ public function testHandleWithArgumentsWithoutOverridden() {
* Note: This test does not care about upcasting for now.
*/
public function testHandleWithArgumentsOnOveriddenRoute() {
$view = $this->getMock('Drupal\views\ViewStorageInterface');
$view = $this->getMock('Drupal\views\ViewEntityInterface');
$this->storage->expects($this->once())
->method('load')
......@@ -227,7 +227,7 @@ public function testHandleWithArgumentsOnOveriddenRoute() {
* are pulled in.
*/
public function testHandleWithArgumentsOnOveriddenRouteWithUpcasting() {
$view = $this->getMock('Drupal\views\ViewStorageInterface');
$view = $this->getMock('Drupal\views\ViewEntityInterface');
$this->storage->expects($this->once())
->method('load')
......
......@@ -61,7 +61,7 @@ protected function setUp() {
$this->user = $this->getMock('Drupal\Core\Session\AccountInterface');
$this->requestStack = new RequestStack();
$this->view = $this->getMock('Drupal\views\ViewStorageInterface');
$this->view = $this->getMock('Drupal\views\ViewEntityInterface');
$this->viewsData = $this->getMockBuilder('Drupal\views\ViewsData')
->disableOriginalConstructor()
->getMock();
......
......@@ -430,7 +430,7 @@ function views_add_contextual_links(&$render_element, $location, ViewExecutable
break;
}
else {
$args[$parameter_name] = $view->storage->{$property};
$args[$parameter_name] = $view->storage->get($property);
}
}
}
......
......@@ -12,8 +12,7 @@
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Drupal\views\ViewExecutable;
use Drupal\views\ViewStorageInterface;
use Drupal\views\Views;
use Drupal\views\ViewEntityInterface;
use Drupal\views_ui\ViewUI;
use Drupal\views\ViewsData;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -138,7 +137,7 @@ public function reportPlugins() {
/**
* Calls a method on a view and reloads the listing page.
*
* @param \Drupal\views\ViewStorageInterface $view
* @param \Drupal\views\ViewEntityInterface $view
* The view being acted upon.
* @param string $op
* The operation to perform, e.g., 'enable' or 'disable'.
......@@ -150,7 +149,7 @@ public function reportPlugins() {
* back to the listing page.
*
*/
public function ajaxOperation(ViewStorageInterface $view, $op, Request $request) {
public function ajaxOperation(ViewEntityInterface $view, $op, Request $request) {
// Perform the operation.
$view->$op()->save();
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ViewExecutable;
use Drupal\views\ViewStorageInterface;
use Drupal\views\ViewEntityInterface;
use Drupal\views\Views;
/**
......@@ -34,7 +34,7 @@ public function getFormKey() {
/**
* {@inheritdoc}
*/
public function getForm(ViewStorageInterface $view, $display_id, $js, $type = NULL) {
public function getForm(ViewEntityInterface $view, $display_id, $js, $type = NULL) {
$this->setType($type);
return parent::getForm($view, $display_id, $js);
}
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\views\ViewStorageInterface;
use Drupal\views\ViewEntityInterface;
use Drupal\views\ViewExecutable;
use Drupal\views\Views;
use Symfony\Component\HttpFoundation\Request;
......@@ -37,7 +37,7 @@ public function getFormKey() {
/**
* {@inheritdoc}
*/
public function getForm(ViewStorageInterface $view, $display_id, $js, $type = NULL, $id = NULL) {
public function getForm(ViewEntityInterface $view, $display_id, $js, $type = NULL, $id = NULL) {
$this->setType($type);
$this->setID($id);
return parent::getForm($view, $display_id, $js);
......
......@@ -8,7 +8,7 @@
namespace Drupal\views_ui\Form\Ajax;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ViewStorageInterface;
use Drupal\views\ViewEntityInterface;
use Drupal\views\ViewExecutable;
/**
......@@ -34,7 +34,7 @@ public function getFormKey() {
/**
* {@inheritdoc}
*/
public function getForm(ViewStorageInterface $view, $display_id, $js, $type = NULL, $id = NULL) {
public function getForm(ViewEntityInterface $view, $display_id, $js, $type = NULL, $id = NULL) {
$this->setType($type);
$this->setID($id);
return parent::getForm($view, $display_id, $js);
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Views;
use Drupal\views\ViewStorageInterface;
use Drupal\views\ViewEntityInterface;
use Drupal\views\ViewExecutable;
/**
......@@ -35,7 +35,7 @@ public function getFormKey() {
/**
* {@inheritdoc}
*/
public function getForm(ViewStorageInterface $view, $display_id, $js, $type = NULL, $id = NULL) {
public function getForm(ViewEntityInterface $view, $display_id, $js, $type = NULL, $id = NULL) {
$this->setType($type);
$this->setID($id);
return parent::getForm($view, $display_id, $js);
......
......@@ -8,7 +8,7 @@
namespace Drupal\views_ui\Form\Ajax;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ViewStorageInterface;
use Drupal\views\ViewEntityInterface;
/**
* Provides a form for editing the Views display.
......@@ -35,7 +35,7 @@ public function getFormKey() {
* @todo Remove this and switch all usage of $form_state->get('section') to
* $form_state->get('type').
*/
public function getFormState(ViewStorageInterface $view, $display_id, $js) {
public function getFormState(ViewEntityInterface $view, $display_id, $js) {
$form_state = parent::getFormState($view, $display_id, $js);
$form_state->set('section', $this->type);
return $form_state;
......@@ -44,7 +44,7 @@ public function getFormState(ViewStorageInterface $view, $display_id, $js) {
/**
* {@inheritdoc}
*/
public function getForm(ViewStorageInterface $view, $display_id, $js, $type = NULL) {
public function getForm(ViewEntityInterface $view, $display_id, $js, $type = NULL) {
$this->setType($type);
return parent::getForm($view, $display_id, $js);
}
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\views\ViewStorageInterface;
use Drupal\views\ViewEntityInterface;
use Drupal\views\ViewExecutable;
/**
......@@ -34,7 +34,7 @@ public function getFormKey() {
/**
* {@inheritdoc}
*/
public function getForm(ViewStorageInterface $view, $display_id, $js, $type = NULL) {
public function getForm(ViewEntityInterface $view, $display_id, $js, $type = NULL) {
$this->setType($type);
return parent::getForm($view, $display_id, $js);
}
......
......@@ -34,7 +34,7 @@ public function getFormId() {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/** @var $view \Drupal\views\ViewStorageInterface */
/** @var $view \Drupal\views\ViewEntityInterface */
$view = $form_state->get('view');
$display_id = $form_state->get('display_id');
......
......@@ -11,7 +11,8 @@
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ViewStorageInterface;
use Drupal\views_ui\ViewUI;
use Drupal\views\ViewEntityInterface;
use Drupal\views\Ajax;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\CloseModalDialogCommand;
......@@ -63,7 +64,7 @@ protected function setType($type) {
/**
* {@inheritdoc}
*/
public function getFormState(ViewStorageInterface $view, $display_id, $js) {
public function getFormState(ViewEntityInterface $view, $display_id, $js) {
// $js may already have been converted to a Boolean.
$ajax = is_string($js) ? $js === 'ajax' : $js;
return (new FormState())
......@@ -81,7 +82,7 @@ public function getFormState(ViewStorageInterface $view, $display_id, $js) {
/**
* {@inheritdoc}
*/
public function getForm(ViewStorageInterface $view, $display_id, $js) {
public function getForm(ViewEntityInterface $view, $display_id, $js) {
$form_state = $this->getFormState($view, $display_id, $js);
$view = $form_state->get('view');
$key = $form_state->get('form_key');
......
......@@ -8,7 +8,7 @@
namespace Drupal\views_ui\Form\Ajax;
use Drupal\Core\Form\FormInterface;
use Drupal\views\ViewStorageInterface;
use Drupal\views\ViewEntityInterface;
interface ViewsFormInterface extends FormInterface {
......@@ -24,7 +24,7 @@ public function getFormKey();
/**
* Gets the form state for this form.
*
* @param \Drupal\views\ViewStorageInterface $view
* @param \Drupal\views\ViewEntityInterface $view
* The view being edited.
* @param string|null $display_id
* The display ID being edited, or NULL to load the first available display.
......@@ -35,12 +35,12 @@ public function getFormKey();
* @return \Drupal\Core\Form\FormStateInterface
* The current state of the form.
*/
public function getFormState(ViewStorageInterface $view, $display_id, $js);
public function getFormState(ViewEntityInterface $view, $display_id, $js);
/**
* Creates a new instance of this form.
*
* @param \Drupal\views\ViewStorageInterface $view
* @param \Drupal\views\ViewEntityInterface $view
* The view being edited.
* @param string|null $display_id
* The display ID being edited, or NULL to load the first available display.
......@@ -55,6 +55,6 @@ public function getFormState(ViewStorageInterface $view, $display_id, $js);
* @todo When http://drupal.org/node/1843224 is in, this will return
* \Drupal\Core\Ajax\AjaxResponse instead of the array of AJAX commands.
*/
public function getForm(ViewStorageInterface $view, $display_id, $js);
public function getForm(ViewEntityInterface $view, $display_id, $js);
}
......@@ -855,7 +855,7 @@ public function submitDisplayAdd($form, FormStateInterface $form_state) {
* Submit handler to Duplicate a display as another display type.
*/
public function submitDuplicateDisplayAsType($form, FormStateInterface $form_state) {
/** @var \Drupal\views\ViewStorageInterface $view */
/** @var \Drupal\views\ViewEntityInterface $view */
$view = $this->entity;
$display_id = $this->displayID;
......
......@@ -21,7 +21,7 @@
use Drupal\Core\Session\AccountInterface;
use Drupal\views\Plugin\views\query\Sql;
use Drupal\views\Entity\View;
use Drupal\views\ViewStorageInterface;
use Drupal\views\ViewEntityInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
......@@ -29,7 +29,7 @@
/**
* Stores UI related temporary settings.
*/
class ViewUI implements ViewStorageInterface {
class ViewUI implements ViewEntityInterface {
/**
* Indicates if a view is currently being edited.
......@@ -109,7 +109,7 @@ class ViewUI implements ViewStorageInterface {
/**
* The View storage object.
*
* @var \Drupal\views\ViewStorageInterface
* @var \Drupal\views\ViewEntityInterface
*/
protected $storage;
......@@ -165,10 +165,10 @@ class ViewUI implements ViewStorageInterface {
/**
* Constructs a View UI object.
*
* @param \Drupal\views\ViewStorageInterface $storage
* @param \Drupal\views\ViewEntityInterface $storage
* The View storage object to wrap.
*/
public function __construct(ViewStorageInterface $storage, ViewExecutable $executable = NULL) {
public function __construct(ViewEntityInterface $storage, ViewExecutable $executable = NULL) {
$this->entityType = 'view';
$this->storage = $storage;
if (!isset($executable)) {
......@@ -1168,4 +1168,17 @@ public function getTypedData() {
$this->storage->getTypedData();
}
/**
* {@inheritdoc}
*/
public function addDisplay($plugin_id = 'page', $title = NULL, $id = NULL) {
return $this->storage->addDisplay($plugin_id, $title, $id);
}
/**
* {@inheritdoc}
*/
public function getViewExecutable() {
return $this->storage->getViewExecutable();
}
}
......@@ -10,7 +10,6 @@
use Drupal\Core\Url;
use Drupal\views\Views;
use Drupal\views\ViewExecutable;
use Drupal\views\ViewStorageInterface;
use Drupal\views_ui\ViewUI;
use Drupal\views\Analyzer;
use Drupal\Core\Ajax\AjaxResponse;
......
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