Issue #2096787 by damiankloip, derhasi: Clean up Views area plugins.

8.0.x
Nathaniel Catchpole 2013-10-16 11:53:48 +01:00
parent 15acad2df9
commit e2bb2d6400
10 changed files with 107 additions and 64 deletions

View File

@ -273,11 +273,6 @@ abstract class HandlerBase extends PluginBase {
} }
} }
/**
* Validate the options form.
*/
public function validateOptionsForm(&$form, &$form_state) { }
/** /**
* Build the options form. * Build the options form.
*/ */
@ -322,12 +317,6 @@ abstract class HandlerBase extends PluginBase {
\Drupal::moduleHandler()->alter('views_handler_options', $this->options, $this->view); \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. * 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 * This gives all the handlers some time to set up before any handler has
* been fully run. * 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. * 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() { } public function adminSummary() { }
@ -629,10 +625,12 @@ abstract class HandlerBase extends PluginBase {
public function validate() { return array(); } 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. * a placeholder used when a handler can't be found.
*/ */
public function broken() { } public function broken() {
return FALSE;
}
/** /**
* Creates cross-database SQL date formatting. * Creates cross-database SQL date formatting.

View File

@ -9,7 +9,6 @@ namespace Drupal\views\Plugin\views\area;
use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\PluginBase;
use Drupal\views\Plugin\views\HandlerBase; 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() { protected function defineOptions() {
$options = parent::defineOptions(); $options = parent::defineOptions();
@ -59,15 +68,14 @@ abstract class AreaPluginBase extends HandlerBase {
} }
/** /**
* Provide extra data to the administration form * {@inheritdoc}
*/ */
public function adminSummary() { public function adminSummary() {
return $this->adminLabel(); return $this->adminLabel();
} }
/** /**
* Default options form that provides the label widget that all fields * {@inheritdoc}
* should have.
*/ */
public function buildOptionsForm(&$form, &$form_state) { public function buildOptionsForm(&$form, &$form_state) {
parent::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. * Performs any operations needed before full rendering.
* *
@ -119,13 +122,6 @@ abstract class AreaPluginBase extends HandlerBase {
return empty($this->options['empty']); return empty($this->options['empty']);
} }
/**
* Area handlers shouldn't have groupby.
*/
public function usesGroupBy() {
return FALSE;
}
} }
/** /**

View File

@ -7,9 +7,6 @@
namespace Drupal\views\Plugin\views\area; 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. * A special handler to take the place of missing or broken handlers.
* *
@ -19,6 +16,9 @@ use Drupal\views\ViewExecutable;
*/ */
class Broken extends AreaPluginBase { class Broken extends AreaPluginBase {
/**
* {@inheritdoc}
*/
public function adminLabel($short = FALSE) { public function adminLabel($short = FALSE) {
$args = array( $args = array(
'@module' => $this->definition['original_configuration']['provider'], '@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); 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) { public function render($empty = FALSE) {
// Simply render nothing by returning an empty render array. // 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() { public function broken() {
return TRUE; return TRUE;

View File

@ -9,7 +9,6 @@ namespace Drupal\views\Plugin\views\area;
use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutable;
use Drupal\Component\Annotation\PluginID;
/** /**
* Provides an area handler which renders an entity in a certain view mode. * 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) { public function render($empty = FALSE) {
if (!$empty || !empty($this->options['empty'])) { if (!$empty || !empty($this->options['empty'])) {

View File

@ -8,7 +8,6 @@
namespace Drupal\views\Plugin\views\area; namespace Drupal\views\Plugin\views\area;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Drupal\Component\Annotation\PluginID;
/** /**
* Alter the HTTP response status code used by the view. * Alter the HTTP response status code used by the view.

View File

@ -7,7 +7,6 @@
namespace Drupal\views\Plugin\views\area; namespace Drupal\views\Plugin\views\area;
use Drupal\Component\Annotation\PluginID;
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Xss; use Drupal\Component\Utility\Xss;
use Drupal\views\Plugin\views\style\DefaultSummary; use Drupal\views\Plugin\views\style\DefaultSummary;
@ -21,6 +20,9 @@ use Drupal\views\Plugin\views\style\DefaultSummary;
*/ */
class Result extends AreaPluginBase { class Result extends AreaPluginBase {
/**
* {@inheritdoc}
*/
protected function defineOptions() { protected function defineOptions() {
$options = parent::defineOptions(); $options = parent::defineOptions();
@ -32,6 +34,9 @@ class Result extends AreaPluginBase {
return $options; return $options;
} }
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, &$form_state) { public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state); parent::buildOptionsForm($form, $form_state);
$item_list = array( $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) { public function render($empty = FALSE) {
// Must have options and does not work on summaries. // Must have options and does not work on summaries.

View File

@ -7,8 +7,6 @@
namespace Drupal\views\Plugin\views\area; namespace Drupal\views\Plugin\views\area;
use Drupal\Component\Annotation\PluginID;
/** /**
* Views area text handler. * Views area text handler.
* *
@ -19,7 +17,7 @@ use Drupal\Component\Annotation\PluginID;
class Text extends TokenizeAreaPluginBase { class Text extends TokenizeAreaPluginBase {
/** /**
* Overrides \Drupal\views\Plugin\views\area\TokenizeAreaPluginBase::defineOptions(). * {@inheritdoc}
*/ */
protected function defineOptions() { protected function defineOptions() {
$options = parent::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) { public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state); parent::buildOptionsForm($form, $form_state);
@ -44,6 +42,9 @@ class Text extends TokenizeAreaPluginBase {
); );
} }
/**
* {@inheritdoc}
*/
public function submitOptionsForm(&$form, &$form_state) { public function submitOptionsForm(&$form, &$form_state) {
$form_state['values']['options']['format'] = $form_state['values']['options']['content']['format']; $form_state['values']['options']['format'] = $form_state['values']['options']['content']['format'];
$form_state['values']['options']['content'] = $form_state['values']['options']['content']['value']; $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) { public function render($empty = FALSE) {
$format = isset($this->options['format']) ? $this->options['format'] : filter_default_format(); $format = isset($this->options['format']) ? $this->options['format'] : filter_default_format();

View File

@ -7,8 +7,6 @@
namespace Drupal\views\Plugin\views\area; namespace Drupal\views\Plugin\views\area;
use Drupal\Component\Annotation\PluginID;
/** /**
* Views area text handler. * 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) { public function render($empty = FALSE) {
if (!$empty || !empty($this->options['empty'])) { if (!$empty || !empty($this->options['empty'])) {

View File

@ -7,8 +7,6 @@
namespace Drupal\views\Plugin\views\area; namespace Drupal\views\Plugin\views\area;
use Drupal\Component\Annotation\PluginID;
/** /**
* Views area title override handler. * Views area title override handler.
* *
@ -19,7 +17,7 @@ use Drupal\Component\Annotation\PluginID;
class Title extends AreaPluginBase { class Title extends AreaPluginBase {
/** /**
* Overrides Drupal\views\Plugin\views\AreaPluginBase::defineOptions(). * {@inheritdoc}
*/ */
protected function defineOptions() { protected function defineOptions() {
$options = parent::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) { public function buildOptionsForm(&$form, &$form_state) {
parent::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) { public function preRender(array $results) {
parent::preRender($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) { public function render($empty = FALSE) {
// Do nothing for this handler by returning an empty render array. // Do nothing for this handler by returning an empty render array.

View File

@ -2,12 +2,13 @@
/** /**
* @file * @file
* Definition of Drupal\views\Plugin\views\area\View. * Contains \Drupal\views\Plugin\views\area\View.
*/ */
namespace Drupal\views\Plugin\views\area; 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. * Views area handlers. Insert a view inside of an area.
@ -25,6 +26,43 @@ class View extends AreaPluginBase {
*/ */
protected $isEmpty; 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} * {@inheritdoc}
*/ */
@ -37,8 +75,7 @@ class View extends AreaPluginBase {
} }
/** /**
* Default options form that provides the label widget that all fields * {@inheritdoc}
* should have.
*/ */
public function buildOptionsForm(&$form, &$form_state) { public function buildOptionsForm(&$form, &$form_state) {
parent::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) { public function render($empty = FALSE) {
if (!empty($this->options['view_to_insert'])) { if (!empty($this->options['view_to_insert'])) {
list($view_name, $display_id) = explode(':', $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)) { if (empty($view) || !$view->access($display_id)) {
return array(); return array();
} }