Introduce a handler base plugin

8.0.x
Daniel Wehner 2012-07-27 06:53:56 -05:00 committed by Tim Plunkett
parent be8fab2fe4
commit cabe4b1995
8 changed files with 49 additions and 17 deletions

View File

@ -70,7 +70,8 @@ function _views_create_handler($definition, $type = 'handler', $handler_type = N
$handler = new $definition['override handler']; $handler = new $definition['override handler'];
} }
else { else {
$handler = new $definition['handler']; // @todo: $definition['handler'] is kind of a bad.
$handler = new $definition['handler']($definition, $definition['handler']);
} }
$handler->set_definition($definition); $handler->set_definition($definition);

View File

@ -268,7 +268,7 @@ function views_views_plugins() {
'title' => t('SQL Query'), 'title' => t('SQL Query'),
'help' => t('Query will be generated and run using the Drupal database API.'), 'help' => t('Query will be generated and run using the Drupal database API.'),
'class' => 'views_plugin_query_default', 'class' => 'views_plugin_query_default',
'class' => 'Drupal\views\Plugins\views\query\SqlQuery', 'class' => 'Drupal\views\Plugins\views\query\Sql',
), ),
), ),
'cache' => array( 'cache' => array(

View File

@ -8,6 +8,7 @@
namespace Drupal\views\Plugins\views\area; namespace Drupal\views\Plugins\views\area;
use Drupal\views\Plugins\views\Plugin; use Drupal\views\Plugins\views\Plugin;
use Drupal\views\Plugins\views\Handler;
/** /**
* @defgroup views_area_handlers Views area handlers * @defgroup views_area_handlers Views area handlers
@ -21,7 +22,7 @@ use Drupal\views\Plugins\views\Plugin;
* *
* @ingroup views_area_handlers * @ingroup views_area_handlers
*/ */
class AreaPluginBase extends Plugin { class AreaPluginBase extends Handler {
/** /**
* Get this field's label. * Get this field's label.
*/ */

View File

@ -7,7 +7,8 @@
namespace Drupal\views\Plugins\views\argument; namespace Drupal\views\Plugins\views\argument;
use Drupal\views\Plugins\Plugin; use Drupal\views\Plugins\views\Plugin;
use Drupal\views\Plugins\views\Handler;
/** /**
* @defgroup views_argument_handlers Views argument handlers * @defgroup views_argument_handlers Views argument handlers
@ -39,7 +40,7 @@ use Drupal\views\Plugins\Plugin;
* *
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
*/ */
class ArgumentPluginBase extends Plugin { class ArgumentPluginBase extends Handler {
var $validator = NULL; var $validator = NULL;
var $argument = NULL; var $argument = NULL;

View File

@ -9,7 +9,7 @@ namespace Drupal\views\Plugins\views\display;
use Drupal\views\View; use Drupal\views\View;
use Drupal\views\Plugins\views\Plugin; use Drupal\views\Plugins\views\Plugin;
use Drupal\views\Plugins\views\query\QueryPluginType; use Drupal\views\Plugins\Type\QueryPluginManager;
/** /**
* @defgroup views_display_plugins Views display plugins * @defgroup views_display_plugins Views display plugins
@ -881,6 +881,10 @@ class DisplayPluginBase extends Plugin {
// access & cache store their options as siblings with the // access & cache store their options as siblings with the
// type; all others use an 'options' array. // type; all others use an 'options' array.
if ($type != 'access' && $type != 'cache') { if ($type != 'access' && $type != 'cache') {
if (!isset($options['options'])) {
// debug($type);
// debug($options);
}
$options = $options['options']; $options = $options['options'];
} }
} }
@ -889,7 +893,7 @@ class DisplayPluginBase extends Plugin {
$plugin = views_get_plugin($type, $name); $plugin = views_get_plugin($type, $name);
} }
else { else {
$plugin_type = new QueryPluginType(); $plugin_type = new QueryPluginManager();
$plugin = $plugin_type->createInstance($name); $plugin = $plugin_type->createInstance($name);
} }

View File

@ -8,6 +8,7 @@
namespace Drupal\views\Plugins\views\field; namespace Drupal\views\Plugins\views\field;
use Drupal\views\Plugins\views\Plugin; use Drupal\views\Plugins\views\Plugin;
use Drupal\views\Plugins\views\Handler;
/** /**
* @defgroup views_field_handlers Views field handlers * @defgroup views_field_handlers Views field handlers
@ -46,7 +47,7 @@ define('VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY', 2);
* *
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class FieldPluginBase extends Plugin { class FieldPluginBase extends Handler {
var $field_alias = 'unknown'; var $field_alias = 'unknown';
var $aliases = array(); var $aliases = array();
@ -1624,7 +1625,7 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
* *
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_broken extends views_handler_field { class views_handler_field_broken extends FieldPluginBase {
function ui_name($short = FALSE) { function ui_name($short = FALSE) {
return t('Broken/missing handler'); return t('Broken/missing handler');
} }
@ -1648,7 +1649,7 @@ class views_handler_field_broken extends views_handler_field {
* *
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_file_size extends views_handler_field { class views_handler_field_file_size extends FieldPluginBase {
function option_definition() { function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
@ -1691,7 +1692,7 @@ class views_handler_field_file_size extends views_handler_field {
* *
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_xss extends views_handler_field { class views_handler_field_xss extends FieldPluginBase {
function render($values) { function render($values) {
$value = $this->get_value($values); $value = $this->get_value($values);
return $this->sanitize_value($value, 'xss'); return $this->sanitize_value($value, 'xss');

View File

@ -5,6 +5,8 @@
* Contains the basic 'node' field handler. * Contains the basic 'node' field handler.
*/ */
use Drupal\views\Plugins\views\field\FieldPluginBase;
/** /**
* Field handler to provide simple renderer that allows linking to a node. * Field handler to provide simple renderer that allows linking to a node.
* Definition terms: * Definition terms:
@ -12,7 +14,7 @@
* *
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_node extends views_handler_field { class views_handler_field_node extends FieldPluginBase {
function init(&$view, &$options) { function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);

View File

@ -1364,18 +1364,40 @@ function views_get_plugin($type, $plugin, $reset = FALSE) {
*/ */
function views_get_plugin_manager($type) { function views_get_plugin_manager($type) {
switch ($type) { switch ($type) {
case 'style':
$manager = new StylePluginManager();
break;
case 'display': case 'display':
$manager = new DisplayPluginManager(); $manager = new DisplayPluginManager();
break; break;
case 'localization': case 'style':
$manager = new LocalizationPluginManager(); $manager = new StylePluginManager();
break; break;
case 'row': case 'row':
$manager = new RowPluginManager(); $manager = new RowPluginManager();
break; break;
case 'argument default':
$manager = new ArgumentDefaultPluginManager();
break;
case 'argument validator':
$manager = new ArgumentValidatorPluginManager();
break;
case 'access':
$manager = new AccessPluginManager();
break;
case 'query':
$manager = new QueryPluginManager();
break;
case 'cache':
$manager = new CachePluginManager();
break;
// @todo: find out whether to use underscores or spaces.
case 'exposed_form':
$manager = new ExposedFormPluginManager();
break;
case 'pager':
$manager = new PagerPluginManager();
break;
case 'localization':
$manager = new LocalizationPluginManager();
break;
} }
return $manager; return $manager;