Commit df47b727 authored by dawehner's avatar dawehner 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
......@@ -21,36 +21,48 @@
* @Plugin(
* id = "comment",
* base_table = "comment",
* created_column = "created",
* 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]"
* }
* }
* title = @Translation("Comments")
* )
*/
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) {
$options = array();
$options['comment'] = t('comments');
......
......@@ -17,19 +17,27 @@
* @Plugin(
* id = "file_managed",
* base_table = "file_managed",
* created_column = "timestamp",
* title = @Translation("Files"),
* path_field = {
* "id" = "uri",
* "table" = "file_managed",
* "field" = "uri",
* "exclude" = TRUE,
* "file_download_path" = TRUE
* }
* title = @Translation("Files")
* )
*/
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) {
$display_options = parent::default_display_options($form, $form_state);
......
......@@ -21,35 +21,56 @@
* @Plugin(
* id = "node",
* base_table = "node",
* created_column = "created",
* 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]"
* }
* }
* title = @Translation("Content")
* )
*
*/
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) {
$options = array();
$options['teasers'] = t('teasers');
......
......@@ -21,38 +21,54 @@
* @Plugin(
* id = "node_revision",
* base_table = "node_revision",
* created_column = "timestamp",
* 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
* }
* }
* title = @Translation("Content revisions")
* )
*/
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.
*/
......
......@@ -17,21 +17,25 @@
* @Plugin(
* id = "taxonomy_term",
* base_table = "taxonomy_term_data",
* title = @Translation("Taxonomy terms"),
* path_field = {
* "id" = "tid",
* "table" = "taxonomy_term_data",
* "field" = "tid",
* "exclude" = TRUE,
* "alter" = {
* "alter_text" = 1,
* "text" = "taxonomy/term/[tid]"
* }
* }
* title = @Translation("Taxonomy terms")
* )
*/
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) {
$display_options = parent::default_display_options($form, $form_state);
......
......@@ -21,30 +21,42 @@
* @Plugin(
* id = "users",
* base_table = "users",
* created_column = "created",
* 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]"
* }
* }
* title = @Translation("Users")
* )
*/
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) {
$display_options = parent::default_display_options($form, $form_state);
......
......@@ -31,7 +31,7 @@ function validate($form, &$form_state);
*
* @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);
......
......@@ -17,16 +17,81 @@
*/
abstract class WizardPluginBase implements WizardInterface {
/**
* Stores the base table connected with the wizard.
*
* @var string
*/
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;
/**
* Contains the information from entity_get_info of the $entity_type.
*
* @var array
*/
protected $entity_info = array();
protected $validated_views = array();
/**
* The wizard plugin definition, like the base_table.
*
* @var 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(
'id' => NULL,
'expose' => array('operator' => FALSE),
......@@ -37,13 +102,6 @@ function __construct($plugin) {
$this->base_table = $plugin['base_table'];
$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;
$entities = entity_get_info();
......@@ -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
* The plugin information.
*/
function getPlugin() {
return $this->plugin;
public function getPathField() {
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) {
$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) {
elseif ($style_plugin->usesFields()) {
$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) {
'none' => t('Unsorted'),
);
// 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(
$this->plugin['created_column'] . ':DESC' => t('Newest first'),
$this->plugin['created_column'] . ':ASC' => t('Oldest first'),
$created_column . ':DESC' => t('Newest first'),
$created_column . ':ASC' => t('Oldest first'),
);
}
if (isset($this->plugin['available_sorts'])) {
$sorts += $this->plugin['available_sorts'];
if ($available_sorts = $this->getAvailableSorts()) {
$sorts += $available_sorts;
}
foreach ($sorts as &$option) {
......@@ -458,7 +566,7 @@ protected function build_sorts(&$form, &$form_state) {
'#type' => 'select',
'#title' => t('sorted by'),
'#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) {
$filters = array();
// Add any filters provided by the plugin.
if (isset($this->plugin['filters'])) {
foreach ($this->plugin['filters'] as $name => $info) {
$filters[$name] = $info;
}
foreach ($this->getFilters() as $name => $info) {
$filters[$name] = $info;
}
// Add any filters specified by the user when filling out the wizard.
......@@ -691,10 +797,8 @@ protected function default_display_sorts($form, $form_state) {
$sorts = array();
// Add any sorts provided by the plugin.
if (isset($this->plugin['sorts'])) {
foreach ($this->plugin['sorts'] as $name => $info) {
$sorts[$name] = $info;
}
foreach ($this->getSorts() as $name => $info) {
$sorts[$name] = $info;
}
// Add any sorts specified by the user when filling out the wizard.
......
Markdown is supported
0%