Commit 86ec547c authored by damiankloip's avatar damiankloip Committed by tim.plunkett

Issue #1674356 by damiankloip, dawehner: Make a battleplan for the plugins.

parent 89531573
<?php
/**
* @file
* Definition of views_handler_area_text_custom.
*/
/**
* Views area text custom handler.
*
* @ingroup views_area_handlers
*/
class views_handler_area_text_custom extends views_handler_area_text {
function option_definition() {
$options = parent::option_definition();
unset($options['format']);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// Alter the form element, to be a regular text area.
$form['content']['#type'] = 'textarea';
unset($form['content']['#format']);
unset($form['content']['#wysiwyg']);
// @TODO: Use the token refactored base class.
}
// Empty, so we don't inherit options_submit from the parent.
function options_submit(&$form, &$form_state) {
}
function render($empty = FALSE) {
if (!$empty || !empty($this->options['empty'])) {
return $this->render_textarea_custom($this->options['content']);
}
return '';
}
/**
* Render a text area with filter_xss_admin.
*/
function render_textarea_custom($value) {
if ($value) {
if ($this->options['tokenize']) {
$value = $this->view->style_plugin->tokenize_value($value, 0);
}
return $this->sanitize_value($value, 'xss_admin');
}
}
}
......@@ -8,6 +8,7 @@
use Drupal\Core\Database\Database;
use Drupal\views\View;
use Drupal\views\Analyzer;
use Drupal\views\Plugins\Type\WizardManager;
/**
* Create an array of Views admin CSS for adding or attaching.
......
This diff is collapsed.
<?php
/**
* @file
* Definition of Drupal\views\Plugin\Discovery\ViewsDiscovery.
*/
namespace Drupal\views\Plugins\Discovery;
use Drupal\Core\Plugin\Discovery\HookDiscovery;
/**
* Discovery interface which supports the hook_views_plugins mechanism.
*/
class ViewsDiscovery extends HookDiscovery {
/**
* The plugin type in views which should be discovered, for example query.
*
* @var string
*/
protected $viewsPluginType;
/**
* Constructs a Drupal\views\Plugin\Discovery\ViewsDiscovery object.
*
* @param string $hook
* The Drupal hook that a module can implement in order to interface to
* this discovery class.
* @param string $plugin_type
* The plugin type in views which should be discovered, for example query.
*/
function __construct($hook, $plugin_type) {
$this->viewsPluginType = $plugin_type;
parent::__construct($hook);
}
/**
* Implements Drupal\Component\Plugin\Discovery\DicoveryInterface::getDefinitions().
*/
public function getDefinitions() {
$definitions = parent::getDefinitions();
return $definitions[$this->viewsPluginType];
}
}
<?php
/**
* @file
* Definition of Drupal\views\Plugins\Type\AccessPluginManager.
*/
namespace Drupal\views\Plugins\Type;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\views\Plugins\Discovery\ViewsDiscovery;
class AccessPluginManager extends PluginManagerBase {
public function __construct() {
$this->discovery = new ViewsDiscovery('views_plugins', 'access');
$this->factory = new DefaultFactory($this);
}
}
<?php
/**
* @file
* Definition of Drupal\views\Plugins\Type\ArgumentPluginManager.
*/
namespace Drupal\views\Plugins\Type;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\views\Plugins\Discovery\ViewsDiscovery;
class ArgumentPluginManager extends PluginManagerBase {
public function __construct() {
$this->discovery = new ViewsDiscovery('views_plugins', 'argument');
$this->factory = new DefaultFactory($this);
}
}
<?php
/**
* @file
* Definition of Drupal\views\Plugins\Type\CachePluginManager.
*/
namespace Drupal\views\Plugins\Type;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\views\Plugins\views\Discovery\ViewsDiscovery;
class CachePluginManager extends PluginManagerBase {
public function __construct() {
$this->discovery = new ViewsDiscovery('views_plugins', 'cache');
$this->factory = new DefaultFactory($this);
}
}
<?php
/**
* @file
* Definition of Drupal\views\Plugins\Type\DisplayExtenderPluginManager.
*/
namespace Drupal\views\Plugins\Type;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\views\Plugins\views\Discovery\ViewsDiscovery;
class DisplayPluginManager extends PluginManagerBase {
public function __construct() {
$this->discovery = new ViewsDiscovery('views_plugins', 'display_extender');
$this->factory = new DefaultFactory($this);
}
}
<?php
/**
* @file
* Definition of Drupal\views\Plugins\Type\DisplayPluginManager.
*/
namespace Drupal\views\Plugins\Type;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\views\Plugins\views\Discovery\ViewsDiscovery;
class DisplayPluginManager extends PluginManagerBase {
public function __construct() {
$this->discovery = new ViewsDiscovery('views_plugins', 'display');
$this->factory = new DefaultFactory($this);
}
}
<?php
/**
* @file
* Definition of Drupal\views\Plugins\Type\ExposedFormPluginManager.
*/
namespace Drupal\views\Plugins\Type;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\views\Plugins\views\Discovery\ViewsDiscovery;
class ExposedFormPluginManager extends PluginManagerBase {
public function __construct() {
$this->discovery = new ViewsDiscovery('views_plugins', 'exposed_form');
$this->factory = new DefaultFactory($this);
}
}
<?php
/**
* @file
* Definition of Drupal\views\Plugins\Type\HandlerPluginManager.
*/
namespace Drupal\views\Plugins\Type;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\views\Plugins\views\Discovery\ViewsDiscovery;
class HandlerPluginManager extends PluginManagerBase {
public function __construct() {
$this->discovery = new ViewsDiscovery('views_plugins', 'handler');
$this->factory = new DefaultFactory($this);
}
}
<?php
/**
* @file
* Definition of Drupal\views\Plugins\Type\LocalizationPluginManager.
*/
namespace Drupal\views\Plugins\Type;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\views\Plugins\views\Discovery\ViewsDiscovery;
class LocalizationPluginManager extends PluginManagerBase {
public function __construct() {
$this->discovery = new ViewsDiscovery('views_plugins', 'localization');
$this->factory = new DefaultFactory($this);
}
}
<?php
/**
* @file
* Definition of Drupal\views\Plugins\Type\PagerPluginManager.
*/
namespace Drupal\views\Plugins\Type;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\views\Plugins\Discovery\ViewsDiscovery;
class PagerPluginManager extends PluginManagerBase {
public function __construct() {
$this->discovery = new ViewsDiscovery('views_plugins', 'pager');
$this->factory = new DefaultFactory($this);
}
}
<?php
/**
* @file
* Definition of Drupal\views\Plugins\Type\QueryPluginManager.
*/
namespace Drupal\views\Plugins\Type;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\views\Plugins\Discovery\ViewsDiscovery;
class QueryPluginManager extends PluginManagerBase {
public function __construct() {
$this->discovery = new ViewsDiscovery('views_plugins', 'query');
$this->factory = new DefaultFactory($this);
}
}
<?php
/**
* @file
* Definition of Drupal\views\Plugins\Type\RowPluginManager.
*/
namespace Drupal\views\Plugins\Type;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\views\Plugins\Discovery\ViewsDiscovery;
class RowPluginManager extends PluginManagerBase {
public function __construct() {
$this->discovery = new ViewsDiscovery('views_plugins', 'row');
$this->factory = new DefaultFactory($this);
}
}
<?php
/**
* @file
* Definition of Drupal\views\Plugins\Type\StylePluginManager.
*/
namespace Drupal\views\Plugins\Type;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\views\Plugins\Discovery\ViewsDiscovery;
class StylePluginManager extends PluginManagerBase {
public function __construct() {
$this->discovery = new ViewsDiscovery('views_plugins', 'style');
$this->factory = new DefaultFactory($this);
}
}
<?php
/**
* @file
* Definition of Drupal\views\Plugins\Type\WizardManager.
*/
namespace Drupal\views\Plugins\Type;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Plugin\Discovery\HookDiscovery;
use Drupal\Core\Plugin\MapClassLoader;
class WizardManager extends PluginManagerBase {
public function __construct() {
$this->discovery = new HookDiscovery('views_wizard');
$this->factory = new DefaultFactory($this->discovery);
}
}
This diff is collapsed.
<?php
/**
* @file
* Definition of Drupal\views\Plugin\PluginInterface.
*/
namespace Drupal\views\Plugins\views;
use Drupal\Component\Plugin\PluginInspectionInterface;
interface PluginInterface extends PluginInspectionInterface {
}
......@@ -2,9 +2,13 @@
/**
* @file
* Definition of views_plugin_access.
* Definition of Drupal\views\Plugins\views\access\AccessPluginBase.
*/
namespace Drupal\views\Plugins\views\access;
use Drupal\views\Plugins\views\Plugin;
/**
* @defgroup views_access_plugins Views access plugins
* @{
......@@ -16,7 +20,7 @@
/**
* The base plugin to handle access control.
*/
class views_plugin_access extends views_plugin {
class AccessPluginBase extends Plugin {
/**
* Initialize the plugin.
*
......
......@@ -2,15 +2,17 @@
/**
* @file
* Definition of views_plugin_access_none.
* Definition of Drupal\views\Plugins\views\access\None.
*/
namespace Drupal\views\Plugins\views\access;
/**
* Access plugin that provides no access control at all.
*
* @ingroup views_access_plugins
*/
class views_plugin_access_none extends views_plugin_access {
class None extends AccessPluginBase {
function summary_title() {
return t('Unrestricted');
}
......
......@@ -2,15 +2,17 @@
/**
* @file
* Definition of views_plugin_access_perm.
* Definition of Drupal\views\Plugins\views\access\Permission.
*/
namespace Drupal\views\Plugins\views\access;
/**
* Access plugin that provides permission-based access control.
*
* @ingroup views_access_plugins
*/
class views_plugin_access_perm extends views_plugin_access {
class Permission extends AccessPluginBase {
function access($account) {
return views_check_perm($this->options['perm'], $account);
}
......
......@@ -2,15 +2,17 @@
/**
* @file
* Definition of views_plugin_access_role.
* Definition of Drupal\views\Plugins\views\access\Role.
*/
namespace Drupal\views\Plugins\views\access;
/**
* Access plugin that provides role-based access control.
*
* @ingroup views_access_plugins
*/
class views_plugin_access_role extends views_plugin_access {
class Role extends AccessPluginBase {
function access($account) {
return views_check_roles(array_filter($this->options['role']), $account);
}
......
......@@ -2,9 +2,13 @@
/**
* @file
* Views area handlers.
* Definition of Drupal\views\Plugins\views\area\AreaPluginBase.
*/
namespace Drupal\views\Plugins\views\area;
use Drupal\views\Plugins\views\Plugin;
/**
* @defgroup views_area_handlers Views area handlers
* @{
......@@ -17,21 +21,7 @@
*
* @ingroup views_area_handlers
*/
class views_handler_area extends views_handler {
/**
* Overrides views_handler::init().
*
* Make sure that no result area handlers are set to be shown when the result
* is empty.
*/
function init(&$view, &$options) {
parent::init($view, $options);
if ($this->handler_type == 'empty') {
$this->options['empty'] = TRUE;
}
}
class AreaPluginBase extends Plugin {
/**
* Get this field's label.
*/
......@@ -48,7 +38,7 @@ function option_definition() {
$this->definition['field'] = !empty($this->definition['field']) ? $this->definition['field'] : '';
$label = !empty($this->definition['label']) ? $this->definition['label'] : $this->definition['field'];
$options['label'] = array('default' => $label, 'translatable' => TRUE);
$options['empty'] = array('default' => FALSE, 'bool' => TRUE);
$options['empty'] = array('default' => 0, 'bool' => TRUE);
return $options;
}
......
<?php
/**
* @file
* Definition of Drupal\views\Plugins\views\area\result.
*/
namespace Drupal\views\Plugins\views\area;
/**
* Views area handler to display some configurable result summary.
*
* @ingroup views_area_handlers
*/
class Result extends AreaPluginBase {
function option_definition() {
$options = parent::option_definition();
$options['content'] = array(
'default' => 'Displaying @start - @end of @total',
'translatable' => TRUE,
);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$variables = array(
'items' => array(
'@start -- the initial record number in the set',
'@end -- the last record number in the set',
'@total -- the total records in the set',
'@name -- the human-readable name of the view',
'@per_page -- the number of items per page',
'@current_page -- the current page number',
'@page_count -- the total page count',
),
);
$list = theme('item_list', $variables);
$form['content'] = array(
'#title' => t('Display'),
'#type' => 'textarea',
'#rows' => 3,
'#default_value' => $this->options['content'],
'#description' => t('You may use HTML code in this field. The following tokens are supported:') . $list,
);
}
/**
* Find out the information to render.
*/
function render($empty = FALSE) {
// Must have options and does not work on summaries.
if (!isset($this->options['content']) || $this->view->plugin_name == 'default_summary') {
return;
}
$output = '';
$format = $this->options['content'];
// Calculate the page totals.
$current_page = (int) $this->view->get_current_page() + 1;
$per_page = (int) $this->view->get_items_per_page();
$count = count($this->view->result);
// @TODO: Maybe use a possible is views empty functionality.
// Not every view has total_rows set, use view->result instead.
$total = isset($this->view->total_rows) ? $this->view->total_rows : count($this->view->result);
$name = check_plain($this->view->human_name);
if ($per_page === 0) {
$page_count = 1;
$start = 1;
$end = $total;
}
else {
$page_count = (int) ceil($total / $per_page);
$total_count = $current_page * $per_page;
if ($total_count > $total) {
$total_count = $total;
}
$start = ($current_page - 1) * $per_page + 1;
$end = $total_count;
}
// Get the search information.
$items = array('start', 'end', 'total', 'name', 'per_page', 'current_page', 'page_count');
$replacements = array();
foreach ($items as $item) {
$replacements["@$item"] = ${$item};
}
// Send the output.
if (!empty($total)) {
$output .= filter_xss_admin(str_replace(array_keys($replacements), array_values($replacements), $format));
}
return $output;
}
}
......@@ -2,15 +2,17 @@
/**
* @file
* Definition of views_handler_area_text.
* Definition of Drupal\views\Plugins\views\area\Text.
*/
namespace Drupal\views\Plugins\views\area;
/**
* Views area text handler.
*
* @ingroup views_area_handlers
*/
class views_handler_area_text extends views_handler_area {
class Text extends AreaPluginBase {
function option_definition() {
$options = parent::option_definition();
......@@ -31,7 +33,7 @@ function options_form(&$form, &$form_state) {
'#wysiwyg' => FALSE,
);
// @TODO: Refactor token handling into a base class.
$form['tokenize'] = array(
'#type' => 'checkbox',
'#title' => t('Use replacement tokens from the first row'),
......
<?php
/**
* @file
* Definition of Drupal\views\Plugins\views\area\View.
*/
namespace Drupal\views\Plugins\views\area;
/**
* Views area handlers. Insert a view inside of an area.