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

Issue #1185042: Move style specific wizard code into the styles.

parent 5b77cda1
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
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\views\Plugin\views\style; namespace Drupal\views\Plugin\views\style;
use Drupal\views\Plugin\views\PluginBase; use Drupal\views\Plugin\views\PluginBase;
use Drupal\views\Plugin\views\wizard\WizardInterface;
use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation; use Drupal\Core\Annotation\Translation;
...@@ -328,6 +329,37 @@ function options_validate(&$form, &$form_state) { ...@@ -328,6 +329,37 @@ function options_validate(&$form, &$form_state) {
} }
} }
/**
* Provide a form in the views wizard if this style is selected.
*
* @param array $form
* An associative array containing the structure of the form.
* @param array $form_state
* An associative array containing the current state of the form.
* @param string $type
* The display type, either block or page.
*/
function wizard_form(&$form, &$form_state, $type) {
}
/**
* Alter the options of a display before they are added to the view.
*
* @param array $form
* An associative array containing the structure of the form.
* @param array $form_state
* An associative array containing the current state of the form.
* @param Drupal\views\Plugin\views\wizard\WizardInterface $wizard
* The current used wizard.
* @param array $display_options
* The options which will be used on the view. The style plugin should
* alter this to its own needs.
* @param string $display_type
* The display type, either block or page.
*/
function wizard_submit(&$form, &$form_state, WizardInterface $wizard, &$display_options, $display_type) {
}
/** /**
* Called by the view builder to see if this style handler wants to * Called by the view builder to see if this style handler wants to
* interfere with the sorts. If so it should build; if it returns * interfere with the sorts. If so it should build; if it returns
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
namespace Drupal\views\Plugin\views\style; namespace Drupal\views\Plugin\views\style;
use Drupal\views\Plugin\views\wizard\WizardInterface;
use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation; use Drupal\Core\Annotation\Translation;
...@@ -353,4 +354,13 @@ function even_empty() { ...@@ -353,4 +354,13 @@ function even_empty() {
return parent::even_empty() || !empty($this->options['empty_table']); return parent::even_empty() || !empty($this->options['empty_table']);
} }
function wizard_submit(&$form, &$form_state, WizardInterface $wizard, &$display_options, $display_type) {
// If any of the displays use the table style, take sure that the fields
// always have a labels by unsetting the override.
foreach ($display_options['default']['fields'] as &$field) {
unset($field['label']);
}
}
} }
...@@ -55,6 +55,17 @@ function __construct($plugin) { ...@@ -55,6 +55,17 @@ function __construct($plugin) {
} }
} }
/**
* Gets the active stored plugin information.
*
* @return array
* The plugin information.
*/
function getPlugin() {
return $this->plugin;
}
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));
$feed_row_options = views_fetch_plugin_names('row', 'feed', array($this->base_table)); $feed_row_options = views_fetch_plugin_names('row', 'feed', array($this->base_table));
...@@ -303,6 +314,7 @@ protected function build_form_style(&$form, &$form_state, $type) { ...@@ -303,6 +314,7 @@ 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);
} }
/** /**
...@@ -513,49 +525,10 @@ protected function build_display_options($form, $form_state) { ...@@ -513,49 +525,10 @@ protected function build_display_options($form, $form_state) {
* Alter the full array of display options before they are added to the view. * Alter the full array of display options before they are added to the view.
*/ */
protected function alter_display_options(&$display_options, $form, $form_state) { protected function alter_display_options(&$display_options, $form, $form_state) {
// If any of the displays use jump menus, we want to add fields to the view foreach ($display_options as $display_type => $options) {
// that store the path that will be used in the jump menu. The fields to // Allow style plugins to hook in and provide some settings.
// use for this are defined by the plugin. $style_plugin = views_get_plugin('style', $options['style_plugin']);
if (isset($this->plugin['path_field'])) { $style_plugin->wizard_submit($form, $form_state, $this, $display_options, $display_type);
$path_field = $this->plugin['path_field'];
$path_fields_added = FALSE;
foreach ($display_options as $display_type => $options) {
if (!empty($options['style_plugin']) && $options['style_plugin'] == 'jump_menu') {
// Regardless of how many displays have jump menus, we only need to
// add a single set of path fields to the view.
if (!$path_fields_added) {
// The plugin might provide supplemental fields that it needs to
// generate the path (for example, node revisions need the node ID
// as well as the revision ID). We need to add these first so they
// are available as replacement patterns in the main path field.
$path_fields = !empty($this->plugin['path_fields_supplemental']) ? $this->plugin['path_fields_supplemental'] : array();
$path_fields[] = &$path_field;
// Generate a unique ID for each field so we don't overwrite
// existing ones.
foreach ($path_fields as &$field) {
$field['id'] = View::generate_item_id($field['id'], $display_options['default']['fields']);
$display_options['default']['fields'][$field['id']] = $field;
}
$path_fields_added = TRUE;
}
// Configure the style plugin to use the path field to generate the
// jump menu path.
$display_options[$display_type]['style_options']['path'] = $path_field['id'];
}
}
}
// If any of the displays use the table style, take sure that the fields
// always have a labels by unsetting the override.
foreach ($display_options as &$options) {
if ($options['style_plugin'] == 'table') {
foreach ($display_options['default']['fields'] as &$field) {
unset($field['label']);
}
}
} }
} }
......
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