Views 3 Roadmap doesn't say anything about implement exposed forms as plugins.

However I think that if headers, or footers will be plugins, exposed filters should be too. This will allow other modules to define especial exposed filters.

I'm marking this issue as 'need works' beacause it ins't ready. Comments are welcome.

Exposed forms as plugin may help to implement this features

From views 3 roadmap:

Ability to have view not run when no value selected
People constantly ask for this feature, wherein the view will be empty until something has been selected in the exposed filters.

Control of text on 'button'
Paired with a proper translation plugin, this would be a nice little touch.

Own section in UI
To start with, the exposed forms have enough possible settings that they need their own section in the UI so that we can give them their settings. We can intelligently unset this if nothing is using the exposed form or maybe we can require it to be turned on before the 'expose' button shows up on anything.

Comments

dagmar’s picture

Title: Exposed forms as plugin » Exposed forms as plugins
Status: Needs work » Needs review
StatusFileSize
new18.6 KB

More code.

This patch allows user to select between "Basic" exposed form and "On demand" exposed form.

The first is the standard exposed form, the second one only display the list if user set a value for at least one of the exposed filters available.

Changing status.

dagmar’s picture

StatusFileSize
new18.71 KB

Some small fix:

  • Allow translate "Apply" button.
  • Check if exposed filter is enabled.

I was thinking that maybe this plugin is a possible way to implement: #228510: Exposed Sorts. With this patch, exposed forms can alter the query by using query()

dawehner’s picture

+++ views.module	18 Aug 2009 15:54:41 -0000
@@ -972,7 +972,7 @@ function views_exposed_form(&$form_state
-    '#value' => t('Apply'),
+    '#value' => t($form_state['submit_button']),

Why not let this be handled by the plugin. There could be perhaps a dynamic submit button, but there shouldn't be this string in the locale_source table.

+++ plugins/views_plugin_display.inc	18 Aug 2009 15:54:52 -0000
@@ -1547,6 +1636,29 @@ class views_plugin_display extends views
+          $plugin->options_submit($form['exposed_form_options'], $form_state);
+          krumo($form_state['values'][$section]);
+++ plugins/views_plugin_exposed_form.inc	18 Aug 2009 15:54:52 -0000
@@ -0,0 +1,96 @@
+  function option_defaults(&$options) {
+    $options['submit_button'] = t('Apply');

needs to be removed before commiting the patch.

+++ plugins/views_plugin_exposed_form.inc	18 Aug 2009 15:54:52 -0000
@@ -0,0 +1,96 @@
+  function option_defaults(&$options) {
+    $options['submit_button'] = t('Apply');

So currently the submit button value is handled full by the plugin. This would cause currently apply be translated to "foo". And then t("foo") will be called again.

This review is powered by Dreditor.

dagmar’s picture

StatusFileSize
new18.7 KB

Thanks dereine:

New patch.

BTW. I'm not sure if this is the better way to obtain an empty text for a view.

  function query() {
    if (!$this->exposed_filter_applied()) {
      // clear WHERE statment to display empty text
      $this->view->query->where = array();
      $this->view->query->add_where(0, '1 = 0');
    }

What do you think?

dawehner’s picture

Issue tags: +views 3.x roadmap

Just tagging to views 3.x

merlinofchaos’s picture

Despite a couple of small problems, I'm tempted to go ahead and commit this. This is something I like a lot. Great work!

1) There's a leftover krumo() statement.
2) The option_defaults() is outdated and needs to be pulled from everywhere. Go with the option_definition() pattern used in styles and row styles instead. That is more robust.
3) Let's give the "Exposed" options their own category in the UI. I plan to re-org this stuff a little anyhow.

The fact that we need option_definition as opposed to option_defaults is the only thing preventing me from just committing it now; that's going to be a pain to go back and fix. So let's fix that, then I can commit it.

dagmar’s picture

StatusFileSize
new18.81 KB

I have rebuilt it fixing the items that you have remarked.

Also this patch fixes an small bug in #4, now it is possible define different input formats for "Text On Demand" and "Empty Text"

BTW, I doesn't speak english very well, I'm not sure if "On Demand" is the better name for one of the plugins. Maybe there is another better. Please feel free to change it if know another better.

dagmar’s picture

Please, see #228510: Exposed Sorts. I have created a patch that includes this patch and the support for exposed sorts.

merlinofchaos’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Needs review » Patch (to be ported)
StatusFileSize
new13.18 KB

Cleaned up a bit and committed. Patch attached because this needs to be ported.

merlinofchaos’s picture

I think that patch is missing the plugin class files; they'll have to be pulled from the 6.x-3.x branch.

dawehner’s picture

StatusFileSize
new18.11 KB

Here is the first part. The settings of the exposed forms, are not displayed currently.

The plugins are included in the patch.

dagmar’s picture

+++ plugins/views_plugin_exposed_form_on_demand.inc	11 Nov 2009 06:49:14 -0000
@@ -0,0 +1,71 @@
+      $this->view->query->add_where(0, '1 = 0');

I think that this patch is not based on last commit. This line is different in the repository.

dawehner’s picture

Status: Patch (to be ported) » Needs work
StatusFileSize
new21.57 KB

@Dagmar:
This is part of the current drupal6 _on_demand exposed form plugin. I don't do anything here.

New version:

- Current problem:
Exposed_input is sometimes returns as array() sometimes as $value.

Here is a example view to reproduce this.

$view = new view;
$view->name = 'frontpage';
$view->description = 'Emulates the default Drupal front page; you may set the default home page path to this view to make it your front page.';
$view->tag = 'default';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('sorts', array(
  'sticky' => array(
    'id' => 'sticky',
    'table' => 'node',
    'field' => 'sticky',
    'order' => 'DESC',
  ),
  'created' => array(
    'id' => 'created',
    'table' => 'node',
    'field' => 'created',
    'order' => 'DESC',
    'relationship' => 'none',
    'granularity' => 'second',
  ),
));
$handler->override_option('filters', array(
  'promote' => array(
    'operator' => '=',
    'value' => '1',
    'group' => 0,
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => FALSE,
      'operator' => '',
      'identifier' => 'promote',
      'label' => 'Promoted to front page',
      'remember' => FALSE,
      'single' => TRUE,
      'optional' => FALSE,
    ),
    'id' => 'promote',
    'table' => 'node',
    'field' => 'promote',
  ),
  'status' => array(
    'operator' => '=',
    'value' => '1',
    'group' => 0,
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => FALSE,
      'operator' => '',
      'identifier' => 'status',
      'label' => 'Published',
      'remember' => FALSE,
      'single' => TRUE,
      'optional' => FALSE,
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
  'role' => array(),
  'perm' => '',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('use_pager', '1');
$handler->override_option('row_plugin', 'node');
$handler->override_option('row_options', array(
  'teaser' => 1,
  'links' => 1,
));
$handler->override_option('exposed_form', array(
  'type' => 'basic',
  'options' => array(),
));
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('path', 'frontpage');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
));
$handler = $view->new_display('feed', 'Feed', 'feed');
$handler->override_option('title', 'Front page feed');
$handler->override_option('style_plugin', 'rss');
$handler->override_option('style_options', array(
  'mission_description' => 1,
  'description' => '',
));
$handler->override_option('row_plugin', 'node_rss');
$handler->override_option('row_options', array(
  'item_length' => 'default',
));
$handler->override_option('path', 'rss.xml');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
));
$handler->override_option('displays', array(
  'default' => 'default',
  'page' => 'page',
));
$handler->override_option('sitename_title', '1');
dagmar’s picture

