Commit 30e1afed authored by tim.plunkett's avatar tim.plunkett
Browse files

Issue #1744334 by dawehner: Move uses_row_class(), uses_row_plugin(), and...

Issue #1744334 by dawehner: Move uses_row_class(), uses_row_plugin(), and uses_fields() from plugin annotation to a class property.
parent e6bddaea
......@@ -2054,7 +2054,7 @@ function views_ui_import_validate($form, &$form_state) {
drupal_set_message(t('Style plugin @plugin is not available.', array('@plugin' => $display->handler->get_option('style_plugin'))), 'error');
$broken = TRUE;
}
elseif ($plugin->uses_row_plugin()) {
elseif ($plugin->usesRowPlugin()) {
$plugin = views_get_plugin('row', $display->handler->get_option('row_plugin'));
if (!$plugin) {
drupal_set_message(t('Row plugin @plugin is not available.', array('@plugin' => $display->handler->get_option('row_plugin'))), 'error');
......@@ -2210,7 +2210,7 @@ function views_ui_edit_form_get_bucket($type, $view, $display) {
case 'field':
// Fetch the style plugin info so we know whether to list fields or not.
$style_plugin = $display->handler->get_plugin();
$uses_fields = $style_plugin && $style_plugin->uses_fields();
$uses_fields = $style_plugin && $style_plugin->usesFields();
if (!$uses_fields) {
$build['fields'][] = array(
'#markup' => t('The selected style or row format does not utilize fields.'),
......
......@@ -843,11 +843,13 @@ function get_option($option) {
/**
* Determine if the display's style uses fields.
*
* @return bool
*/
function uses_fields() {
$plugin = $this->get_plugin();
function usesFields() {
$plugin = $this->get_plugin('style');
if ($plugin) {
return $plugin->uses_fields();
return $plugin->usesFields();
}
}
......@@ -1218,7 +1220,7 @@ function options_summary(&$categories, &$options) {
$options['style_plugin']['links']['style_options'] = t('Change settings for this format');
}
if (!empty($style_plugin['uses_row_plugin'])) {
if ($style_plugin_instance->usesRowPlugin()) {
$manager = new ViewsPluginManager('row');
$row_plugin = $manager->getDefinition($this->get_option('row_plugin'));
$row_plugin_instance = $this->get_plugin('row');
......@@ -1947,7 +1949,7 @@ function options_form(&$form, &$form_state) {
}
}
if ($plugin->uses_row_plugin()) {
if ($plugin->usesRowPlugin()) {
$row_plugin = $this->get_plugin('row');
if ($row_plugin) {
$funcs[] = $this->option_link(t('Row style output'), 'analyze-theme-row') . ': ' . $this->format_themes($row_plugin->theme_functions());
......@@ -1960,7 +1962,7 @@ function options_form(&$form, &$form_state) {
}
}
if ($plugin->uses_fields()) {
if ($plugin->usesFields()) {
foreach ($this->get_handlers('field') as $id => $handler) {
$funcs[] = $this->option_link(t('Field @field (ID: @id)', array('@field' => $handler->ui_name(), '@id' => $id)), 'analyze-theme-field') . ': ' . $this->format_themes($handler->theme_functions());
}
......@@ -2729,7 +2731,7 @@ function get_style_type() { return 'normal'; }
function validate() {
$errors = array();
// Make sure displays that use fields HAVE fields.
if ($this->uses_fields()) {
if ($this->usesFields()) {
$fields = FALSE;
foreach ($this->get_handlers('field') as $field) {
if (empty($field->options['exclude'])) {
......@@ -2946,7 +2948,7 @@ function export_style($indent, $prefix, $storage, $option, $definition, $parents
$plugin = $style_plugin;
}
else {
if (!$style_plugin || !$style_plugin->uses_row_plugin()) {
if (!$style_plugin || !$style_plugin->usesRowPlugin()) {
return;
}
......@@ -3007,7 +3009,7 @@ function unpack_style($indent, $prefix, $storage, $option, $definition, $parents
$plugin = $style_plugin;
}
else {
if (!$style_plugin || !$style_plugin->uses_row_plugin()) {
if (!$style_plugin || !$style_plugin->usesRowPlugin()) {
return;
}
......
......@@ -37,7 +37,7 @@ function options_form(&$form, &$form_state) {
$this->view->init_style();
// Allow to choose all fields as possible
if ($this->view->style_plugin->uses_fields()) {
if ($this->view->style_plugin->usesFields()) {
$options = array();
foreach ($this->view->display_handler->get_handlers('field') as $name => $field) {
$options[$name] = $field->ui_name(TRUE);
......
......@@ -23,13 +23,19 @@
* title = @Translation("Fields"),
* help = @Translation("Displays the fields with an optional template."),
* theme = "views_view_fields",
* uses_fields = TRUE,
* type = "normal",
* help_topic = "style-row-fields"
* )
*/
class Fields extends RowPluginBase {
/**
* Does the row plugin support to add fields to it's output.
*
* @var bool
*/
public $usesFields = TRUE;
function option_definition() {
$options = parent::option_definition();
......
......@@ -31,6 +31,13 @@ abstract class RowPluginBase extends PluginBase {
*/
public $usesOptions = TRUE;
/**
* Does the row plugin support to add fields to it's output.
*
* @var bool
*/
public $usesFields = FALSE;
/**
* Initialize the row plugin.
*/
......@@ -42,8 +49,13 @@ function init(&$view, &$display, $options = NULL) {
$this->unpack_options($this->options, isset($options) ? $options : $display->handler->get_option('row_options'));
}
function uses_fields() {
return !empty($this->definition['uses_fields']);
/**
* Returns the usesFields property.
*
* @return bool
*/
function usesFields() {
return $this->usesFields;
}
......
......@@ -18,13 +18,19 @@
* title = @Translation("Fields"),
* help = @Translation("Display fields as RSS items."),
* theme = "views_view_row_rss",
* uses_fields = TRUE,
* type = "feed",
* help_topic = "style-row-fields"
* )
*/
class RssFields extends RowPluginBase {
/**
* Does the row plugin support to add fields to it's output.
*
* @var bool
*/
public $usesFields = TRUE;
function option_definition() {
$options = parent::option_definition();
$options['title_field'] = array('default' => '');
......
......@@ -21,8 +21,6 @@
* title = @Translation("Unformatted list"),
* help = @Translation("Displays rows one after another."),
* theme = "views_view_unformatted",
* uses_row_plugin = TRUE,
* uses_row_class = TRUE,
* uses_grouping = TRUE,
* type = "normal",
* help_topic = "style-unformatted"
......@@ -30,6 +28,20 @@
*/
class DefaultStyle extends StylePluginBase {
/**
* Does the style plugin allows to use style plugins.
*
* @var bool
*/
public $usesRowPlugin = TRUE;
/**
* Does the style plugin support custom css class for the rows.
*
* @var bool
*/
public $usesRowClass = TRUE;
/**
* Set default options
*/
......
......@@ -20,15 +20,26 @@
* title = @Translation("Grid"),
* help = @Translation("Displays rows in a grid."),
* theme = "views_view_grid",
* uses_fields = FALSE,
* uses_row_plugin = TRUE,
* uses_row_class = TRUE,
* type = "normal",
* help_topic = "style-grid"
* )
*/
class Grid extends StylePluginBase {
/**
* Does the style plugin allows to use style plugins.
*
* @var bool
*/
public $usesRowPlugin = TRUE;
/**
* Does the style plugin support custom css class for the rows.
*
* @var bool
*/
public $usesRowClass = TRUE;
/**
* Set default options
*/
......
......@@ -20,14 +20,26 @@
* title = @Translation("HTML List"),
* help = @Translation("Displays rows as HTML list."),
* theme = "views_view_list",
* uses_row_plugin = TRUE,
* uses_row_class = TRUE,
* type = "normal",
* help_topic = "style-list"
* )
*/
class HtmlList extends StylePluginBase {
/**
* Does the style plugin allows to use style plugins.
*
* @var bool
*/
public $usesRowPlugin = TRUE;
/**
* Does the style plugin support custom css class for the rows.
*
* @var bool
*/
public $usesRowClass = TRUE;
/**
* Set default options
*/
......
......@@ -20,13 +20,19 @@
* title = @Translation("RSS Feed"),
* help = @Translation("Generates an RSS feed from a view."),
* theme = "views_view_rss",
* uses_row_plugin = TRUE,
* type = "feed",
* help_topic = "style-rss"
* )
*/
class Rss extends StylePluginBase {
/**
* Does the style plugin for itself support to add fields to it's output.
*
* @var bool
*/
public $usesRowPlugin = TRUE;
function attach_to($display_id, $path, $title) {
$display = $this->view->display[$display_id]->handler;
$url_options = array();
......
......@@ -48,6 +48,30 @@ abstract class StylePluginBase extends PluginBase {
*/
var $row_plugin;
/**
* Does the style plugin allows to use style plugins.
*
* @var bool
*/
public $usesRowPlugin = FALSE;
/**
* Does the style plugin support custom css class for the rows.
*
* @var bool
*/
public $usesRowClass = FALSE;
/**
* Does the style plugin for itself support to add fields to it's output.
*
* This option only makes sense on style plugins without row plugins, like
* for example table.
*
* @var bool
*/
public $usesFields = FALSE;
/**
* Initialize a style plugin.
*
......@@ -64,7 +88,7 @@ function init(&$view, &$display, $options = NULL) {
// Overlay incoming options on top of defaults
$this->unpack_options($this->options, isset($options) ? $options : $display->handler->get_option('style_options'));
if ($this->uses_row_plugin() && $display->handler->get_option('row_plugin')) {
if ($this->usesRowPlugin() && $display->handler->get_option('row_plugin')) {
$this->row_plugin = $display->handler->get_plugin('row');
}
......@@ -86,17 +110,22 @@ function destroy() {
}
/**
* Return TRUE if this style also uses a row plugin.
* Returns the usesRowPlugin property.
*
* @return bool
*/
function uses_row_plugin() {
return !empty($this->definition['uses_row_plugin']);
function usesRowPlugin() {
return $this->usesRowPlugin;
}
/**
* Return TRUE if this style also uses a row plugin.
* Returns the usesRowClass property.
*
* @return bool
*/
function uses_row_class() {
return !empty($this->definition['uses_row_class']);
function usesRowClass() {
return $this->usesRowClass;
}
/**
......@@ -104,15 +133,15 @@ function uses_row_class() {
*
* @return bool
*/
function uses_fields() {
function usesFields() {
// If we use a row plugin, ask the row plugin. Chances are, we don't
// care, it does.
$row_uses_fields = FALSE;
if ($this->uses_row_plugin() && !empty($this->row_plugin)) {
$row_uses_fields = $this->row_plugin->uses_fields();
if ($this->usesRowPlugin() && !empty($this->row_plugin)) {
$row_uses_fields = $this->row_plugin->usesFields();
}
// Otherwise, check the definition or the option.
return $row_uses_fields || !empty($this->definition['uses_fields']) || !empty($this->options['uses_fields']);
return $row_uses_fields || $this->usesFields || !empty($this->options['uses_fields']);
}
/**
......@@ -121,7 +150,7 @@ function uses_fields() {
* Used to ensure we don't fetch tokens when not needed for performance.
*/
function uses_tokens() {
if ($this->uses_row_class()) {
if ($this->usesRowClass()) {
$class = $this->options['row_class'];
if (strpos($class, '[') !== FALSE || strpos($class, '!') !== FALSE || strpos($class, '%') !== FALSE) {
return TRUE;
......@@ -133,9 +162,9 @@ function uses_tokens() {
* Return the token replaced row class for the specified row.
*/
function get_row_class($row_index) {
if ($this->uses_row_class()) {
if ($this->usesRowClass()) {
$class = $this->options['row_class'];
if ($this->uses_fields() && $this->view->field) {
if ($this->usesFields() && $this->view->field) {
$class = strip_tags($this->tokenize_value($class, $row_index));
}
......@@ -181,7 +210,7 @@ function even_empty() {
function option_definition() {
$options = parent::option_definition();
$options['grouping'] = array('default' => array());
if ($this->uses_row_class()) {
if ($this->usesRowClass()) {
$options['row_class'] = array('default' => '');
$options['default_row_class'] = array('default' => TRUE, 'bool' => TRUE);
$options['row_class_special'] = array('default' => TRUE, 'bool' => TRUE);
......@@ -197,7 +226,7 @@ function options_form(&$form, &$form_state) {
// themselves from being groupable by setting their "use grouping" definiton
// key to FALSE.
// @TODO: Document "uses grouping" in docs.php when docs.php is written.
if ($this->uses_fields() && $this->definition['uses_grouping']) {
if ($this->usesFields() && $this->definition['uses_grouping']) {
$options = array('' => t('- None -'));
$field_labels = $this->display->handler->get_field_labels(TRUE);
$options += $field_labels;
......@@ -251,7 +280,7 @@ function options_form(&$form, &$form_state) {
}
}
if ($this->uses_row_class()) {
if ($this->usesRowClass()) {
$form['row_class'] = array(
'#title' => t('Row class'),
'#description' => t('The class to provide on each row.'),
......@@ -259,7 +288,7 @@ function options_form(&$form, &$form_state) {
'#default_value' => $this->options['row_class'],
);
if ($this->uses_fields()) {
if ($this->usesFields()) {
$form['row_class']['#description'] .= ' ' . t('You may use field tokens from as per the "Replacement patterns" used in "Rewrite the output of this field" for all fields.');
}
......@@ -277,7 +306,7 @@ function options_form(&$form, &$form_state) {
);
}
if (!$this->uses_fields() || !empty($this->options['uses_fields'])) {
if (!$this->usesFields() || !empty($this->options['uses_fields'])) {
$form['uses_fields'] = array(
'#type' => 'checkbox',
'#title' => t('Force using fields'),
......@@ -328,7 +357,7 @@ function pre_render($result) {
* Render the display in this style.
*/
function render() {
if ($this->uses_row_plugin() && empty($this->row_plugin)) {
if ($this->usesRowPlugin() && empty($this->row_plugin)) {
vpr('Drupal\views\Plugin\views\style\StylePluginBase: Missing row plugin');
return;
}
......@@ -374,7 +403,7 @@ function render_grouping_sets($sets, $level = 0) {
}
// Render as a record set.
else {
if ($this->uses_row_plugin()) {
if ($this->usesRowPlugin()) {
foreach ($set['rows'] as $index => $row) {
$this->view->row_index = $index;
$set['rows'][$index] = $this->row_plugin->render($row);
......@@ -523,7 +552,7 @@ function render_grouping($records, $groupings = array(), $group_rendered = NULL)
* The result array from $view->result
*/
function render_fields($result) {
if (!$this->uses_fields()) {
if (!$this->usesFields()) {
return;
}
......@@ -586,7 +615,7 @@ function get_field_value($index, $field) {
function validate() {
$errors = parent::validate();
if ($this->uses_row_plugin()) {
if ($this->usesRowPlugin()) {
$plugin = $this->display->handler->get_plugin('row');
if (empty($plugin)) {
$errors[] = t('Style @style requires a row style but the row plugin is invalid.', array('@style' => $this->definition['title']));
......
......@@ -20,15 +20,33 @@
* title = @Translation("Table"),
* help = @Translation("Displays rows in a table."),
* theme = "views_view_table",
* uses_row_plugin = FALSE,
* uses_row_class = TRUE,
* uses_fields = TRUE,
* type = "normal",
* help_topic = "style-table"
* )
*/
class Table extends StylePluginBase {
/**
* Does the style plugin for itself support to add fields to it's output.
*
* @var bool
*/
public $usesFields = TRUE;
/**
* Does the style plugin allows to use style plugins.
*
* @var bool
*/
public $usesRowPlugin = FALSE;
/**
* Does the style plugin support custom css class for the rows.
*
* @var bool
*/
public $usesRowClass = TRUE;
/**
* Contains the current active sort column.
* @var string
......
......@@ -278,7 +278,7 @@ protected function build_form_style(&$form, &$form_state, $type) {
// @fixme
$style_plugin = views_get_plugin('style', $style);
if (isset($style_plugin) && $style_plugin->uses_row_plugin()) {
if (isset($style_plugin) && $style_plugin->usesRowPlugin()) {
$options = $this->row_style_options($type);
$style_form['row_plugin'] = array(
'#type' => 'select',
......@@ -300,7 +300,7 @@ protected function build_form_style(&$form, &$form_state, $type) {
'#theme_wrappers' => array('container'),
);
}
elseif ($style_plugin->uses_fields()) {
elseif ($style_plugin->usesFields()) {
$style_form['row_plugin'] = array('#markup' => '<span>' . t('of fields') . '</span>');
}
}
......
......@@ -1019,7 +1019,7 @@ function build($display_id = NULL) {
return FALSE;
}
if ($this->style_plugin->uses_fields()) {
if ($this->style_plugin->usesFields()) {
$this->_build('field');
}
......@@ -1245,7 +1245,7 @@ function render($display_id = NULL) {
// Give field handlers the opportunity to perform additional queries
// using the entire resultset prior to rendering.
if ($this->style_plugin->uses_fields()) {
if ($this->style_plugin->usesFields()) {
foreach ($this->field as $id => $handler) {
if (!empty($this->field[$id])) {
$this->field[$id]->pre_render($this->result);
......
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