Skip to content
Snippets Groups Projects
Commit df47b727 authored by Daniel Wehner's avatar Daniel Wehner Committed by Tim Plunkett
Browse files

Issue #1747810 by dawehner, tim.plunkett: Move wizard-specific...

Issue #1747810 by dawehner, tim.plunkett: Move wizard-specific meta-information from plugin annotation to a class property.
parent e41eddb3
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -21,36 +21,48 @@ ...@@ -21,36 +21,48 @@
* @Plugin( * @Plugin(
* id = "comment", * id = "comment",
* base_table = "comment", * base_table = "comment",
* created_column = "created", * title = @Translation("Comments")
* title = @Translation("Comments"),
* filters = {
* "status" = {
* "value" = 1,
* "table" = "comment",
* "field" = "status"
* },
* "status_node" = {
* "value" = 1,
* "table" = "node",
* "field" = "status",
* "relationship" = "nid",
* }
* },
* path_field = {
* "id" = "cid",
* "table" = "comment",
* "field" = "cid",
* "exclude" = TRUE,
* "link_to_comment" = FALSE,
* "alter" = {
* "alter_text" = 1,
* "text" = "comment/[cid]#comment-[cid]"
* }
* }
* ) * )
*/ */
class Comment extends WizardPluginBase { class Comment extends WizardPluginBase {
/**
* Set the created column.
*/
protected $createdColumn = 'created';
/**
* Set default values for the path field options.
*/
protected $pathField = array(
'id' => 'cid',
'table' => 'comment',
'field' => 'cid',
'exclude' => TRUE,
'link_to_comment' => FALSE,
'alter' => array(
'alter_text' => TRUE,
'text' => 'comment/[cid]#comment-[cid]'
),
);
/**
* Set default values for the filters.
*/
protected $filters = array(
'status' => array(
'value' => TRUE,
'table' => 'comment',
'field' => 'status'
),
'status_node' => array(
'value' => TRUE,
'table' => 'node',
'field' => 'status',
'relationship' => 'nid'
)
);
protected function row_style_options($type) { protected function row_style_options($type) {
$options = array(); $options = array();
$options['comment'] = t('comments'); $options['comment'] = t('comments');
......
...@@ -17,19 +17,27 @@ ...@@ -17,19 +17,27 @@
* @Plugin( * @Plugin(
* id = "file_managed", * id = "file_managed",
* base_table = "file_managed", * base_table = "file_managed",
* created_column = "timestamp", * title = @Translation("Files")
* title = @Translation("Files"),
* path_field = {
* "id" = "uri",
* "table" = "file_managed",
* "field" = "uri",
* "exclude" = TRUE,
* "file_download_path" = TRUE
* }
* ) * )
*/ */
class File extends WizardPluginBase { class File extends WizardPluginBase {
/**
* Set the created column.
*/
protected $createdColumn = 'timestamp';
/**
* Set default values for the path field options.
*/
protected $pathField = array(
'id' => 'uri',
'table' => 'file_managed',
'field' => 'uri',
'exclude' => TRUE,
'file_download_path' => TRUE
);
protected function default_display_options($form, $form_state) { protected function default_display_options($form, $form_state) {
$display_options = parent::default_display_options($form, $form_state); $display_options = parent::default_display_options($form, $form_state);
......
...@@ -21,35 +21,56 @@ ...@@ -21,35 +21,56 @@
* @Plugin( * @Plugin(
* id = "node", * id = "node",
* base_table = "node", * base_table = "node",
* created_column = "created", * title = @Translation("Content")
* title = @Translation("Content"),
* available_sorts = {
* "title:DESC" = @Translation("Title")
* },
* filters = {
* "status" = {
* "value" = 1,
* "table" = "node",
* "field" = "status"
* }
* },
* path_field = {
* "id" = "nid",
* "table" = "node",
* "field" = "nid",
* "exclude" = TRUE,
* "link_to_node" = FALSE,
* "alter" = {
* "alter_text" = 1,
* "text" = "node/[nid]"
* }
* }
* ) * )
*
*/ */
class Node extends WizardPluginBase { class Node extends WizardPluginBase {
/**
* Set the created column.
*/
protected $createdColumn = 'created';
/**
* Set default values for the path field options.
*/
protected $pathField = array(
'id' => 'nid',
'table' => 'node',
'field' => 'nid',
'exclude' => TRUE,
'link_to_node' => FALSE,
'alter' => array(
'alter_text' => TRUE,
'text' => 'node/[nid]'
)
);
/**
* Set default values for the filters.
*/
protected $filters = array(
'status' => array(
'value' => TRUE,
'table' => 'node',
'field' => 'status'
)
);
/**
* Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::getAvailableSorts().
*
* @return array
*/
public function getAvailableSorts() {
// You can't execute functions in properties, so override the method
return array(
'title:DESC' => t('Title')
);
}
protected function row_style_options($type) { protected function row_style_options($type) {
$options = array(); $options = array();
$options['teasers'] = t('teasers'); $options['teasers'] = t('teasers');
......
...@@ -21,38 +21,54 @@ ...@@ -21,38 +21,54 @@
* @Plugin( * @Plugin(
* id = "node_revision", * id = "node_revision",
* base_table = "node_revision", * base_table = "node_revision",
* created_column = "timestamp", * title = @Translation("Content revisions")
* title = @Translation("Content revisions"),
* filters = {
* "status" = {
* "value" = 1,
* "table" = "node",
* "field" = "status"
* }
* },
* path_field = {
* "id" = "vid",
* "table" = "node_revision",
* "field" = "vid",
* "exclude" = TRUE,
* "alter" = {
* "alter_text" = 1,
* "text" = "node/[nid]/revisions/[vid]/view"
* }
* },
* path_fields_supplemental = {
* {
* "id" = "nid",
* "table" = "node",
* "field" = "nid",
* "exclude" = TRUE,
* "link_to_node" = FALSE
* }
* }
* ) * )
*/ */
class NodeRevision extends WizardPluginBase { class NodeRevision extends WizardPluginBase {
/**
* Set the created column.
*/
protected $createdColumn = 'timestamp';
/**
* Set default values for the path field options.
*/
protected $pathField = array(
'id' => 'vid',
'table' => 'node_revision',
'field' => 'vid',
'exclude' => TRUE,
'alter' => array(
'alter_text' => TRUE,
'text' => 'node/[nid]/revisions/[vid]/view'
)
);
/**
* Set the additional information for the pathField property.
*/
protected $pathFieldsSupplemental = array(
array(
'id' => 'nid',
'table' => 'node',
'field' => 'nid',
'exclude' => TRUE,
'link_to_node' => FALSE
)
);
/**
* Set default values for the filters.
*/
protected $filters = array(
'status' => array(
'value' => TRUE,
'table' => 'node',
'field' => 'status'
)
);
/** /**
* Node revisions do not support full posts or teasers, so remove them. * Node revisions do not support full posts or teasers, so remove them.
*/ */
......
...@@ -17,21 +17,25 @@ ...@@ -17,21 +17,25 @@
* @Plugin( * @Plugin(
* id = "taxonomy_term", * id = "taxonomy_term",
* base_table = "taxonomy_term_data", * base_table = "taxonomy_term_data",
* title = @Translation("Taxonomy terms"), * title = @Translation("Taxonomy terms")
* path_field = {
* "id" = "tid",
* "table" = "taxonomy_term_data",
* "field" = "tid",
* "exclude" = TRUE,
* "alter" = {
* "alter_text" = 1,
* "text" = "taxonomy/term/[tid]"
* }
* }
* ) * )
*/ */
class TaxonomyTerm extends WizardPluginBase { class TaxonomyTerm extends WizardPluginBase {
/**
* Set default values for the path field options.
*/
protected $pathField = array(
'id' => 'tid',
'table' => 'taxonomy_term_data',
'field' => 'tid',
'exclude' => TRUE,
'alter' => array(
'alter_text' => TRUE,
'text' => 'taxonomy/term/[tid]'
)
);
protected function default_display_options($form, $form_state) { protected function default_display_options($form, $form_state) {
$display_options = parent::default_display_options($form, $form_state); $display_options = parent::default_display_options($form, $form_state);
......
...@@ -21,30 +21,42 @@ ...@@ -21,30 +21,42 @@
* @Plugin( * @Plugin(
* id = "users", * id = "users",
* base_table = "users", * base_table = "users",
* created_column = "created", * title = @Translation("Users")
* title = @Translation("Users"),
* filters = {
* "status" = {
* "value" = 1,
* "table" = "users",
* "field" = "status"
* }
* },
* path_field = {
* "id" = "uid",
* "table" = "users",
* "field" = "uid",
* "exclude" = TRUE,
* "link_to_user" = FALSE,
* "alter" = {
* "alter_text" = 1,
* "text" = "user/[uid]"
* }
* }
* ) * )
*/ */
class Users extends WizardPluginBase { class Users extends WizardPluginBase {
/**
* Set the created column.
*/
protected $createdColumn = 'created';
/**
* Set default values for the path field options.
*/
protected $pathField = array(
'id' => 'uid',
'table' => 'users',
'field' => 'uid',
'exclude' => TRUE,
'link_to_user' => FALSE,
'alter' => array(
'alter_text' => TRUE,
'text' => 'user/[uid]'
)
);
/**
* Set default values for the filters.
*/
protected $filters = array(
'status' => array(
'value' => TRUE,
'table' => 'users',
'field' => 'status'
)
);
protected function default_display_options($form, $form_state) { protected function default_display_options($form, $form_state) {
$display_options = parent::default_display_options($form, $form_state); $display_options = parent::default_display_options($form, $form_state);
......
...@@ -31,7 +31,7 @@ function validate($form, &$form_state); ...@@ -31,7 +31,7 @@ function validate($form, &$form_state);
* *
* @return a view object. * @return a view object.
* *
* @throws ViewsWizardException in the event of a problem. * @throws Drupal\views\Plugin\views\wizard\WizardException
*/ */
function create_view($form, &$form_state); function create_view($form, &$form_state);
......
...@@ -17,16 +17,81 @@ ...@@ -17,16 +17,81 @@
*/ */
abstract class WizardPluginBase implements WizardInterface { abstract class WizardPluginBase implements WizardInterface {
/**
* Stores the base table connected with the wizard.
*
* @var string
*/
protected $base_table; protected $base_table;
/**
* Stores the entity type connected with the wizard.
*
* There might be base tables connected with entity types, if not this would
* be empty.
*
* @var string
*/
protected $entity_type; protected $entity_type;
/**
* Contains the information from entity_get_info of the $entity_type.
*
* @var array
*/
protected $entity_info = array(); protected $entity_info = array();
protected $validated_views = array(); protected $validated_views = array();
/**
* The wizard plugin definition, like the base_table.
*
* @var array
*/
protected $plugin = array(); protected $plugin = array();
/**
* The table column used for sorting by create date of this wizard.
*
* @var string
*/
protected $createdColumn;
/**
* Stores a views item configuration array used for a jump-menu field.
*
* @var array
*/
protected $pathField = array();
/**
* Stores additional fields required to generate the pathField.
*
* @var array
*/
protected $pathFieldsSupplemental = array();
/**
* Stores views items configuration arrays for filters added by the wizard.
*
* @var array
*/
protected $filters = array();
/**
* Stores views items configuration arrays for sorts added by the wizard.
*
* @var array
*/
protected $sorts = array();
/**
* Stores the available store criteria.
*
* @var array
*/
protected $availableSorts = array();
protected $filter_defaults = array( protected $filter_defaults = array(
'id' => NULL, 'id' => NULL,
'expose' => array('operator' => FALSE), 'expose' => array('operator' => FALSE),
...@@ -37,13 +102,6 @@ function __construct($plugin) { ...@@ -37,13 +102,6 @@ function __construct($plugin) {
$this->base_table = $plugin['base_table']; $this->base_table = $plugin['base_table'];
$default = $this->filter_defaults; $default = $this->filter_defaults;
if (isset($plugin['filters'])) {
foreach ($plugin['filters'] as $name => $info) {
$default['id'] = $name;
$plugin['filters'][$name] = $info + $default;
}
}
$this->plugin = $plugin; $this->plugin = $plugin;
$entities = entity_get_info(); $entities = entity_get_info();
...@@ -56,15 +114,65 @@ function __construct($plugin) { ...@@ -56,15 +114,65 @@ function __construct($plugin) {
} }
/** /**
* Gets the active stored plugin information. * Returns the createdColumn property.
*
* @return string
*/
public function getCreatedColumn() {
return $this->createdColumn;
}
/**
* Returns the pathField property.
* *
* @return array * @return array
* The plugin information.
*/ */
function getPlugin() { public function getPathField() {
return $this->plugin; return $this->pathField;
} }
/**
* Returns the pathFieldsSupplemental property.
*
* @var array()
*/
public function getPathFieldsSupplemental() {
return $this->pathFieldsSupplemental;
}
/**
* Returns the filters property.
*
* @return array
*/
public function getFilters() {
$filters = array();
foreach ($this->filters as $name => $info) {
$default['id'] = $name;
$filters[$name] = $info + $default;
}
return $filters;
}
/**
* Returns the availableSorts property.
*
* @return array
*/
public function getAvailableSorts() {
return $this->availableSorts;
}
/**
* Returns the sorts property.
*
* @return array
*/
public function getSorts() {
return $this->sorts;
}
function build_form($form, &$form_state) { function build_form($form, &$form_state) {
$style_options = views_fetch_plugin_names('style', 'normal', array($this->base_table)); $style_options = views_fetch_plugin_names('style', 'normal', array($this->base_table));
...@@ -314,7 +422,6 @@ protected function build_form_style(&$form, &$form_state, $type) { ...@@ -314,7 +422,6 @@ protected function build_form_style(&$form, &$form_state, $type) {
elseif ($style_plugin->usesFields()) { 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>');
} }
$style_plugin->wizard_form($form, $form_state, $type);
} }
/** /**
...@@ -436,14 +543,15 @@ protected function build_sorts(&$form, &$form_state) { ...@@ -436,14 +543,15 @@ protected function build_sorts(&$form, &$form_state) {
'none' => t('Unsorted'), 'none' => t('Unsorted'),
); );
// Check if we are allowed to sort by creation date. // Check if we are allowed to sort by creation date.
if (!empty($this->plugin['created_column'])) { $created_column = $this->getCreatedColumn();
if ($created_column) {
$sorts += array( $sorts += array(
$this->plugin['created_column'] . ':DESC' => t('Newest first'), $created_column . ':DESC' => t('Newest first'),
$this->plugin['created_column'] . ':ASC' => t('Oldest first'), $created_column . ':ASC' => t('Oldest first'),
); );
} }
if (isset($this->plugin['available_sorts'])) { if ($available_sorts = $this->getAvailableSorts()) {
$sorts += $this->plugin['available_sorts']; $sorts += $available_sorts;
} }
foreach ($sorts as &$option) { foreach ($sorts as &$option) {
...@@ -458,7 +566,7 @@ protected function build_sorts(&$form, &$form_state) { ...@@ -458,7 +566,7 @@ protected function build_sorts(&$form, &$form_state) {
'#type' => 'select', '#type' => 'select',
'#title' => t('sorted by'), '#title' => t('sorted by'),
'#options' => $sorts, '#options' => $sorts,
'#default_value' => isset($this->plugin['created_column']) ? $this->plugin['created_column'] . ':DESC' : 'none', '#default_value' => isset($created_column) ? $created_column . ':DESC' : 'none',
); );
} }
} }
...@@ -612,10 +720,8 @@ protected function default_display_filters($form, $form_state) { ...@@ -612,10 +720,8 @@ protected function default_display_filters($form, $form_state) {
$filters = array(); $filters = array();
// Add any filters provided by the plugin. // Add any filters provided by the plugin.
if (isset($this->plugin['filters'])) { foreach ($this->getFilters() as $name => $info) {
foreach ($this->plugin['filters'] as $name => $info) { $filters[$name] = $info;
$filters[$name] = $info;
}
} }
// Add any filters specified by the user when filling out the wizard. // Add any filters specified by the user when filling out the wizard.
...@@ -691,10 +797,8 @@ protected function default_display_sorts($form, $form_state) { ...@@ -691,10 +797,8 @@ protected function default_display_sorts($form, $form_state) {
$sorts = array(); $sorts = array();
// Add any sorts provided by the plugin. // Add any sorts provided by the plugin.
if (isset($this->plugin['sorts'])) { foreach ($this->getSorts() as $name => $info) {
foreach ($this->plugin['sorts'] as $name => $info) { $sorts[$name] = $info;
$sorts[$name] = $info;
}
} }
// Add any sorts specified by the user when filling out the wizard. // Add any sorts specified by the user when filling out the wizard.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment