From 3abb68e9729e1f188d3e4133b5325759525f8fa3 Mon Sep 17 00:00:00 2001 From: Daniel Wehner <daniel.wehner@erdfisch.de> Date: Sat, 25 Aug 2012 17:40:27 +0200 Subject: [PATCH] Issue #1185042: Move style specific wizard code into the styles. --- .../Plugin/views/style/StylePluginBase.php | 32 ++++++++++ lib/Drupal/views/Plugin/views/style/Table.php | 10 ++++ .../Plugin/views/wizard/WizardPluginBase.php | 59 +++++-------------- 3 files changed, 58 insertions(+), 43 deletions(-) diff --git a/lib/Drupal/views/Plugin/views/style/StylePluginBase.php b/lib/Drupal/views/Plugin/views/style/StylePluginBase.php index aa9c0b09c817..a8d2f45300fe 100644 --- a/lib/Drupal/views/Plugin/views/style/StylePluginBase.php +++ b/lib/Drupal/views/Plugin/views/style/StylePluginBase.php @@ -8,6 +8,7 @@ namespace Drupal\views\Plugin\views\style; use Drupal\views\Plugin\views\PluginBase; +use Drupal\views\Plugin\views\wizard\WizardInterface; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; @@ -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 * interfere with the sorts. If so it should build; if it returns diff --git a/lib/Drupal/views/Plugin/views/style/Table.php b/lib/Drupal/views/Plugin/views/style/Table.php index d4a651655012..cce545206f88 100644 --- a/lib/Drupal/views/Plugin/views/style/Table.php +++ b/lib/Drupal/views/Plugin/views/style/Table.php @@ -7,6 +7,7 @@ namespace Drupal\views\Plugin\views\style; +use Drupal\views\Plugin\views\wizard\WizardInterface; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; @@ -353,4 +354,13 @@ function even_empty() { 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']); + } + } + + } diff --git a/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php b/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php index 75a79bde2eb4..c10ddba4e629 100644 --- a/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php +++ b/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php @@ -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) { $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)); @@ -303,6 +314,7 @@ 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); } /** @@ -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. */ 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 - // that store the path that will be used in the jump menu. The fields to - // use for this are defined by the plugin. - if (isset($this->plugin['path_field'])) { - $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']); - } - } + foreach ($display_options as $display_type => $options) { + // Allow style plugins to hook in and provide some settings. + $style_plugin = views_get_plugin('style', $options['style_plugin']); + $style_plugin->wizard_submit($form, $form_state, $this, $display_options, $display_type); } } -- GitLab