Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Views style plugin for Drupal?

I'm trying to create a Views Style plugin for the Views module in Drupal. The aim on the style plugin is to render the view as a drop down (i.e. SELECT) box.

I can't for the life of me find any decent or complete documentation on how to do this. I've looked at the source code of other Views Style plugins but that does not help.

Does anyone know how it's done or know any decent documentation, guides or tutorials on the subject?

like image 859
Camsoft Avatar asked Sep 13 '10 14:09

Camsoft


1 Answers

Not sure a style element is quite what you're looking for: even if you could get the form element to render as proper HTML, the security on the forms API is going to be be hostile to any values submitted from that element.

(Form elements in Drupal have a dual life: they exist as HTML s, but also in the form_state cache. So, any form element that isn't explicitly rendered by the forms API will be discarded when the form is submitted.)

A better solution, if you're looking for views-driven form elements, would be to build the form using the normal form API and have views populate the #options array of the element.

The function _nodereference_potential_references_views from the nodereference CCK add-on has a similar feature, and would probably be a good place to start. (It uses CCK hooks so you can't copy-paste directly in this case, but it should give you a pretty good sense of what you need to do)

like image 185
anschauung Avatar answered Sep 29 '22 08:09

anschauung