From e2bb2d640079185c06b37110c1986b4cda23e268 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Wed, 16 Oct 2013 11:53:48 +0100 Subject: [PATCH] Issue #2096787 by damiankloip, derhasi: Clean up Views area plugins. --- .../Drupal/views/Plugin/views/HandlerBase.php | 28 +++++------ .../Plugin/views/area/AreaPluginBase.php | 28 +++++------ .../Drupal/views/Plugin/views/area/Broken.php | 27 +++++++--- .../Drupal/views/Plugin/views/area/Entity.php | 3 +- .../Plugin/views/area/HTTPStatusCode.php | 1 - .../Drupal/views/Plugin/views/area/Result.php | 9 +++- .../Drupal/views/Plugin/views/area/Text.php | 11 ++-- .../views/Plugin/views/area/TextCustom.php | 4 +- .../Drupal/views/Plugin/views/area/Title.php | 10 ++-- .../Drupal/views/Plugin/views/area/View.php | 50 ++++++++++++++++--- 10 files changed, 107 insertions(+), 64 deletions(-) diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php index 9569c5d3fdea..763622f7dd08 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php @@ -273,11 +273,6 @@ abstract class HandlerBase extends PluginBase { } } - /** - * Validate the options form. - */ - public function validateOptionsForm(&$form, &$form_state) { } - /** * Build the options form. */ @@ -322,12 +317,6 @@ abstract class HandlerBase extends PluginBase { \Drupal::moduleHandler()->alter('views_handler_options', $this->options, $this->view); } - /** - * Perform any necessary changes to the form values prior to storage. - * There is no need for this function to actually store the data. - */ - public function submitOptionsForm(&$form, &$form_state) { } - /** * Provides the handler some groupby. */ @@ -493,7 +482,14 @@ abstract class HandlerBase extends PluginBase { * This gives all the handlers some time to set up before any handler has * been fully run. */ - public function preQuery() { } + public function preQuery() { + } + + /** + * Don't run a query by default. + */ + public function query() { + } /** * Run after the view is executed, before the result is cached. @@ -556,7 +552,7 @@ abstract class HandlerBase extends PluginBase { } /** - * Provide text for the administrative summary + * Provide text for the administrative summary. */ public function adminSummary() { } @@ -629,10 +625,12 @@ abstract class HandlerBase extends PluginBase { public function validate() { return array(); } /** - * Determine if the handler is considered 'broken', meaning it's a + * Determines if the handler is considered 'broken', meaning it's a * a placeholder used when a handler can't be found. */ - public function broken() { } + public function broken() { + return FALSE; + } /** * Creates cross-database SQL date formatting. diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/AreaPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/AreaPluginBase.php index b3028613b926..0255ecc3cbb0 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/AreaPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/AreaPluginBase.php @@ -9,7 +9,6 @@ namespace Drupal\views\Plugin\views\area; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; -use Drupal\views\Plugin\views\PluginBase; use Drupal\views\Plugin\views\HandlerBase; /** @@ -47,6 +46,16 @@ abstract class AreaPluginBase extends HandlerBase { } } + /** + * {@inheritdoc} + */ + public function usesGroupBy() { + return FALSE; + } + + /** + * {@inheritdoc} + */ protected function defineOptions() { $options = parent::defineOptions(); @@ -59,15 +68,14 @@ abstract class AreaPluginBase extends HandlerBase { } /** - * Provide extra data to the administration form + * {@inheritdoc} */ public function adminSummary() { return $this->adminLabel(); } /** - * Default options form that provides the label widget that all fields - * should have. + * {@inheritdoc} */ public function buildOptionsForm(&$form, &$form_state) { parent::buildOptionsForm($form, $form_state); @@ -81,11 +89,6 @@ abstract class AreaPluginBase extends HandlerBase { } } - /** - * Don't run a query - */ - public function query() { } - /** * Performs any operations needed before full rendering. * @@ -119,13 +122,6 @@ abstract class AreaPluginBase extends HandlerBase { return empty($this->options['empty']); } - /** - * Area handlers shouldn't have groupby. - */ - public function usesGroupBy() { - return FALSE; - } - } /** diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/Broken.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/Broken.php index 08d30692cdaf..dff668bfa6db 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/Broken.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/Broken.php @@ -7,9 +7,6 @@ namespace Drupal\views\Plugin\views\area; -use Drupal\Component\Annotation\PluginID; -use Drupal\views\ViewExecutable; - /** * A special handler to take the place of missing or broken handlers. * @@ -19,6 +16,9 @@ use Drupal\views\ViewExecutable; */ class Broken extends AreaPluginBase { + /** + * {@inheritdoc} + */ public function adminLabel($short = FALSE) { $args = array( '@module' => $this->definition['original_configuration']['provider'], @@ -26,11 +26,22 @@ class Broken extends AreaPluginBase { return $this->isOptional() ? t('Optional handler is missing (Module: @module) …', $args) : t('Broken/missing handler (Module: @module) …', $args); } - public function defineOptions() { return array(); } - public function ensureMyTable() { /* No table to ensure! */ } - public function query($group_by = FALSE) { /* No query to run */ } /** - * Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render(). + * {@inheritdoc} + */ + public function defineOptions() { + return array(); + } + + /** + * {@inheritdoc} + */ + public function ensureMyTable() { + // No table to ensure. + } + + /** + * {@inheritdoc} */ public function render($empty = FALSE) { // Simply render nothing by returning an empty render array. @@ -75,7 +86,7 @@ class Broken extends AreaPluginBase { } /** - * Determine if the handler is considered 'broken' + * {@inheritdoc} */ public function broken() { return TRUE; diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/Entity.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/Entity.php index 4bf13c74b43b..13634246682f 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/Entity.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/Entity.php @@ -9,7 +9,6 @@ namespace Drupal\views\Plugin\views\area; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; -use Drupal\Component\Annotation\PluginID; /** * Provides an area handler which renders an entity in a certain view mode. @@ -89,7 +88,7 @@ class Entity extends TokenizeAreaPluginBase { } /** - * Overrides \Drupal\views\Plugin\views\area\AreaPluginBase::render(). + * {@inheritdoc} */ public function render($empty = FALSE) { if (!$empty || !empty($this->options['empty'])) { diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/HTTPStatusCode.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/HTTPStatusCode.php index d44887689529..f79b2fc5ceff 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/HTTPStatusCode.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/HTTPStatusCode.php @@ -8,7 +8,6 @@ namespace Drupal\views\Plugin\views\area; use Symfony\Component\HttpFoundation\Response; -use Drupal\Component\Annotation\PluginID; /** * Alter the HTTP response status code used by the view. diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php index f1276caec443..b6a63ba41c69 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php @@ -7,7 +7,6 @@ namespace Drupal\views\Plugin\views\area; -use Drupal\Component\Annotation\PluginID; use Drupal\Component\Utility\String; use Drupal\Component\Utility\Xss; use Drupal\views\Plugin\views\style\DefaultSummary; @@ -21,6 +20,9 @@ use Drupal\views\Plugin\views\style\DefaultSummary; */ class Result extends AreaPluginBase { + /** + * {@inheritdoc} + */ protected function defineOptions() { $options = parent::defineOptions(); @@ -32,6 +34,9 @@ class Result extends AreaPluginBase { return $options; } + /** + * {@inheritdoc} + */ public function buildOptionsForm(&$form, &$form_state) { parent::buildOptionsForm($form, $form_state); $item_list = array( @@ -67,7 +72,7 @@ class Result extends AreaPluginBase { } /** - * Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render(). + * {@inheritdoc} */ public function render($empty = FALSE) { // Must have options and does not work on summaries. diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/Text.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/Text.php index a9dd6c57299e..7206e5b2bd50 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/Text.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/Text.php @@ -7,8 +7,6 @@ namespace Drupal\views\Plugin\views\area; -use Drupal\Component\Annotation\PluginID; - /** * Views area text handler. * @@ -19,7 +17,7 @@ use Drupal\Component\Annotation\PluginID; class Text extends TokenizeAreaPluginBase { /** - * Overrides \Drupal\views\Plugin\views\area\TokenizeAreaPluginBase::defineOptions(). + * {@inheritdoc} */ protected function defineOptions() { $options = parent::defineOptions(); @@ -29,7 +27,7 @@ class Text extends TokenizeAreaPluginBase { } /** - * Overrides \Drupal\views\Plugin\views\area\TokenizeAreaPluginBase::buildOptionsForm(). + * {@inheritdoc} */ public function buildOptionsForm(&$form, &$form_state) { parent::buildOptionsForm($form, $form_state); @@ -44,6 +42,9 @@ class Text extends TokenizeAreaPluginBase { ); } + /** + * {@inheritdoc} + */ public function submitOptionsForm(&$form, &$form_state) { $form_state['values']['options']['format'] = $form_state['values']['options']['content']['format']; $form_state['values']['options']['content'] = $form_state['values']['options']['content']['value']; @@ -51,7 +52,7 @@ class Text extends TokenizeAreaPluginBase { } /** - * Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render(). + * {@inheritdoc} */ public function render($empty = FALSE) { $format = isset($this->options['format']) ? $this->options['format'] : filter_default_format(); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/TextCustom.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/TextCustom.php index dac981518a17..4494caa3436e 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/TextCustom.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/TextCustom.php @@ -7,8 +7,6 @@ namespace Drupal\views\Plugin\views\area; -use Drupal\Component\Annotation\PluginID; - /** * Views area text handler. * @@ -42,7 +40,7 @@ class TextCustom extends TokenizeAreaPluginBase { } /** - * Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render(). + * {@inheritdoc} */ public function render($empty = FALSE) { if (!$empty || !empty($this->options['empty'])) { diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/Title.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/Title.php index 7ee019753e48..66f34952b077 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/Title.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/Title.php @@ -7,8 +7,6 @@ namespace Drupal\views\Plugin\views\area; -use Drupal\Component\Annotation\PluginID; - /** * Views area title override handler. * @@ -19,7 +17,7 @@ use Drupal\Component\Annotation\PluginID; class Title extends AreaPluginBase { /** - * Overrides Drupal\views\Plugin\views\AreaPluginBase::defineOptions(). + * {@inheritdoc} */ protected function defineOptions() { $options = parent::defineOptions(); @@ -28,7 +26,7 @@ class Title extends AreaPluginBase { } /** - * Overrides Drupal\views\Plugin\views\AreaPluginBase::buildOptionsForm(). + * {@inheritdoc} */ public function buildOptionsForm(&$form, &$form_state) { parent::buildOptionsForm($form, $form_state); @@ -45,7 +43,7 @@ class Title extends AreaPluginBase { } /** - * Overrides Drupal\views\Plugin\views\AreaPluginBase::preRender(). + * {@inheritdoc} */ public function preRender(array $results) { parent::preRender($results); @@ -58,7 +56,7 @@ class Title extends AreaPluginBase { } /** - * Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render(). + * {@inheritdoc} */ public function render($empty = FALSE) { // Do nothing for this handler by returning an empty render array. diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/View.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/View.php index 8b7f21cd6463..412f19289c8c 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/View.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/View.php @@ -2,12 +2,13 @@ /** * @file - * Definition of Drupal\views\Plugin\views\area\View. + * Contains \Drupal\views\Plugin\views\area\View. */ namespace Drupal\views\Plugin\views\area; -use Drupal\Component\Annotation\PluginID; +use Drupal\Core\Entity\EntityStorageControllerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Views area handlers. Insert a view inside of an area. @@ -25,6 +26,43 @@ class View extends AreaPluginBase { */ protected $isEmpty; + /** + * The view storage controller. + * + * @var \Drupal\Core\Entity\EntityStorageControllerInterface + */ + protected $viewStorage; + + /** + * Constructs a View object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param array $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Entity\EntityStorageControllerInterface $view_storage + * The view storage controller. + */ + public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageControllerInterface $view_storage) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + + $this->viewStorage = $view_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity.manager')->getStorageController('view') + ); + } + /** * {@inheritdoc} */ @@ -37,8 +75,7 @@ class View extends AreaPluginBase { } /** - * Default options form that provides the label widget that all fields - * should have. + * {@inheritdoc} */ public function buildOptionsForm(&$form, &$form_state) { parent::buildOptionsForm($form, $form_state); @@ -64,13 +101,14 @@ class View extends AreaPluginBase { } /** - * Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render(). + * {@inheritdoc} */ public function render($empty = FALSE) { if (!empty($this->options['view_to_insert'])) { list($view_name, $display_id) = explode(':', $this->options['view_to_insert']); - $view = views_get_view($view_name); + $view = $this->viewStorage->load($view_name); + if (empty($view) || !$view->access($display_id)) { return array(); }