@dereine:

Cleaned up a bit and committed.

Earl Miles changed the name and some parts of these plugins. Please see http://drupal.org/cvs?commit=287352

dawehner’s picture

Ah ok. thanks for this information.

merlinofchaos’s picture

Sorry, dagmar admitted he wasn't sure On Demand was right, so I changed it as I worked on it. I also really dislike adding WHERE clauses to the query to force it to produce an invalid result, and instead made sure that there is a way to abort the query by setting a value in the build info.

dawehner’s picture

Status: Needs work » Needs review

Together with http://drupal.org/node/652716#comment-2348648 it works as expected.

Its from my perspective rtbr

dawehner’s picture

StatusFileSize
new14.09 KB

So here is combined patch with the patch above.

This patch is quite important because there are many many issues which needs this patch

dawehner’s picture

StatusFileSize
new13.51 KB

Updated version

dawehner’s picture

StatusFileSize
new22.8 KB

Some files missed

dagmar’s picture

Status: Needs review » Needs work

dereine, please use this patch http://drupal.org/cvs?commit=287352 you are still using the old version of plugins. I.e plugin named "On demand" was replaced by "Input required" in Views DRUPAL-6--3

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new20.76 KB

Oh, i forgot the remove the other one. As you see in the patch, i have both input_required, but also on_demand

dagmar’s picture

Status: Needs review » Needs work
+++ plugins/views_plugin_exposed_form.inc
@@ -0,0 +1,97 @@
+    $options['submit_button'] = array('default' => t('Apply'), 'translatable' => TRUE);

Change t('Apply') for 'Apply'

+++ plugins/views_plugin_exposed_form.inc
@@ -0,0 +1,97 @@
+      'submit_button' => $this->options['submit_button'],

This is not necessary, exposed_form_alter will change the label of the button.

+++ plugins/views_plugin_exposed_form.inc.orig
@@ -0,0 +1,109 @@
+  function pre_execute() { }

pre_execute is never called. See patch: #633482: pre_execute is never called on exposed forms plugins

+++ plugins/views_plugin_exposed_form.inc.orig
@@ -0,0 +1,109 @@
+  function exposed_form_alter(&$form, &$form_state) { }

Should take care of change the label of submit button. This patch seems to be including #635966: Allow exposed form plugins to alter the exposed form however this is not totally complete.

+++ plugins/views_plugin_exposed_form_on_demand.inc
@@ -0,0 +1,71 @@
+    return t('On demand');

mmm, still "On demand?"

dawehner’s picture

StatusFileSize
new16.33 KB


Change t('Apply') for 'Apply'

This was part of the original commited version see http://drupalcode.org/viewvc/drupal/contributions/modules/views/plugins/views_plugin_exposed_form.inc?r1=1.1&r2=1.1.2.1

The same answer applies to the next 3 reviews.

The last:
Damn i got confused by the names, i remove the wrong file :)

Updated version

dagmar’s picture

Status: Needs work » Needs review

change

+files[] = plugins/views_plugin_exposed_form_on_demand.inc

and I think is ready

dawehner’s picture

StatusFileSize
new16.94 KB

Next version

dawehner’s picture

StatusFileSize
new18.14 KB

I missed a render call

dagmar’s picture

Status: Needs review » Reviewed & tested by the community

Now works fine.

dawehner’s picture

Status: Reviewed & tested by the community » Fixed

Thanks dagmar for the testing and finding bugs again :)

http://drupal.org/cvs?commit=306686

Status: Fixed » Closed (fixed)
Issue tags: -views 3.x roadmap

Automatically closed -- issue fixed for 2 weeks with no activity.