Issue #1744334 by dawehner: Move uses_row_class(), uses_row_plugin(), and uses_fields() from plugin annotation to a class property.

8.0.x
Tim Plunkett 2012-08-23 16:29:53 +02:00
parent e6bddaea6e
commit 30e1afed56
14 changed files with 168 additions and 54 deletions

View File

@ -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'); drupal_set_message(t('Style plugin @plugin is not available.', array('@plugin' => $display->handler->get_option('style_plugin'))), 'error');
$broken = TRUE; $broken = TRUE;
} }
elseif ($plugin->uses_row_plugin()) { elseif ($plugin->usesRowPlugin()) {
$plugin = views_get_plugin('row', $display->handler->get_option('row_plugin')); $plugin = views_get_plugin('row', $display->handler->get_option('row_plugin'));
if (!$plugin) { if (!$plugin) {
drupal_set_message(t('Row plugin @plugin is not available.', array('@plugin' => $display->handler->get_option('row_plugin'))), 'error'); 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': case 'field':
// Fetch the style plugin info so we know whether to list fields or not. // Fetch the style plugin info so we know whether to list fields or not.
$style_plugin = $display->handler->get_plugin(); $style_plugin = $display->handler->get_plugin();
$uses_fields = $style_plugin && $style_plugin->uses_fields(); $uses_fields = $style_plugin && $style_plugin->usesFields();
if (!$uses_fields) { if (!$uses_fields) {
$build['fields'][] = array( $build['fields'][] = array(
'#markup' => t('The selected style or row format does not utilize fields.'), '#markup' => t('The selected style or row format does not utilize fields.'),

View File

@ -843,11 +843,13 @@ abstract class DisplayPluginBase extends PluginBase {
/** /**
* Determine if the display's style uses fields. * Determine if the display's style uses fields.
*
* @return bool
*/ */
function uses_fields() { function usesFields() {
$plugin = $this->get_plugin(); $plugin = $this->get_plugin('style');
if ($plugin) { if ($plugin) {
return $plugin->uses_fields(); return $plugin->usesFields();
} }
} }
@ -1218,7 +1220,7 @@ abstract class DisplayPluginBase extends PluginBase {
$options['style_plugin']['links']['style_options'] = t('Change settings for this format'); $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'); $manager = new ViewsPluginManager('row');
$row_plugin = $manager->getDefinition($this->get_option('row_plugin')); $row_plugin = $manager->getDefinition($this->get_option('row_plugin'));
$row_plugin_instance = $this->get_plugin('row'); $row_plugin_instance = $this->get_plugin('row');
@ -1947,7 +1949,7 @@ abstract class DisplayPluginBase extends PluginBase {
} }
} }
if ($plugin->uses_row_plugin()) { if ($plugin->usesRowPlugin()) {
$row_plugin = $this->get_plugin('row'); $row_plugin = $this->get_plugin('row');
if ($row_plugin) { if ($row_plugin) {
$funcs[] = $this->option_link(t('Row style output'), 'analyze-theme-row') . ': ' . $this->format_themes($row_plugin->theme_functions()); $funcs[] = $this->option_link(t('Row style output'), 'analyze-theme-row') . ': ' . $this->format_themes($row_plugin->theme_functions());
@ -1960,7 +1962,7 @@ abstract class DisplayPluginBase extends PluginBase {
} }
} }
if ($plugin->uses_fields()) { if ($plugin->usesFields()) {
foreach ($this->get_handlers('field') as $id => $handler) { 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()); $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 @@ abstract class DisplayPluginBase extends PluginBase {
function validate() { function validate() {
$errors = array(); $errors = array();
// Make sure displays that use fields HAVE fields. // Make sure displays that use fields HAVE fields.
if ($this->uses_fields()) { if ($this->usesFields()) {
$fields = FALSE; $fields = FALSE;
foreach ($this->get_handlers('field') as $field) { foreach ($this->get_handlers('field') as $field) {
if (empty($field->options['exclude'])) { if (empty($field->options['exclude'])) {
@ -2946,7 +2948,7 @@ abstract class DisplayPluginBase extends PluginBase {
$plugin = $style_plugin; $plugin = $style_plugin;
} }
else { else {
if (!$style_plugin || !$style_plugin->uses_row_plugin()) { if (!$style_plugin || !$style_plugin->usesRowPlugin()) {
return; return;
} }
@ -3007,7 +3009,7 @@ abstract class DisplayPluginBase extends PluginBase {
$plugin = $style_plugin; $plugin = $style_plugin;
} }
else { else {
if (!$style_plugin || !$style_plugin->uses_row_plugin()) { if (!$style_plugin || !$style_plugin->usesRowPlugin()) {
return; return;
} }

View File

@ -37,7 +37,7 @@ class Combine extends String {
$this->view->init_style(); $this->view->init_style();
// Allow to choose all fields as possible // Allow to choose all fields as possible
if ($this->view->style_plugin->uses_fields()) { if ($this->view->style_plugin->usesFields()) {
$options = array(); $options = array();
foreach ($this->view->display_handler->get_handlers('field') as $name => $field) { foreach ($this->view->display_handler->get_handlers('field') as $name => $field) {
$options[$name] = $field->ui_name(TRUE); $options[$name] = $field->ui_name(TRUE);

View File

@ -23,13 +23,19 @@ use Drupal\Core\Annotation\Translation;
* title = @Translation("Fields"), * title = @Translation("Fields"),
* help = @Translation("Displays the fields with an optional template."), * help = @Translation("Displays the fields with an optional template."),
* theme = "views_view_fields", * theme = "views_view_fields",
* uses_fields = TRUE,
* type = "normal", * type = "normal",
* help_topic = "style-row-fields" * help_topic = "style-row-fields"
* ) * )
*/ */
class Fields extends RowPluginBase { class Fields extends RowPluginBase {
/**
* Does the row plugin support to add fields to it's output.
*
* @var bool
*/
public $usesFields = TRUE;
function option_definition() { function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();

View File

@ -31,6 +31,13 @@ abstract class RowPluginBase extends PluginBase {
*/ */
public $usesOptions = TRUE; public $usesOptions = TRUE;
/**
* Does the row plugin support to add fields to it's output.
*
* @var bool
*/
public $usesFields = FALSE;
/** /**
* Initialize the row plugin. * Initialize the row plugin.
*/ */
@ -42,8 +49,13 @@ abstract class RowPluginBase extends PluginBase {
$this->unpack_options($this->options, isset($options) ? $options : $display->handler->get_option('row_options')); $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;
} }

View File

@ -18,13 +18,19 @@ use Drupal\Core\Annotation\Translation;
* title = @Translation("Fields"), * title = @Translation("Fields"),
* help = @Translation("Display fields as RSS items."), * help = @Translation("Display fields as RSS items."),
* theme = "views_view_row_rss", * theme = "views_view_row_rss",
* uses_fields = TRUE,
* type = "feed", * type = "feed",
* help_topic = "style-row-fields" * help_topic = "style-row-fields"
* ) * )
*/ */
class RssFields extends RowPluginBase { class RssFields extends RowPluginBase {
/**
* Does the row plugin support to add fields to it's output.
*
* @var bool
*/
public $usesFields = TRUE;
function option_definition() { function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['title_field'] = array('default' => ''); $options['title_field'] = array('default' => '');

View File

@ -21,8 +21,6 @@ use Drupal\Core\Annotation\Translation;
* title = @Translation("Unformatted list"), * title = @Translation("Unformatted list"),
* help = @Translation("Displays rows one after another."), * help = @Translation("Displays rows one after another."),
* theme = "views_view_unformatted", * theme = "views_view_unformatted",
* uses_row_plugin = TRUE,
* uses_row_class = TRUE,
* uses_grouping = TRUE, * uses_grouping = TRUE,
* type = "normal", * type = "normal",
* help_topic = "style-unformatted" * help_topic = "style-unformatted"
@ -30,6 +28,20 @@ use Drupal\Core\Annotation\Translation;
*/ */
class DefaultStyle extends StylePluginBase { 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 * Set default options
*/ */

View File

@ -20,15 +20,26 @@ use Drupal\Core\Annotation\Translation;
* title = @Translation("Grid"), * title = @Translation("Grid"),
* help = @Translation("Displays rows in a grid."), * help = @Translation("Displays rows in a grid."),
* theme = "views_view_grid", * theme = "views_view_grid",
* uses_fields = FALSE,
* uses_row_plugin = TRUE,
* uses_row_class = TRUE,
* type = "normal", * type = "normal",
* help_topic = "style-grid" * help_topic = "style-grid"
* ) * )
*/ */
class Grid extends StylePluginBase { 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 * Set default options
*/ */

View File

@ -20,14 +20,26 @@ use Drupal\Core\Annotation\Translation;
* title = @Translation("HTML List"), * title = @Translation("HTML List"),
* help = @Translation("Displays rows as HTML list."), * help = @Translation("Displays rows as HTML list."),
* theme = "views_view_list", * theme = "views_view_list",
* uses_row_plugin = TRUE,
* uses_row_class = TRUE,
* type = "normal", * type = "normal",
* help_topic = "style-list" * help_topic = "style-list"
* ) * )
*/ */
class HtmlList extends StylePluginBase { 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 * Set default options
*/ */

View File

@ -20,13 +20,19 @@ use Drupal\Core\Annotation\Translation;
* title = @Translation("RSS Feed"), * title = @Translation("RSS Feed"),
* help = @Translation("Generates an RSS feed from a view."), * help = @Translation("Generates an RSS feed from a view."),
* theme = "views_view_rss", * theme = "views_view_rss",
* uses_row_plugin = TRUE,
* type = "feed", * type = "feed",
* help_topic = "style-rss" * help_topic = "style-rss"
* ) * )
*/ */
class Rss extends StylePluginBase { 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) { function attach_to($display_id, $path, $title) {
$display = $this->view->display[$display_id]->handler; $display = $this->view->display[$display_id]->handler;
$url_options = array(); $url_options = array();

View File

@ -48,6 +48,30 @@ abstract class StylePluginBase extends PluginBase {
*/ */
var $row_plugin; 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. * Initialize a style plugin.
* *
@ -64,7 +88,7 @@ abstract class StylePluginBase extends PluginBase {
// Overlay incoming options on top of defaults // Overlay incoming options on top of defaults
$this->unpack_options($this->options, isset($options) ? $options : $display->handler->get_option('style_options')); $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'); $this->row_plugin = $display->handler->get_plugin('row');
} }
@ -86,17 +110,22 @@ abstract class StylePluginBase extends PluginBase {
} }
/** /**
* Return TRUE if this style also uses a row plugin. * Returns the usesRowPlugin property.
*
* @return bool
*/ */
function uses_row_plugin() { function usesRowPlugin() {
return !empty($this->definition['uses_row_plugin']); return $this->usesRowPlugin;
} }
/** /**
* Return TRUE if this style also uses a row plugin. * Returns the usesRowClass property.
*
* @return bool
*/ */
function uses_row_class() { function usesRowClass() {
return !empty($this->definition['uses_row_class']); return $this->usesRowClass;
} }
/** /**
@ -104,15 +133,15 @@ abstract class StylePluginBase extends PluginBase {
* *
* @return bool * @return bool
*/ */
function uses_fields() { function usesFields() {
// If we use a row plugin, ask the row plugin. Chances are, we don't // If we use a row plugin, ask the row plugin. Chances are, we don't
// care, it does. // care, it does.
$row_uses_fields = FALSE; $row_uses_fields = FALSE;
if ($this->uses_row_plugin() && !empty($this->row_plugin)) { if ($this->usesRowPlugin() && !empty($this->row_plugin)) {
$row_uses_fields = $this->row_plugin->uses_fields(); $row_uses_fields = $this->row_plugin->usesFields();
} }
// Otherwise, check the definition or the option. // 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 @@ abstract class StylePluginBase extends PluginBase {
* Used to ensure we don't fetch tokens when not needed for performance. * Used to ensure we don't fetch tokens when not needed for performance.
*/ */
function uses_tokens() { function uses_tokens() {
if ($this->uses_row_class()) { if ($this->usesRowClass()) {
$class = $this->options['row_class']; $class = $this->options['row_class'];
if (strpos($class, '[') !== FALSE || strpos($class, '!') !== FALSE || strpos($class, '%') !== FALSE) { if (strpos($class, '[') !== FALSE || strpos($class, '!') !== FALSE || strpos($class, '%') !== FALSE) {
return TRUE; return TRUE;
@ -133,9 +162,9 @@ abstract class StylePluginBase extends PluginBase {
* Return the token replaced row class for the specified row. * Return the token replaced row class for the specified row.
*/ */
function get_row_class($row_index) { function get_row_class($row_index) {
if ($this->uses_row_class()) { if ($this->usesRowClass()) {
$class = $this->options['row_class']; $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)); $class = strip_tags($this->tokenize_value($class, $row_index));
} }
@ -181,7 +210,7 @@ abstract class StylePluginBase extends PluginBase {
function option_definition() { function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['grouping'] = array('default' => array()); $options['grouping'] = array('default' => array());
if ($this->uses_row_class()) { if ($this->usesRowClass()) {
$options['row_class'] = array('default' => ''); $options['row_class'] = array('default' => '');
$options['default_row_class'] = array('default' => TRUE, 'bool' => TRUE); $options['default_row_class'] = array('default' => TRUE, 'bool' => TRUE);
$options['row_class_special'] = array('default' => TRUE, 'bool' => TRUE); $options['row_class_special'] = array('default' => TRUE, 'bool' => TRUE);
@ -197,7 +226,7 @@ abstract class StylePluginBase extends PluginBase {
// themselves from being groupable by setting their "use grouping" definiton // themselves from being groupable by setting their "use grouping" definiton
// key to FALSE. // key to FALSE.
// @TODO: Document "uses grouping" in docs.php when docs.php is written. // @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 -')); $options = array('' => t('- None -'));
$field_labels = $this->display->handler->get_field_labels(TRUE); $field_labels = $this->display->handler->get_field_labels(TRUE);
$options += $field_labels; $options += $field_labels;
@ -251,7 +280,7 @@ abstract class StylePluginBase extends PluginBase {
} }
} }
if ($this->uses_row_class()) { if ($this->usesRowClass()) {
$form['row_class'] = array( $form['row_class'] = array(
'#title' => t('Row class'), '#title' => t('Row class'),
'#description' => t('The class to provide on each row.'), '#description' => t('The class to provide on each row.'),
@ -259,7 +288,7 @@ abstract class StylePluginBase extends PluginBase {
'#default_value' => $this->options['row_class'], '#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.'); $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 @@ abstract class StylePluginBase extends PluginBase {
); );
} }
if (!$this->uses_fields() || !empty($this->options['uses_fields'])) { if (!$this->usesFields() || !empty($this->options['uses_fields'])) {
$form['uses_fields'] = array( $form['uses_fields'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Force using fields'), '#title' => t('Force using fields'),
@ -328,7 +357,7 @@ abstract class StylePluginBase extends PluginBase {
* Render the display in this style. * Render the display in this style.
*/ */
function render() { 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'); vpr('Drupal\views\Plugin\views\style\StylePluginBase: Missing row plugin');
return; return;
} }
@ -374,7 +403,7 @@ abstract class StylePluginBase extends PluginBase {
} }
// Render as a record set. // Render as a record set.
else { else {
if ($this->uses_row_plugin()) { if ($this->usesRowPlugin()) {
foreach ($set['rows'] as $index => $row) { foreach ($set['rows'] as $index => $row) {
$this->view->row_index = $index; $this->view->row_index = $index;
$set['rows'][$index] = $this->row_plugin->render($row); $set['rows'][$index] = $this->row_plugin->render($row);
@ -523,7 +552,7 @@ abstract class StylePluginBase extends PluginBase {
* The result array from $view->result * The result array from $view->result
*/ */
function render_fields($result) { function render_fields($result) {
if (!$this->uses_fields()) { if (!$this->usesFields()) {
return; return;
} }
@ -586,7 +615,7 @@ abstract class StylePluginBase extends PluginBase {
function validate() { function validate() {
$errors = parent::validate(); $errors = parent::validate();
if ($this->uses_row_plugin()) { if ($this->usesRowPlugin()) {
$plugin = $this->display->handler->get_plugin('row'); $plugin = $this->display->handler->get_plugin('row');
if (empty($plugin)) { if (empty($plugin)) {
$errors[] = t('Style @style requires a row style but the row plugin is invalid.', array('@style' => $this->definition['title'])); $errors[] = t('Style @style requires a row style but the row plugin is invalid.', array('@style' => $this->definition['title']));

View File

@ -20,15 +20,33 @@ use Drupal\Core\Annotation\Translation;
* title = @Translation("Table"), * title = @Translation("Table"),
* help = @Translation("Displays rows in a table."), * help = @Translation("Displays rows in a table."),
* theme = "views_view_table", * theme = "views_view_table",
* uses_row_plugin = FALSE,
* uses_row_class = TRUE,
* uses_fields = TRUE,
* type = "normal", * type = "normal",
* help_topic = "style-table" * help_topic = "style-table"
* ) * )
*/ */
class Table extends StylePluginBase { 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. * Contains the current active sort column.
* @var string * @var string

View File

@ -278,7 +278,7 @@ abstract class WizardPluginBase implements WizardInterface {
// @fixme // @fixme
$style_plugin = views_get_plugin('style', $style); $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); $options = $this->row_style_options($type);
$style_form['row_plugin'] = array( $style_form['row_plugin'] = array(
'#type' => 'select', '#type' => 'select',
@ -300,7 +300,7 @@ abstract class WizardPluginBase implements WizardInterface {
'#theme_wrappers' => array('container'), '#theme_wrappers' => array('container'),
); );
} }
elseif ($style_plugin->uses_fields()) { elseif ($style_plugin->usesFields()) {
$style_form['row_plugin'] = array('#markup' => '<span>' . t('of fields') . '</span>'); $style_form['row_plugin'] = array('#markup' => '<span>' . t('of fields') . '</span>');
} }
} }

View File

@ -1019,7 +1019,7 @@ class View extends ViewsDbObject {
return FALSE; return FALSE;
} }
if ($this->style_plugin->uses_fields()) { if ($this->style_plugin->usesFields()) {
$this->_build('field'); $this->_build('field');
} }
@ -1245,7 +1245,7 @@ class View extends ViewsDbObject {
// Give field handlers the opportunity to perform additional queries // Give field handlers the opportunity to perform additional queries
// using the entire resultset prior to rendering. // using the entire resultset prior to rendering.
if ($this->style_plugin->uses_fields()) { if ($this->style_plugin->usesFields()) {
foreach ($this->field as $id => $handler) { foreach ($this->field as $id => $handler) {
if (!empty($this->field[$id])) { if (!empty($this->field[$id])) {
$this->field[$id]->pre_render($this->result); $this->field[$id]->pre_render($this->result);