Views Team

I recently ran across the need to use a variable stored in superglobals, specifically $_GET as the default value for a contextual filter. My specific use case was I have a search page built in views, that uses a Search API index. In addition, I have a suggested results view where editors and admins of the site can tag certain keywords using a vocabulary, and then associate various nodes to that term. Thus if someone searches for "software", the view grabs that value, looks to see if there is a taxonomy term that matches, and if so, display the related nodes.

This was easily accomplished when the site used the Apachesolr module, which put the search term as an argument ("search/software") but when we moved to the Search API, the search box is a filter in views, and thus gets added to the end as a variable ("search?query=software"), which won't work as an argument. Also, the order of those variables can change if using facets, etc.

I created a module that adds an option to the default value drop down to specify a superglobal, and then a variable within that superglobal. It can traverse arrays and objects, and can go to any depth and then returns that value as $arg.

The reason I am posting this is the module is up for review, but I wanted to reach out to you guys to see if you feel this better as a contrib module or something that could be possibly worked into views, either for 7.x-3.x or 8.x.

If you're feeling adventurous you can check out the sandbox at http://drupal.org/sandbox/ryan.armstrong/1946464 also any thoughts on security issues, or thoughts in general are welcome as well.

Comments

dawehner’s picture

Cool idea. Well I believe as long you trust people with the "administer views" permission, which you really should, everything seems fine.

ryan.armstrong’s picture

Yea I was surprised it hadn't been done before. I am currently trying to get the module reviewed (http://drupal.org/node/1946502 if anyone has a second ;) but it's really just a views plugin, so I didn't know if it would be something that could be a candidate for inclusion in Views core, since it allows you to grab a $_GET variable rather then just using an argument. It opens up doing a lot of things with variables set by views filters in other views.

ryan.armstrong’s picture

One other thing I wanted to reach out to the views community about was regarding some error messages the coder module at http://ventral.org/pareview is throwing back at me. I based my plugin off of the views_plugin_argument_default_raw.inc plugin, and didn't change anything except names. So the code style errors I am getting from my module, also exist in Views core. I was curious as to what people thought the best course of action would be. Should I fix them in my code to adhere to Coder, or stick with how Views has them written? A couple of the errors I can't change as they ask that I change some of the internal method names, which need to remain the same. Here is the output:

FILE: ...7-pareview/pareview_temp/views_plugin_argument_default_superglobals.inc
--------------------------------------------------------------------------------
FOUND 11 ERROR(S) AFFECTING 4 LINE(S)
--------------------------------------------------------------------------------
13 | ERROR | Class name must begin with a capital letter
13 | ERROR | Class name must use UpperCamel naming without underscores
14 | ERROR | Missing function doc comment
14 | ERROR | Method name
| | "views_plugin_argument_default_superglobals::option_definition"
| | is not in lowerCamel format, it must not contain underscores
14 | ERROR | No scope modifier specified for function "option_definition"
22 | ERROR | Missing function doc comment
22 | ERROR | Method name
| | "views_plugin_argument_default_superglobals::options_form" is not
| | in lowerCamel format, it must not contain underscores
22 | ERROR | No scope modifier specified for function "options_form"
52 | ERROR | Missing function doc comment
52 | ERROR | Method name
| | "views_plugin_argument_default_superglobals::get_argument" is not
| | in lowerCamel format, it must not contain underscores
52 | ERROR | No scope modifier specified for function "get_argument"
--------------------------------------------------------------------------------