Commit 76c51dc7 authored by tim.plunkett's avatar tim.plunkett Committed by tim.plunkett

Issue #1788266 by tim.plunkett, dawehner: Access the different views related...

Issue #1788266 by tim.plunkett, dawehner: Access the different views related properties on the right object.
parent eebb9798
......@@ -124,7 +124,7 @@ function views_revert_views() {
continue;
}
if ($view->type == dt('Overridden')) {
$overridden[$view->name] = $view->name;
$overridden[$view->storage->name] = $view->storage->name;
}
}
......@@ -220,14 +220,14 @@ function views_revert_view($view) {
// Revert the view.
$view->delete();
// Clear its cache.
views_temp_store()->delete($view->name);
views_temp_store()->delete($view->storage->name);
// Give feedback.
$message = dt("Reverted the view '@viewname'", array('@viewname' => $view->name));
$message = dt("Reverted the view '@viewname'", array('@viewname' => $view->storage->name));
drush_log($message, 'success');
// Reverted one more view.
}
else {
drush_set_error(dt("The view '@viewname' is not overridden.", array('@viewname' => $view->name)));
drush_set_error(dt("The view '@viewname' is not overridden.", array('@viewname' => $view->storage->name)));
}
}
......@@ -319,7 +319,7 @@ function drush_views_list() {
foreach ($views as $id => $view) {
// if options were specified, check that first
// mismatch push the loop to the next view
if ($with_tags && !in_array($view->tag, $tags)) {
if ($with_tags && !in_array($view->storage->tag, $tags)) {
continue;
}
if ($with_status && !$view->disabled == $status) {
......@@ -328,21 +328,21 @@ function drush_views_list() {
if ($with_type && strtolower($view->type) !== $type[0]) {
continue;
}
if ($with_name && !stristr($view->name, $name[0])) {
if ($with_name && !stristr($view->storage->name, $name[0])) {
continue;
}
$row = array();
// each row entry should be in the same order as the header
$row[] = $view->name;
$row[] = $view->description;
$row[] = $view->storage->name;
$row[] = $view->storage->description;
$row[] = $view->type;
$row[] = $view->disabled ? dt('Disabled') : dt('Enabled');
$row[] = $view->tag;
$row[] = $view->storage->disabled ? dt('Disabled') : dt('Enabled');
$row[] = $view->storage->tag;
// place the row in the appropiate array,
// so we can have disabled views at the bottom
if ($view->disabled) {
if ($view->storage->disabled) {
$disabled_views[] = $row;
}
else{
......
This diff is collapsed.
......@@ -14,13 +14,6 @@
class ViewsPluginManager extends PluginManagerBase {
/**
* The handler type of this plugin manager, for example filter or field.
*
* @var string
*/
protected $type;
/**
* A list of Drupal core modules.
*
......@@ -32,11 +25,13 @@ public function __construct($type) {
// @todo Remove this hack in http://drupal.org/node/1708404.
views_init();
$this->type = $type;
$this->discovery = new CacheDecorator(new AnnotatedClassDiscovery('views', $this->type), 'views:' . $this->type, 'views');
$this->discovery = new CacheDecorator(new AnnotatedClassDiscovery('views', $type), 'views:' . $type, 'views');
$this->factory = new DefaultFactory($this);
$this->coreModules = views_core_modules();
$this->defaults += array(
'parent' => 'parent',
'plugin_type' => $type,
);
}
/**
......@@ -45,23 +40,17 @@ public function __construct($type) {
public function processDefinition(&$definition, $plugin_id) {
parent::processDefinition($definition, $plugin_id);
// If someone adds an invalid plugin ID, don't provide defaults.
// views_get_plugin() will then don't createInstance.
if (empty($definition)) {
return;
}
$module = isset($definition['module']) ? $definition['module'] : 'views';
// If this module is a core module, use views as the module directory.
$module_dir = in_array($module, $this->coreModules) ? 'views' : $module;
$theme_path = drupal_get_path('module', $module_dir);
// Setup automatic path/file finding for theme registration.
if ($module_dir == 'views') {
$theme_path = drupal_get_path('module', $module_dir) . '/theme';
$theme_path .= '/theme';
$theme_file = 'theme.inc';
}
else {
$theme_path = $path = drupal_get_path('module', $module_dir);
$theme_file = "$module.views.inc";
}
......@@ -69,8 +58,6 @@ public function processDefinition(&$definition, $plugin_id) {
'module' => $module_dir,
'theme path' => $theme_path,
'theme file' => $theme_file,
'parent' => 'parent',
'plugin_type' => $this->type,
);
}
......
......@@ -73,7 +73,7 @@ function render($empty = FALSE) {
// @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);
$name = check_plain($this->view->storage->getHumanName());
if ($per_page === 0) {
$page_count = 1;
$start = 1;
......
......@@ -35,7 +35,7 @@ protected function defineOptions() {
public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
$view_display = $this->view->name . ':' . $this->view->current_display;
$view_display = $this->view->storage->name . ':' . $this->view->current_display;
$options = array('' => t('-Select-'));
$options += views_get_views_as_options(FALSE, 'all', $view_display, FALSE, TRUE);
......
......@@ -301,7 +301,6 @@ public function buildOptionsForm(&$form, &$form_state) {
),
);
$validate_types = array('none' => t('- Basic validation -'));
$plugins = views_get_plugin_definitions('argument_validator');
foreach ($plugins as $id => $info) {
if (!empty($info['no_ui'])) {
......@@ -946,17 +945,8 @@ public function validateArgument($arg) {
return $this->argument_validated = TRUE;
}
if ($this->options['validate']['type'] == 'none') {
return $this->argument_validated = $this->validate_argument_basic($arg);
}
$plugin = $this->get_plugin('argument_validator');
if ($plugin) {
return $this->argument_validated = $plugin->validate_argument($arg);
}
// If the plugin isn't found, fall back to the basic validation path:
return $this->argument_validated = $this->validate_argument_basic($arg);
return $this->argument_validated = $plugin->validate_argument($arg);
}
/**
......@@ -984,25 +974,6 @@ function validate_argument($arg) {
return $rc;
}
/**
* Provide a basic argument validation.
*
* This can be overridden for more complex types; the basic
* validator only checks to see if the argument is not NULL
* or is numeric if the definition says it's numeric.
*/
function validate_argument_basic($arg) {
if (!isset($arg) || $arg === '') {
return FALSE;
}
if (!empty($this->definition['numeric']) && !isset($this->options['break_phrase']) && !is_numeric($arg)) {
return FALSE;
}
return TRUE;
}
/**
* Set the input for this argument
*
......
......@@ -51,7 +51,7 @@ function default_argument_form(&$form, &$form_state) {
*/
function get_default_argument($raw = FALSE) {
if (!$raw && $this->options['default_argument_type'] == 'date') {
return date($this->arg_format, REQUEST_TIME);
return date($this->definition['format'], REQUEST_TIME);
}
elseif (!$raw && in_array($this->options['default_argument_type'], array('node_created', 'node_changed'))) {
foreach (range(1, 3) as $i) {
......@@ -69,10 +69,10 @@ function get_default_argument($raw = FALSE) {
return parent::get_default_argument();
}
elseif ($this->options['default_argument_type'] == 'node_created') {
return date($this->arg_format, $node->created);
return date($this->definition['format'], $node->created);
}
elseif ($this->options['default_argument_type'] == 'node_changed') {
return date($this->arg_format, $node->changed);
return date($this->definition['format'], $node->changed);
}
}
......
......@@ -60,14 +60,6 @@ function default_actions($which = NULL) {
return $actions;
}
function validate_argument_basic($arg) {
if (!empty($this->options['must_not_be'])) {
return !isset($arg);
}
return parent::validate_argument_basic($arg);
}
/**
* Override the behavior of query() to prevent the query
* from being changed in any way.
......
<?php
/**
* @file
* Definition of Drupal\views\Plugin\views\argument_validator\None.
*/
namespace Drupal\views\Plugin\views\argument_validator;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Do not validate the argument.
*
* @ingroup views_argument_validate_plugins
*
* @Plugin(
* id = "none",
* title = @Translation(" - Basic validation - ")
* )
*/
class None extends ArgumentValidatorPluginBase {
function validate_argument($argument) {
if (!empty($this->argument->options['must_not_be'])) {
return !isset($argument);
}
if (!isset($argument) || $argument === '') {
return FALSE;
}
if (!empty($this->argument->definition['numeric']) && !isset($this->argument->options['break_phrase']) && !is_numeric($arg)) {
return FALSE;
}
return TRUE;
}
}
......@@ -177,7 +177,7 @@ function cache_get($type) {
* to be sure that we catch everything. Maybe that's a bad idea.
*/
function cache_flush() {
cache($this->table)->deletePrefix($this->view->name . ':');
cache($this->table)->deletePrefix($this->view->storage->name . ':');
}
/**
......@@ -302,7 +302,7 @@ function get_results_key() {
}
}
$this->_results_key = $this->view->name . ':' . $this->displayHandler->display['id'] . ':results:' . md5(serialize($key_data));
$this->_results_key = $this->view->storage->name . ':' . $this->displayHandler->display['id'] . ':results:' . md5(serialize($key_data));
}
return $this->_results_key;
......@@ -320,7 +320,7 @@ function get_output_key() {
'base_url' => $GLOBALS['base_url'],
);
$this->_output_key = $this->view->name . ':' . $this->displayHandler->display['id'] . ':output:' . md5(serialize($key_data));
$this->_output_key = $this->view->storage->name . ':' . $this->displayHandler->display['id'] . ':output:' . md5(serialize($key_data));
}
return $this->_output_key;
......
......@@ -85,7 +85,7 @@ abstract class DisplayPluginBase extends PluginBase {
*/
protected $usesAttachments = FALSE;
public function init(&$view, &$display, $options = NULL) {
public function init(ViewExecutable $view, &$display, $options = NULL) {
$this->setOptionDefaults($this->options, $this->defineOptions());
$this->view = &$view;
$this->display = &$display;
......@@ -769,7 +769,7 @@ public function getPlugin($type = 'style', $name = NULL) {
break;
case 'query':
$views_data = views_fetch_data($this->view->base_table);
$views_data = views_fetch_data($this->view->storage->base_table);
$name = !empty($views_data['table']['base']['query class']) ? $views_data['table']['base']['query class'] : 'views_query';
default:
$option_name = $type;
......@@ -806,10 +806,10 @@ public function getPlugin($type = 'style', $name = NULL) {
$display_id = $this->isDefaulted($option_name) ? $this->display['id'] : 'default';
if (!isset($this->base_field)) {
$views_data = views_fetch_data($this->view->base_table);
$this->view->base_field = !empty($views_data['table']['base']['field']) ? $views_data['table']['base']['field'] : '';
$views_data = views_fetch_data($this->view->storage->base_table);
$this->view->storage->base_field = !empty($views_data['table']['base']['field']) ? $views_data['table']['base']['field'] : '';
}
$plugin->init($this->view->base_table, $this->view->base_field, $options);
$plugin->init($this->view->storage->base_table, $this->view->storage->base_field, $options);
}
$cache[$type][$name] = $plugin;
}
......@@ -980,7 +980,7 @@ public function optionLink($text, $section, $class = '', $title = '') {
$title = $text;
}
return l($text, 'admin/structure/views/nojs/display/' . $this->view->name . '/' . $this->display['id'] . '/' . $section, array('attributes' => array('class' => 'views-ajax-link ' . $class, 'title' => $title, 'id' => drupal_html_id('views-' . $this->display['id'] . '-' . $section)), 'html' => TRUE));
return l($text, 'admin/structure/views/nojs/display/' . $this->view->storage->name . '/' . $this->display['id'] . '/' . $section, array('attributes' => array('class' => 'views-ajax-link ' . $class, 'title' => $title, 'id' => drupal_html_id('views-' . $this->display['id'] . '-' . $section)), 'html' => TRUE));
}
/**
......@@ -1478,7 +1478,7 @@ public function buildOptionsForm(&$form, &$form_state) {
$access = $this->getOption('access');
$form['access']['type'] = array(
'#type' => 'radios',
'#options' => views_fetch_plugin_names('access', NULL, array($this->view->base_table)),
'#options' => views_fetch_plugin_names('access', NULL, array($this->view->storage->base_table)),
'#default_value' => $access['type'],
);
......@@ -1518,7 +1518,7 @@ public function buildOptionsForm(&$form, &$form_state) {
$cache = $this->getOption('cache');
$form['cache']['type'] = array(
'#type' => 'radios',
'#options' => views_fetch_plugin_names('cache', NULL, array($this->view->base_table)),
'#options' => views_fetch_plugin_names('cache', NULL, array($this->view->storage->base_table)),
'#default_value' => $cache['type'],
);
......@@ -1584,7 +1584,7 @@ public function buildOptionsForm(&$form, &$form_state) {
// Doesn't make sense to show a field setting here if we aren't querying
// an entity base table. Also, we make sure that there's at least one
// entity type with a translation handler attached.
if (in_array($this->view->base_table, $entity_tables) && $has_translation_handlers) {
if (in_array($this->view->storage->base_table, $entity_tables) && $has_translation_handlers) {
$languages = array(
'***CURRENT_LANGUAGE***' => t("Current user's language"),
'***DEFAULT_LANGUAGE***' => t("Default site language"),
......@@ -1613,7 +1613,7 @@ public function buildOptionsForm(&$form, &$form_state) {
$form['#title'] .= t('How should this view be styled');
$form['style_plugin'] = array(
'#type' => 'radios',
'#options' => views_fetch_plugin_names('style', $this->getStyleType(), array($this->view->base_table)),
'#options' => views_fetch_plugin_names('style', $this->getStyleType(), array($this->view->storage->base_table)),
'#default_value' => $this->getOption('style_plugin'),
'#description' => t('If the style you choose has settings, be sure to click the settings button that will appear next to it in the View summary.'),
);
......@@ -1654,7 +1654,7 @@ public function buildOptionsForm(&$form, &$form_state) {
$form['#title'] .= t('How should each row in this view be styled');
$form['row_plugin'] = array(
'#type' => 'radios',
'#options' => views_fetch_plugin_names('row', $this->getStyleType(), array($this->view->base_table)),
'#options' => views_fetch_plugin_names('row', $this->getStyleType(), array($this->view->storage->base_table)),
'#default_value' => $this->getOption('row_plugin'),
);
......@@ -1843,7 +1843,7 @@ public function buildOptionsForm(&$form, &$form_state) {
'#markup' => '<div class="form-item description"><p>' . t('This section lists all possible templates for the display plugin and for the style plugins, ordered roughly from the least specific to the most specific. The active template for each plugin -- which is the most specific template found on the system -- is highlighted in bold.') . '</p></div>',
);
if (isset($this->view->display[$this->view->current_display]->new_id)) {
if (isset($this->view->display_handler->new_id)) {
$form['important']['new_id'] = array(
'#prefix' => '<div class="description">',
'#suffix' => '</div>',
......@@ -2012,7 +2012,7 @@ public function buildOptionsForm(&$form, &$form_state) {
$exposed_form = $this->getOption('exposed_form');
$form['exposed_form']['type'] = array(
'#type' => 'radios',
'#options' => views_fetch_plugin_names('exposed_form', NULL, array($this->view->base_table)),
'#options' => views_fetch_plugin_names('exposed_form', NULL, array($this->view->storage->base_table)),
'#default_value' => $exposed_form['type'],
);
......@@ -2046,7 +2046,7 @@ public function buildOptionsForm(&$form, &$form_state) {
$pager = $this->getOption('pager');
$form['pager']['type'] = array(
'#type' => 'radios',
'#options' => views_fetch_plugin_names('pager', !$this->usesPager() ? 'basic' : NULL, array($this->view->base_table)),
'#options' => views_fetch_plugin_names('pager', !$this->usesPager() ? 'basic' : NULL, array($this->view->storage->base_table)),
'#default_value' => $pager['type'],
);
......@@ -2465,7 +2465,7 @@ public function renderMoreLink() {
if (!empty($this->view->exposed_raw_input)) {
$url_options['query'] = $this->view->exposed_raw_input;
}
$theme = views_theme_functions('views_more', $this->view, $this->view->display[$this->view->current_display]);
$theme = views_theme_functions('views_more', $this->view, $this->view->display_handler->display);
$path = check_url(url($path, $url_options));
return theme($theme, array('more_url' => $path, 'link_text' => check_plain($this->useMoreText()), 'view' => $this->view));
......@@ -2690,8 +2690,8 @@ public function getSpecialBlocks() {
$blocks = array();
if ($this->usesExposedFormInBlock()) {
$delta = '-exp-' . $this->view->name . '-' . $this->display['id'];
$desc = t('Exposed form: @view-@display_id', array('@view' => $this->view->name, '@display_id' => $this->display['id']));
$delta = '-exp-' . $this->view->storage->name . '-' . $this->display['id'];
$desc = t('Exposed form: @view-@display_id', array('@view' => $this->view->storage->name, '@display_id' => $this->display['id']));
$blocks[$delta] = array(
'info' => $desc,
......
......@@ -7,6 +7,7 @@
namespace Drupal\views\Plugin\views\display;
use Drupal\views\ViewExecutable;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Drupal\Core\Annotation\Plugin;
......@@ -43,13 +44,13 @@ class Feed extends Page {
*/
protected $usesPager = FALSE;
public function init(&$view, &$display, $options = NULL) {
public function init(ViewExecutable $view, &$display, $options = NULL) {
parent::init($view, $display, $options);
// Set the default row style. Ideally this would be part of the option
// definition, but in this case it's dependent on the view's base table,
// which we don't know until init().
$row_plugins = views_fetch_plugin_names('row', $this->getStyleType(), array($view->base_table));
$row_plugins = views_fetch_plugin_names('row', $this->getStyleType(), array($view->storage->base_table));
$default_row_plugin = key($row_plugins);
if ($this->options['row_plugin'] == '') {
$this->options['row_plugin'] = $default_row_plugin;
......
......@@ -80,7 +80,7 @@ public function executeHookMenu($callbacks) {
// views_arg_load -- which lives in views.module
$bits = explode('/', $this->getOption('path'));
$page_arguments = array($this->view->name, $this->display['id']);
$page_arguments = array($this->view->storage->name, $this->display['id']);
$this->view->initHandlers();
$view_arguments = $this->view->argument;
......@@ -141,7 +141,7 @@ public function executeHookMenu($callbacks) {
'access callback' => 'views_access',
'access arguments' => $access_arguments,
// Identify URL embedded arguments and correlate them to a handler
'load arguments' => array($this->view->name, $this->display['id'], '%index'),
'load arguments' => array($this->view->storage->name, $this->display['id'], '%index'),
);
$menu = $this->getOption('menu');
if (empty($menu)) {
......@@ -202,7 +202,7 @@ public function executeHookMenu($callbacks) {
'access callback' => 'views_access',
'access arguments' => $access_arguments,
// Identify URL embedded arguments and correlate them to a handler
'load arguments' => array($this->view->name, $this->display['id'], '%index'),
'load arguments' => array($this->view->storage->name, $this->display['id'], '%index'),
'title' => $tab_options['title'],
'description' => $tab_options['description'],
'menu_name' => $tab_options['name'],
......
......@@ -314,8 +314,8 @@ function reset_form(&$form, &$form_state) {
// remember settings.
$display_id = ($this->view->display_handler->isDefaulted('filters')) ? 'default' : $this->view->current_display;
if (isset($_SESSION['views'][$this->view->name][$display_id])) {
unset($_SESSION['views'][$this->view->name][$display_id]);
if (isset($_SESSION['views'][$this->view->storage->name][$display_id])) {
unset($_SESSION['views'][$this->view->storage->name][$display_id]);
}
// Set the form to allow redirect.
......
......@@ -1605,22 +1605,22 @@ public function themeFunctions() {
$themes = array();
$hook = 'views_view_field';
$display = $this->view->display[$this->view->current_display];
$display = $this->view->display_handler->display;
if (!empty($display)) {
$themes[] = $hook . '__' . $this->view->name . '__' . $display['id'] . '__' . $this->options['id'];
$themes[] = $hook . '__' . $this->view->name . '__' . $display['id'];
$themes[] = $hook . '__' . $this->view->storage->name . '__' . $display['id'] . '__' . $this->options['id'];
$themes[] = $hook . '__' . $this->view->storage->name . '__' . $display['id'];
$themes[] = $hook . '__' . $display['id'] . '__' . $this->options['id'];
$themes[] = $hook . '__' . $display['id'];
if ($display['id'] != $display['display_plugin']) {
$themes[] = $hook . '__' . $this->view->name . '__' . $display['display_plugin'] . '__' . $this->options['id'];
$themes[] = $hook . '__' . $this->view->name . '__' . $display['display_plugin'];
$themes[] = $hook . '__' . $this->view->storage->name . '__' . $display['display_plugin'] . '__' . $this->options['id'];
$themes[] = $hook . '__' . $this->view->storage->name . '__' . $display['display_plugin'];
$themes[] = $hook . '__' . $display['display_plugin'] . '__' . $this->options['id'];
$themes[] = $hook . '__' . $display['display_plugin'];
}
}
$themes[] = $hook . '__' . $this->view->name . '__' . $this->options['id'];
$themes[] = $hook . '__' . $this->view->name;
$themes[] = $hook . '__' . $this->view->storage->name . '__' . $this->options['id'];
$themes[] = $hook . '__' . $this->view->storage->name;
$themes[] = $hook . '__' . $this->options['id'];
$themes[] = $hook;
......
......@@ -1240,8 +1240,8 @@ function store_group_input($input, $status) {
// false means that we got a setting that means to recuse ourselves,
// so we should erase whatever happened to be there.
if ($status === FALSE && isset($_SESSION['views'][$this->view->name][$display_id])) {
$session = &$_SESSION['views'][$this->view->name][$display_id];
if ($status === FALSE && isset($_SESSION['views'][$this->view->storage->name][$display_id])) {
$session = &$_SESSION['views'][$this->view->storage->name][$display_id];
if (isset($session[$this->options['group_info']['identifier']])) {
unset($session[$this->options['group_info']['identifier']]);
......@@ -1249,11 +1249,11 @@ function store_group_input($input, $status) {
}
if ($status !== FALSE) {
if (!isset($_SESSION['views'][$this->view->name][$display_id])) {
$_SESSION['views'][$this->view->name][$display_id] = array();
if (!isset($_SESSION['views'][$this->view->storage->name][$display_id])) {
$_SESSION['views'][$this->view->storage->name][$display_id] = array();
}
$session = &$_SESSION['views'][$this->view->name][$display_id];
$session = &$_SESSION['views'][$this->view->storage->name][$display_id];
$session[$this->options['group_info']['identifier']] = $input[$this->options['group_info']['identifier']];
}
......@@ -1334,8 +1334,8 @@ public function storeExposedInput($input, $status) {
// false means that we got a setting that means to recuse ourselves,
// so we should erase whatever happened to be there.
if (!$status && isset($_SESSION['views'][$this->view->name][$display_id])) {
$session = &$_SESSION['views'][$this->view->name][$display_id];
if (!$status && isset($_SESSION['views'][$this->view->storage->name][$display_id])) {
$session = &$_SESSION['views'][$this->view->storage->name][$display_id];
if ($operator && isset($session[$this->options['expose']['operator_id']])) {
unset($session[$this->options['expose']['operator_id']]);
}
......@@ -1346,11 +1346,11 @@ public function storeExposedInput($input, $status) {
}
if ($status) {
if (!isset($_SESSION['views'][$this->view->name][$display_id])) {
$_SESSION['views'][$this->view->name][$display_id] = array();
if (!isset($_SESSION['views'][$this->view->storage->name][$display_id])) {
$_SESSION['views'][$this->view->storage->name][$display_id] = array();
}
$session = &$_SESSION['views'][$this->view->name][$display_id];
$session = &$_SESSION['views'][$this->view->storage->name][$display_id];
if ($operator && isset($input[$this->options['expose']['operator_id']])) {
$session[$this->options['expose']['operator_id']] = $input[$this->options['expose']['operator_id']];
......
......@@ -291,7 +291,7 @@ public function query() {
}
function render($input) {