Commit 55b0a054 authored by alexpott's avatar alexpott

Issue #2219689 by damiankloip: Separate out logic for...

Issue #2219689 by damiankloip: Separate out logic for getPluginTypes/viewsHandlerTypes from ViewExecutable.
parent 4f4b457d
......@@ -1839,74 +1839,7 @@ public function validate() {
* just used for header,footer,empty to link to the internal type: area.
*/
public static function getHandlerTypes() {
static $retval = NULL;
// Statically cache this so t() doesn't run a bajillion times.
if (!isset($retval)) {
$retval = array(
'field' => array(
'title' => t('Fields'), // title
'ltitle' => t('fields'), // lowercase title for mid-sentence
'stitle' => t('Field'), // singular title
'lstitle' => t('field'), // singular lowercase title for mid sentence
'plural' => 'fields',
),
'argument' => array(
'title' => t('Contextual filters'),
'ltitle' => t('contextual filters'),
'stitle' => t('Contextual filter'),
'lstitle' => t('contextual filter'),
'plural' => 'arguments',
),
'sort' => array(
'title' => t('Sort criteria'),
'ltitle' => t('sort criteria'),
'stitle' => t('Sort criterion'),
'lstitle' => t('sort criterion'),
'plural' => 'sorts',
),
'filter' => array(
'title' => t('Filter criteria'),
'ltitle' => t('filter criteria'),
'stitle' => t('Filter criterion'),
'lstitle' => t('filter criterion'),
'plural' => 'filters',
),
'relationship' => array(
'title' => t('Relationships'),
'ltitle' => t('relationships'),
'stitle' => t('Relationship'),
'lstitle' => t('Relationship'),
'plural' => 'relationships',
),
'header' => array(
'title' => t('Header'),
'ltitle' => t('header'),
'stitle' => t('Header'),
'lstitle' => t('Header'),
'plural' => 'header',
'type' => 'area',
),
'footer' => array(
'title' => t('Footer'),
'ltitle' => t('footer'),
'stitle' => t('Footer'),
'lstitle' => t('Footer'),
'plural' => 'footer',
'type' => 'area',
),
'empty' => array(
'title' => t('No results behavior'),
'ltitle' => t('no results behavior'),
'stitle' => t('No results behavior'),
'lstitle' => t('No results behavior'),
'plural' => 'empty',
'type' => 'area',
),
);
}
return $retval;
return Views::getHandlerTypes();
}
/**
......@@ -1915,28 +1848,8 @@ public static function getHandlerTypes() {
* @return array
* An array of plugin type strings.
*/
public static function getPluginTypes() {
return array(
'access',
'area',
'argument',
'argument_default',
'argument_validator',
'cache',
'display_extender',
'display',
'exposed_form',
'field',
'filter',
'join',
'pager',
'query',
'relationship',
'row',
'sort',
'style',
'wizard',
);
public static function getPluginTypes($type = NULL) {
return Views::getPluginTypes($type);
}
/**
......
......@@ -14,6 +14,20 @@
*/
class Views {
/**
* The translation manager.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface
*/
protected static $translationManager;
/**
* A static cache for handler types data.
*
* @var array
*/
protected static $handlerTypes;
/**
* Returns the views data service.
*
......@@ -368,4 +382,156 @@ public static function pluginList() {
return $plugins;
}
/**
* A list of all available views plugin types.
*
* @var array
*/
protected static $plugins = array(
'access' => 'plugin',
'area' => 'handler',
'argument' => 'handler',
'argument_default' => 'plugin',
'argument_validator' => 'plugin',
'cache' => 'plugin',
'display_extender' => 'plugin',
'display' => 'plugin',
'exposed_form' => 'plugin',
'field' => 'handler',
'filter' => 'handler',
'join' => 'plugin',
'pager' => 'plugin',
'query' => 'plugin',
'relationship' => 'handler',
'row' => 'plugin',
'sort' => 'handler',
'style' => 'plugin',
'wizard' => 'plugin',
);
/**
* Provide a list of views handler types used in a view, with some information
* about them.
*
* @return array
* An array of associative arrays containing:
* - title: The title of the handler type.
* - ltitle: The lowercase title of the handler type.
* - stitle: A singular title of the handler type.
* - lstitle: A singular lowercase title of the handler type.
* - plural: Plural version of the handler type.
* - (optional) type: The actual internal used handler type. This key is
* just used for header,footer,empty to link to the internal type: area.
*/
public static function getHandlerTypes() {
// Statically cache this so translation only occurs once per request for all
// of these values.
if (!isset(static::$handlerTypes)) {
static::$handlerTypes = array(
'field' => array(
// title
'title' => static::t('Fields'),
// Lowercase title for mid-sentence.
'ltitle' => static::t('fields'),
// Singular title.
'stitle' => static::t('Field'),
// Singular lowercase title for mid sentence
'lstitle' => static::t('field'),
'plural' => 'fields',
),
'argument' => array(
'title' => static::t('Contextual filters'),
'ltitle' => static::t('contextual filters'),
'stitle' => static::t('Contextual filter'),
'lstitle' => static::t('contextual filter'),
'plural' => 'arguments',
),
'sort' => array(
'title' => static::t('Sort criteria'),
'ltitle' => static::t('sort criteria'),
'stitle' => static::t('Sort criterion'),
'lstitle' => static::t('sort criterion'),
'plural' => 'sorts',
),
'filter' => array(
'title' => static::t('Filter criteria'),
'ltitle' => static::t('filter criteria'),
'stitle' => static::t('Filter criterion'),
'lstitle' => static::t('filter criterion'),
'plural' => 'filters',
),
'relationship' => array(
'title' => static::t('Relationships'),
'ltitle' => static::t('relationships'),
'stitle' => static::t('Relationship'),
'lstitle' => static::t('Relationship'),
'plural' => 'relationships',
),
'header' => array(
'title' => static::t('Header'),
'ltitle' => static::t('header'),
'stitle' => static::t('Header'),
'lstitle' => static::t('Header'),
'plural' => 'header',
'type' => 'area',
),
'footer' => array(
'title' => static::t('Footer'),
'ltitle' => static::t('footer'),
'stitle' => static::t('Footer'),
'lstitle' => static::t('Footer'),
'plural' => 'footer',
'type' => 'area',
),
'empty' => array(
'title' => static::t('No results behavior'),
'ltitle' => static::t('no results behavior'),
'stitle' => static::t('No results behavior'),
'lstitle' => static::t('No results behavior'),
'plural' => 'empty',
'type' => 'area',
),
);
}
return static::$handlerTypes;
}
/**
* Returns a list of plugin types.
*
* @param string $type
* (optional) filter the list of plugins by type. Available options are
* 'plugin' or 'handler'.
*
* @return array
* An array of plugin types.
*/
public static function getPluginTypes($type = NULL) {
if ($type === NULL) {
return array_keys(static::$plugins);
}
if (!in_array($type, array('plugin', 'handler'))) {
throw new \Exception('Invalid plugin type used. Valid types are "plugin" or "handler".');
}
return array_keys(array_filter(static::$plugins, function($plugin_type) use ($type) {
return $plugin_type == $type;
}));
}
/**
* Translates a string to the current language or to a given language.
*
* See the t() documentation for details.
*/
protected static function t($string, array $args = array(), array $options = array()) {
if (empty(static::$translationManager)) {
static::$translationManager = \Drupal::service('string_translation');
}
return static::$translationManager->translate($string, $args, $options);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment