Commit 5128dcbb authored by dawehner's avatar dawehner Committed by tim.plunkett

use annotations to instanciate sorthandlers

parent a5ce14d9
......@@ -10,6 +10,8 @@
use Drupal\views\Join;
use Drupal\views\ViewsObject;
/**
* Instantiate and construct a new plugin.
*
......@@ -20,11 +22,16 @@ function _views_create_plugin($type, $plugin_id, $definition) {
$manager = views_get_plugin_manager($type);
$instance = $manager->createInstance($plugin_id);
$instance->is_plugin = TRUE;
$instance->plugin_type = $type;
$instance->plugin_name = $definition['name'];
$instance->set_definition($definition);
// Let the handler have something like a constructor.
$instance->construct();
return $instance;
}
......@@ -32,58 +39,19 @@ function _views_create_plugin($type, $plugin_id, $definition) {
* Instantiate and construct a new handler
*/
function _views_create_handler($definition, $type = 'handler', $handler_type = NULL) {
// debug('Instantiating handler ' . $definition['handler']);
if (empty($definition['handler'])) {
vpr('_views_create_handler - type: @type - failed: handler has not been provided.',
array('@type' => isset($handler_type) ? ( $type . '(handler type: ' . $handler_type . ')' ) : $type)
);
return;
}
// class_exists will automatically load the code file.
if (!empty($definition['override handler']) &&
!class_exists($definition['override handler'])) {
vpr(
'_views_create_handler - loading override handler @type failed: class @override_handler could not be loaded. ' .
'Verify the class file has been registered in the corresponding .info-file (files[]).',
array(
'@type' => isset($handler_type) ? ( $type . '(handler type: ' . $handler_type . ')' ) : $type,
'@override_handler' => $definition['override handler']
)
);
return;
}
if (!class_exists($definition['handler'])) {
vpr(
'_views_create_handler - loading handler @type failed: class @handler could not be loaded. ' .
'Verify the class file has been registered in the corresponding .info-file (files[]).',
array(
'@type' => isset($handler_type) ? ( $type . '(handler type: ' . $handler_type . ')' ) : $type,
'@handler' => $definition['handler']
)
);
return;
}
if (!empty($definition['override handler'])) {
$handler = new $definition['override handler'];
if ($definition['plugin_id']) {
$manager = views_get_plugin_manager($handler_type);
$handler = $manager->createInstance($definition['plugin_id']);
}
else {
// @todo: $definition['handler'] is kind of a bad.
// @todo: remove this else, once all instances got converted.
$handler = new $definition['handler']($definition, $definition['handler']);
}
$handler->set_definition($definition);
if ($type == 'handler') {
$handler->is_handler = TRUE;
$handler->handler_type = $handler_type;
}
else {
$handler->is_plugin = TRUE;
$handler->plugin_type = $type;
$handler->plugin_name = $definition['name'];
}
$handler->is_handler = TRUE;
$handler->handler_type = $handler_type;
// let the handler have something like a constructor.
$handler->construct();
......
......@@ -1533,7 +1533,7 @@ function get_aggregation_info() {
'argument' => 'views_handler_argument_group_by_numeric',
'field' => 'views_handler_field_numeric',
'filter' => 'views_handler_filter_group_by_numeric',
'sort' => 'views_handler_sort_group_by_numeric',
'sort' => 'groupby_numeric',
),
),
'count_distinct' => array(
......@@ -1543,7 +1543,7 @@ function get_aggregation_info() {
'argument' => 'views_handler_argument_group_by_numeric',
'field' => 'views_handler_field_numeric',
'filter' => 'views_handler_filter_group_by_numeric',
'sort' => 'views_handler_sort_group_by_numeric',
'sort' => 'groupby_numeric',
),
),
'sum' => array(
......@@ -1552,7 +1552,7 @@ function get_aggregation_info() {
'handler' => array(
'argument' => 'views_handler_argument_group_by_numeric',
'filter' => 'views_handler_filter_group_by_numeric',
'sort' => 'views_handler_sort_group_by_numeric',
'sort' => 'groupby_numeric',
),
),
'avg' => array(
......@@ -1561,7 +1561,7 @@ function get_aggregation_info() {
'handler' => array(
'argument' => 'views_handler_argument_group_by_numeric',
'filter' => 'views_handler_filter_group_by_numeric',
'sort' => 'views_handler_sort_group_by_numeric',
'sort' => 'groupby_numeric',
),
),
'min' => array(
......@@ -1570,7 +1570,7 @@ function get_aggregation_info() {
'handler' => array(
'argument' => 'views_handler_argument_group_by_numeric',
'filter' => 'views_handler_filter_group_by_numeric',
'sort' => 'views_handler_sort_group_by_numeric',
'sort' => 'groupby_numeric',
),
),
'max' => array(
......@@ -1579,7 +1579,7 @@ function get_aggregation_info() {
'handler' => array(
'argument' => 'views_handler_argument_group_by_numeric',
'filter' => 'views_handler_filter_group_by_numeric',
'sort' => 'views_handler_sort_group_by_numeric',
'sort' => 'groupby_numeric',
),
),
'stddev_pop' => array(
......@@ -1588,7 +1588,7 @@ function get_aggregation_info() {
'handler' => array(
'argument' => 'views_handler_argument_group_by_numeric',
'filter' => 'views_handler_filter_group_by_numeric',
'sort' => 'views_handler_sort_group_by_numeric',
'sort' => 'groupby_numeric',
),
)
);
......
......@@ -7,13 +7,18 @@
namespace Drupal\views\Plugins\views\sort;
use Drupal\Core\Annotation\Plugin;
/**
* Basic sort handler for dates.
*
* This handler enables granularity, which is the ability to make dates
* equivalent based upon nearness.
*
* @ingroup views_sort_handlers
* @Plugin(
* plugin_id = "date"
* )
*
*/
class Date extends SortPluginBase {
function option_definition() {
......
......@@ -7,10 +7,14 @@
namespace Drupal\views\Plugins\views\sort;
use Drupal\Core\Annotation\Plugin;
/**
* Handler for GROUP BY on simple numeric fields.
*
* @ingroup views_sort_handlers
* @Plugin(
* plugin_id = "groupby_numeric"
* )
*/
class GroupByNumeric extends SortPluginBase {
function init(&$view, &$options) {
......
......@@ -8,6 +8,8 @@
namespace Drupal\views\Plugins\views\sort;
use Drupal\views\Join;
use Drupal\Core\Annotation\Plugin;
/**
* Sort in menu hierarchy order.
......@@ -18,7 +20,9 @@
*
* This is only really useful for the {menu_links} table.
*
* @ingroup views_sort_handlers
* @Plugin(
* plugin_id = "menu_hierarchy"
* )
*/
class MenuHierarchy extends SortPluginBase {
function option_definition() {
......
......@@ -7,10 +7,14 @@
namespace Drupal\views\Plugins\views\sort;
use Drupal\Core\Annotation\Plugin;
/**
* Handle a random sort.
*
* @ingroup views_sort_handlers
* @Plugin(
* plugin_id = "random"
* )
*/
class Random extends SortPluginBase {
function query() {
......
......@@ -8,6 +8,7 @@
namespace Drupal\views\Plugins\views\sort;
use Drupal\views\Plugins\views\Handler;
use Drupal\Core\Annotation\Plugin;
/**
* @defgroup views_sort_handlers Views sort handlers
......@@ -15,11 +16,18 @@
* Handlers to tell Views how to sort queries.
*/
/**
* Base sort handler that has no options and performs a simple sort.
*
* @ingroup views_sort_handlers
*/
/**
* @Plugin(
* plugin_id = "standard"
* )
*/
class SortPluginBase extends Handler {
/**
......@@ -219,6 +227,12 @@ function expose_options() {
*
* @ingroup views_sort_handlers
*/
/**
* @Plugin(
* plugin_id = "broken"
* )
*/
class views_handler_sort_broken extends SortPluginBase {
function ui_name($short = FALSE) {
return t('Broken/missing handler');
......
......@@ -82,7 +82,7 @@ function book_views_data() {
'title' => t('Hierarchy'),
'help' => t('The order of pages in the book hierarchy.'),
'sort' => array(
'handler' => 'views_handler_sort_menu_hierarchy',
'plugin_id' => 'menu_hierarchy',
),
);
......
......@@ -343,7 +343,7 @@ function comment_views_data() {
'sort' => array(
'title' => t('Thread'),
'help' => t('Sort by the threaded order. This will keep child comments together with their parents.'),
'handler' => 'views_handler_sort_comment_thread',
'plugin_id' => 'comment_thread',
),
);
......
......@@ -6,12 +6,20 @@
*/
use Drupal\views\Plugins\views\sort\SortPluginBase;
use Drupal\Core\Annotation\Plugin;
/**
* Sort handler for ordering by thread.
*
* @ingroup views_sort_handlers
*/
/**
* @Plugin(
* plugin_id = 'comment_thread'
* )
*/
class views_handler_sort_comment_thread extends SortPluginBase {
function query() {
$this->ensure_my_table();
......
......@@ -7,7 +7,7 @@
use Drupal\views\Join;
use Drupal\views\Plugins\views\sort\SortPluginBase;
use Drupal\Core\Annotation\Plugin;
/**
* Sort handler to sort by last comment name which might be in 2 different
......@@ -15,6 +15,12 @@
*
* @ingroup views_sort_handlers
*/
/**
* @Plugin(
* plugin_id = "ncs_last_comment_name"
* )
*/
class views_handler_sort_ncs_last_comment_name extends SortPluginBase {
function query() {
$this->ensure_my_table();
......
......@@ -64,7 +64,7 @@ function node_views_data() {
),
// Information for sorting on a nid.
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
......@@ -82,7 +82,7 @@ function node_views_data() {
'link_to_node default' => TRUE,
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
// Information for accepting a title as a filter
'filter' => array(
......@@ -102,7 +102,7 @@ function node_views_data() {
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\Date',
'plugin_id' => 'date'
),
'filter' => array(
'handler' => 'Drupal\views\Plugins\views\filter\Date',
......@@ -118,7 +118,7 @@ function node_views_data() {
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\Date',
'plugin_id' => 'date'
),
'filter' => array(
'handler' => 'Drupal\views\Plugins\views\filter\Date',
......@@ -134,7 +134,7 @@ function node_views_data() {
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
'filter' => array(
'handler' => 'views_handler_filter_node_type',
......@@ -162,7 +162,7 @@ function node_views_data() {
'use equal' => TRUE, // Use status = 1 instead of status <> 0 in WHERE statment
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
......@@ -194,7 +194,7 @@ function node_views_data() {
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
'plugin_id' => 'standard',
),
);
......@@ -216,7 +216,7 @@ function node_views_data() {
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
'help' => t('Whether or not the content is sticky. To list sticky content first, set this to descending.'),
),
);
......@@ -477,7 +477,7 @@ function node_views_data() {
),
// Information for sorting on a nid.
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
'relationship' => array(
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
......@@ -499,7 +499,7 @@ function node_views_data() {
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
'filter' => array(
'handler' => 'Drupal\views\Plugins\views\filter\String',
......@@ -532,7 +532,7 @@ function node_views_data() {
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\Date',
'plugin_id' => 'date'
),
'filter' => array(
'handler' => 'Drupal\views\Plugins\views\filter\Date',
......
......@@ -70,7 +70,7 @@ function search_views_data() {
),
// Information for sorting on a search score.
'sort' => array(
'handler' => 'views_handler_sort_search_score',
'plugin_id' => 'search_score',
'no group by' => TRUE,
),
);
......
......@@ -6,12 +6,19 @@
*/
use Drupal\views\Plugins\views\sort\SortPluginBase;
use Drupal\Core\Annotation\Plugin;
/**
* Field handler to provide simple renderer that allows linking to a node.
*
* @ingroup views_sort_handlers
*/
/**
* @Plugin(
* plugin_id = "search_score"
* )
*/
class views_handler_sort_search_score extends SortPluginBase {
function query() {
// Check to see if the search filter/argument added 'score' to the table.
......
......@@ -39,7 +39,7 @@ function statistics_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\Numeric',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
......@@ -56,7 +56,7 @@ function statistics_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\Numeric',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
......@@ -73,7 +73,7 @@ function statistics_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\Date',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
......@@ -116,7 +116,7 @@ function statistics_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\Numeric',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
......@@ -136,7 +136,7 @@ function statistics_views_data() {
'handler' => 'Drupal\views\Plugins\views\argument\String',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
......@@ -153,7 +153,7 @@ function statistics_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\String',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
'argument' => array(
'handler' => 'Drupal\views\Plugins\views\sort\String',
......@@ -173,7 +173,7 @@ function statistics_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\String',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
//No argument here. Can't send forward slashes as arguments.
//Can be worked around by node ID.
......@@ -192,7 +192,7 @@ function statistics_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\String',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
......@@ -208,7 +208,7 @@ function statistics_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\String',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
'argument' => array(
'handler' => 'Drupal\views\Plugins\views\argument\String',
......@@ -238,7 +238,7 @@ function statistics_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\Numeric',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\Sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
......@@ -251,7 +251,7 @@ function statistics_views_data() {
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
'filter' => array(
'handler' => 'Drupal\views\Plugins\views\filter\Date',
......
......@@ -47,7 +47,7 @@ function system_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\Numeric',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
......@@ -60,7 +60,7 @@ function system_views_data() {
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
'filter' => array(
'handler' => 'Drupal\views\Plugins\views\filter\String',
......@@ -79,7 +79,7 @@ function system_views_data() {
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
'filter' => array(
'handler' => 'Drupal\views\Plugins\views\filter\String',
......@@ -98,7 +98,7 @@ function system_views_data() {
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
'filter' => array(
'handler' => 'Drupal\views\Plugins\views\filter\String',
......@@ -128,7 +128,7 @@ function system_views_data() {
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
'filter' => array(
'handler' => 'Drupal\views\Plugins\views\filter\Numeric',
......@@ -144,7 +144,7 @@ function system_views_data() {
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
'filter' => array(
'handler' => 'views_handler_filter_file_status',
......@@ -160,7 +160,7 @@ function system_views_data() {
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\Date',
'plugin_id' => 'date'
),
'filter' => array(
'handler' => 'Drupal\views\Plugins\views\filter\Date',
......@@ -401,7 +401,7 @@ function system_views_data() {
'handler' => 'Drupal\views\Plugins\views\argument\String',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
$data['file_usage']['type'] = array(
......@@ -418,7 +418,7 @@ function system_views_data() {
'handler' => 'Drupal\views\Plugins\views\argument\String',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
$data['file_usage']['id'] = array(
......@@ -435,7 +435,7 @@ function system_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\Numeric',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
$data['file_usage']['count'] = array(
......@@ -449,7 +449,7 @@ function system_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\Numeric',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
......@@ -481,7 +481,7 @@ function system_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\String',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
// - name
......@@ -500,7 +500,7 @@ function system_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\String',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
// - type
......@@ -519,7 +519,7 @@ function system_views_data() {
'handler' => 'views_handler_filter_system_type',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
// - status
......@@ -538,7 +538,7 @@ function system_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\BooleanOperator',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
// - schema version
......@@ -557,7 +557,7 @@ function system_views_data() {
'handler' => 'Drupal\views\Plugins\views\filter\Numeric',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
),
);
......
......@@ -44,7 +44,7 @@ function taxonomy_views_data() {
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',
'help' => t('The taxonomy vocabulary name'),
),
);
......@@ -76,7 +76,7 @@ function taxonomy_views_data() {
'name field' => 'name',
),
'sort' => array(
'handler' => 'Drupal\views\Plugins\views\sort\SortPluginBase',
'plugin_id' => 'standard',