Attached are two file: viewselector.module and viewselector.inc. These two files provide a form element that allows users to select nodes using a table based view. This form element can be embedded in any form, allowing wide reuse. It is my hope that this code will be incorporated in the main views distribution. I am providing it as a separate module first to support discussion of the features and implementation of this form element. Once Earl approves the basic concept and implementation, I will port it to the views module.
Goal
The goal of this form element is to simplify the selection of nodes. The majority of node selection forms right now use either drop down lists/multi-selects or textfields where a user can type in a node's title. These forms do not allow for interactive selection (e.g. "I want to pick a node that has "Foo" in the title"), nor do they allow the user much more information than just the title.
Views can provides a flexible system for showing more, useful data to the user and also allows for interactively modifying a data set through the use of exposed filters. Many modules are views enabled, allowing for a large amount of different information to be provided.
No method currently exists to embed a view in a form and use it to select nodes.
Implementation Details
This module implements hook_elements to define a new form element: views_node_selector (I admit this name could be better ;-) Here is the definition of the element:
function viewselector_elements() {
$type['views_node_selector'] = array(
'#input' => TRUE,
'#process' => array('viewselector_process_element' => array()),
'#view' => 'frontpage',
'#multiple' => false,
'#page' => 0,
'#collapsed' => false,
'#collapsible' => false,
'#arguments' => array(),
);
return $type;
}
As you can see from this definition, form writers can specify the view to be used, an array of arguments, and a starting page if the view use a pager. Additionally, at render time, the element is themed as a fieldset, so the collapsible and collapsed properties are provided as well.
This element expands into three sub-forms when invoked: filters, selected, and pager.
The filters subform creates a form for each exposed filter in the view. Unlike the default exposed filter form, this subform does not set #name for each element, nor does it make a GET request to the view's page on submission. In the long run, I believe the views module should factor out the code I use in this module, and add the #name and other form data later. This will allow more code reuse in exposed filters.
A user clicks "Filter results" to refresh the page and see the new results.
The pager subform works in a similar way. As the default pager must use and HTTP get, this pager subform is necessary to be compatible with form refreshes (e.g. "preview" on node creation/edit). The pager provides a drop down list of pages the user can select. The user then clicks 'go' to refresh the page with the new view.
The selected subform is either a set of radio buttons or a checkboxes. Radio buttons are use for when the form writer specifies '#multiple' => false. Checkboxes are used for multi-select forms.
Users can supply either a single node id (for single select forms) or an array of node ids in the #default_value. These values will be sent to the checkboxes/radio buttons as default values.
When the form is submitted, the _submit hook will receive the entire array of filters, selected, and pager. It the _submit functions responsibility to know that the data it wants is just in the selected sub-array. This is has to happen due to form API requirements.
View modifications
During the expansion process of the form element, the view is modified. First, every view is set to a table view. I am open to alternatives, but this seemed to be most useful and practical for the initial release.
Next, if no fields are included, a default node title field is inserted into the view.
Next, a selection field is inserted to hold the checkbox/radio button for this node. This field is implemented using the standard views conventions, but is removed from the view edit screen via a form_alter, as it has no use outside of a form.
Next, the view is run in 'queries' mode to get back the count query. This is used to compute the total number of pages, if this view uses paging. Standard paging queries rely on $_GET variables, which we can't use in a form.
Using this paging information, along with the current page, the view is built in "items" mode. The items are used to populate the selected subform's #options array. This is so it will work with the form api and not cause illegal errors later.
Next, the options array is check to see if there are any nodes being passed in (either from default_value or that the person has already selected) that are not included. These are placed in another array ($missing). Later these will be passed into another table view using the specifically included filter. (more on this below).
Theming
When the form element is rendered the view itself is built. Additionally, a table view is built for all "missing" nodes. This missing table allows uses to page back and forth, re-filter, etc, without losing their selections. This information could have been placed into a hidden field or value field, but I thought displaying the data in an additional table would be the most reasonable. The missing table is not affected by filtering or paging.
The theme function wraps each of the filters, the missing table, the main table, and the pager in a div, and concatenates them in that order. This information is placed in the #children key so that it can be used in later themeing.
The '#type' of the element is then set to 'fieldset' and the fieldset theming is called on the element. This places everything in #children (filters, missing, main, and pager) into a fieldset and returns the rendered HTML to Drupal.
Inclusion/Exclusion Filter
The missing node table makes use of a specific inclusion filter. This filter allows the creation of SQL like WHERE node.nid IN (1,2,3), a feature not provided by views out of the box. During form element building, this is used to construct a query that only has the missing nodes in it, but has all the fields/handlers of the selected view.
This filter is also available for users during view creation. Using a view_node_selector form element, users can select nodes for inclusion or exclusion of their views. This has a valid use case of excluding a specific node (e.g. node 123) from a view in all cases, or alternatively always including a node.
Right now, this functionality can be experience by users, as the complex return data from the views node selector element needs to be mapped to view's 'value-type' => 'array' definition. Possible options to solve this problem include serialization/deserialization of the data during view save/load and/or writing a filter handler to help with this process.
I am not sure which route is better. It would also be convenient if there were a post-process function that I could define, where I could return my array of node ids prior to view save. This hook does not yet exist.
Installation and testing
This module should work with the latest 4-7-dev release of views. No patches are necessary.
This module comes with a test harness that you can use to programmatically create forms that use the views node selector. Visit /viewselector after installation. Fill out the form and you will get a form that uses your settings. Good luck and feel free to report bugs. My testing indicates that it works with all standard default views, except taxonomy_term, where it partially works.
Conclusion
I would very much like to see this functionality appear in views so that other modules can write views aware forms. A good use case would be the node reference module in CCK. Using this form element, the nodereference module could pick nodes using exposed filters and paging, instead a giant drop down menu.
I see it as imperative to long term health of this functionality that it becomes part of the view code. It is entirely reliant on views, and hooks deep in to the views innards. It does not make sense to me to release this as a separate module.
Thank you for reading this lengthy message. Please do test this module and let me know what you think. Hopefully, you'll see it in the next views release.
-Mark
| Comment | File | Size | Author |
|---|---|---|---|
| #80 | views_checkout.tgz_.info | 1.69 KB | pwolanin |
| #79 | forms_patch_4.patch | 6.05 KB | pwolanin |
| #71 | form_element_2.patch | 23.62 KB | pwolanin |
| #61 | views_form.inc_.2.txt | 12.1 KB | harry slaughter |
| #60 | views_bulk_operations.png | 46.3 KB | harry slaughter |
Comments
Comment #1
mfredrickson commentedHere's the required .inc file as well.
Comment #2
yched commentedSubscribing - no time to test right now, but this sounds :
- really interesting
- badly needed
Comment #3
Egon Bianchet commentedSimilar projects:
- http://drupal.org/project/editview
- http://drupal.org/project/subform
Since it looks like there is strong demand for this kind of functionality we should try to join efforts ...
Comment #4
bonobo commentedsusbscribing --
will test over the weekend --
Comment #5
mfredrickson commented@Egon
I like where those projects are going, though they are different than what I am proposing in this patch. In both cases, I think they could build on this patch.
Editview - my long term goal for this patch, after the initial version gets into views, to is to rework it to accept any form array and present it for each node on display. Right now, the only options are check boxes or radio buttons - but why not other form elements or forms? An example: build a shopping cart that has a quantity text field that users can update and a checkbox to remove the item from the cart.
Editview could stick in more complicated forms. Or at least reuse the filtering and paging components of this module.
Subform - this module is a little closer to the goals of this patch, but the implementation needs work. It relies on JavaScript for it's functionality and mixes GETs and POSTs. Using this form element would probably be a better base on which to build subform.
Overall, I welcome assistance and collaboration.
Comment #6
mcreature commentedVery nice. I can see lots of uses for this, Subscribing.
Comment #7
merlinofchaos commentedI'm keeping an eye on this, but at this time I don't have the time to be involved in active testing/development, so definitely getting a few people together who have an interest to help out with this is a good idea.
It's very interesting.
Comment #8
mfredrickson commented@merlinofchaos: My goal is to chip away at this module/patch and turn it into a series of small patches that you can more easily digest. Two areas I plan to start on: factoring out common form stuff for exposed filters; adding another param to views_build_view to pass in exposed filter data, instead of always looking for it in $_GET.
Eventually, I'll need a review of the entirely new functionality, but until then, just expect a series of smaller patches.
Comment #9
lunas commentedI tested this out and it is excellent. I have no idea how to implement it the way I want, but I very much look forward to when it is integrated. Specifically, I want this feature with nodereference. When my user goes to create a node and can see in front of them all of their choices, it is much more intuitive than trying to find it in a dropdown. Thanks for doing this and I look forward to actually using it. How difficult would it be to put this into nodereference.module now?
Comment #10
nathanraft commented+1 for this feature.
Node reference does not allow for ease of finding the proper node. Especially when the nodes are similarly named. Being able to see more information about the nodes you are choosing will be great!
Comment #11
kdebaas commentedI was directed here from my original feature request. Sounds very good. I presume it can't be tested against Drupal 5.x yet?
Comment #12
mfredrickson commented@lunas: Thank you for testing. I've already written a nodereference widget to use this on noderef fields. As soon as this gets into views, I'll submit it to CCK.
If anyone would like to try out the new widget, use my contact form, and I'll send it to you. Of course: it's totally beta and has no support. But if you just can't wait....
@kdebaas: Yes - this is probably not 5.x compatible yet. I don't know of any reasons why it wouldn't work - but chances are that some API changed (either in core or in views) that will break this. If you have time to test, please do so - I would be interested to know if it (suprisingly) just works out of the box.
Comment #13
kdebaas commentedDrupal 5.0-RC-1
GD library 2.0 or higher
MySQL database 5.0.24a
PHP 5.1.6
Unicode library PHP Mbstring Extension
Web server Apache/2.0.55 (Ubuntu) PHP/5.1.6
Views 5.x-1.4-2rc1.
Here's what happens:
- Created folder called viewselector in: sites/all/modules.
- Placed viewselector.module and viewselector.inc in folder.
- Created extra file: viewselector.info, (basically copied contents from views_bonus.info)
- Enabled module
- Clicked on newly created menu entry in Navigation: "testing view selector"
Result is white page with:
Fatal error: Call to undefined function _views_get_default_views() in /var/www/parallelports/sites/all/modules/viewselector/viewselector.module on line 435
Next:
- Truncated cache table with PhpMyadmin
- Clicked on "testing view selector"
Result:
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'viewselector_test_form' was given in /var/www/parallelports/includes/form.inc on line 217.
Next:
- Added following line before
$default_views = _views_get_default_views();in viewselector.module:views_load_cache();Result:
Same error message as above.
Hope this means something to you, it's all Chinese to me!
Ciao
Comment #14
moshe weitzman commentedAny progress here? Since Views is now 5.0 compatible, we will probably need that verison before commit.
Comment #15
mfredrickson commentedAgreed. I'm blocking off some time this weekend for getting my various Drupal work up to par. After workflow and viewfield, I'll get this to be 5.0 compat.
I also need to write some patches directly against views, moving some of the exposed filter arguments out of the query builder, and into the front end. Then I can cut down on the size of this module/patch significantly.
Comment #16
panchoChanging version.
Comment #17
lunas commentedI actually have this running in Drupal 5.1 in combination with the noderefselector module. Only problem is that the filter is not working on the node edit form. It can decide which items have been selected, but it won't filter based on the exposed filter of the view. Any ideas why? - right now I'm stuck with either one big list of nodes to select from, or only the nodes that have already been selected - no inbetween.
Comment #18
moshe weitzman commentedAny progress here?
Comment #19
mfredrickson commentedLong story short. No. :-( But it is mission critical to a client on 4.7 who is going to 5.x soon. So I should have some time to revisit.
Comment #20
Lowell commentedIs there a newer version than Dec. 13th? - subscribing
Comment #21
mfredrickson commentedThe best place to watch is probably my sandbox:
http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/mfredrickson/...
There is now a 5.x compatible release, though it still has bugs. Before troubleshooting them too much, I'm going to start looking for ways to simplify my code by presenting some patches for views. Especially, since several of the bugs have to do with arguments and exposed filters - which is something I want to work on for views.
Comment #22
Lowell commentedThanks for the info
I've tried the viewselector test page on a few views and like the way it works.
How do I use this module in different scenarios such as:
--table view of 25 items, I want to select a few and display only those items
--you mentioned cck with node reference to display select box as check boxes or radio buttons
I have limited exposure to drupal modules but am ok with some programming and themeing
Comment #23
mfredrickson commented@lowell -- From earlier in this thread:
That said, your first use case is better served by views' existing exposed filter.
In the second case, I'm not totally sure what you are asking.
My advice, sit this one out and wait for it to get into views. This is not a full module yet, and does not come with any real support. I am committed to helping people get this installed so that they can test it, but that's where the support ends. Of course, bugs and other issues should be stuck on this issue.
Cheers,
-Mark
Comment #24
mfredrickson commentedmy sandbox has been updated.
It now depends on this patch: http://drupal.org/node/125973
Reviews of the linked patch appreciated. Reviews will help this issue along. :-)
Comment #25
JohnG-1 commentedsubscribe - sounds very useful - will test when I get time ...
Comment #26
mfredrickson commentedMy sandbox has been updated again. The form element now depends on views-1.x-dev and this patch: Refactor views_build_views to take exposed filter
Also in my sandbox, I've included the CCK widget that combines this functionality with a node reference field. There's some weirdness with default values. You've been warned.
As always, no support - but reviews actively encouraged. Also, please, please, please review the linked patch above. Earl is busy and there is no way this stuff is going to be incorporated into views until people review the patches. Even just a "I applied this patch and it didn't break my site" would be awesome.
Next steps: I had postponed a patch to get the single include/exclude handler into views. Now that the rest of the form element is nearing completion, this filter should be peeled off into a single, discrete patch for views. Perhaps not depending on the views_node_selector form element in the first patch.
When VNS is framed as a patch to views, it can turn the include/exclude into a better UI.
Comment #27
karens commentedMark, I want to try to do some reviewing but am completely confused about what I need to do to see this in action so I can. Sorry if I'm being dense, but this thread is long and confusing. If I am starting with a clean 5.x install of Drupal and Views, what exactly do I need to do to get to the point where I have something I can review? Is it just apply the patch at http://drupal.org/node/125973 to Views and get the module from your sandbox??
BTW, the subform module mentioned earlier seems to have been abandoned by its maintainer, so that module is clearly not a viable alternative (lots of 'where is MrTaco?' questions and comments from people who tried and failed to find a way to clean up the code in the issues queue, plus just try to find out more about him from the link on his Drupal user page you'll find not only is it not a Drupal site but there is not even a home page!).
Comment #28
mfredrickson commentedKaren,
No problem. Here are the steps one needs to take to test this module:
1. Clean copy of Drupal 5.x and create some content (devel's generate-content.php is useful here)
2. Get the CVS version of Views-5.x (eg. views-5.x-1.x-dev)
3. Get the patch from http://drupal.org/node/125973
4. Apply the patch to views
5. Get the latest viewselector code from my sandbox (mfredrickson)
6. Enable Views and Views Form Element
7. You should get a link in your navigation menu to "test viewselector" - click this
8. You are now on a form that allows you to configure the different options of the form element (e.g. setting #required, #default_value, #view, etc). Pick some options and click submit.
9. This is the form element at work. You should be able to choose any view and filter and page through it.
10. You can submit the form and get a list of which nids you selected.
11. Rinse, repeat with a new view
Things to look for in a review:
1. Patch applying cleanly
2. Paging and filtering working within the form
3. Submitting the form provides you with the right nids
4. The different options work appropriately - required, multiple, etc
5. Views work as you would expect. Though you only get table renderings of the view. Perhaps this can be expanded to other representations later. Even if you don't include a field in the view normally, the form element will add the node title automatically.
If you want to get adventurous you could start writing your own form that uses the 'views_node_selector'. In lieu of documentation, look in the viewselector_elements function for documentation of your options.
To test the CCK widget, follow the above steps, plus enabling content, node reference, and the node reference views widget. It should behave like any other widget, so I don't think I need to go into detail.
Let me know if this is not clear.
Comment #29
karens commented+1 on this idea from me, and I think this is very close to working as it should. Nice job Mark!
I've tried out the patch and the views selector and nodereference selector modules, so here's my assessment:
1) I had problems applying the patch, noted in the patch issue. Once I got past that, the patch works fine and adds a nice new capability to pass filters as well as args to views_build_view(), which is a very nice feature irregardless of anything done here.
2) On the Views Selector, your "testing view selector" menu item is visible to anonymous users. I would move that into the admin area and give it some access control. Or maybe it's going away and is not meant to be a part of the final module, wasn't sure about that. I found it a bit confusing to understand, but again, I'm not sure if that is going to stay or not, so I'm not going to worry about that for now.
3) I did some playing around with the Views selector, but wouldn't say I have fully tested it yet. Initially things seem to be working fine.
4) As to the nodereference selector, nice feature! and basically it works fine, but there are a few issues. For one thing, you need to select the same view in the field as you select in the widget or you can run into problems when your widget allows you to select items that the field doesn't allow, so that needs to be documented in the widget settings. There are some other issues/fixes I could suggest, but I'm not sure I should pollute this issue by going into that here. I should get them documented somewhere while they are fresh in my mind, though, so maybe we should open a CCK issue for that??
Comment #30
jarea commentedI think this is what I have been looking for, but I am not quite sure at this point.
I have set up a clean install of Drupal 5.x, uploaded the patched Views module, view selector files, devel and CCK. I created a single CCK field added to the page node type and then created a test view showing the title and the cck field that I created.
I pulled up testing view selector, selected test as the view and left all of the other fields blank, hit submit and I get a list of node teasers (clearly not what was called for in the test view). It is not clear viewselector is at work here. I am not seeing where the selected subfields are showing. I seem to be missing something here, but not sure what. Any guidance you can provide would be greatly appreciated.
BTW - had the same problems with the first chunk when trying to patch views.module. Used KarenS' suggestion and just deleted the 1st chunk from the patch, then all went fine. After that, install was flawless.
Thanks - jarea
Comment #31
karens commented@jarea, yes, sounds like you are still missing something in your installation. When you see the view in the node it should be in a table format with checkboxes next to each title. You had to install the Node Reference Views Widget (in the CCK area) and the Views Form Element (in the Views area).
Once installed, when you go to edit your nodereference field, you'll see two places that refer to Views. The one at the bottom of the page is created by the core nodereference module and is not the one you want to work with here. You want the one at the top of the page. If you select the test view in that one and save the field, you should see the view in your node as a table with checkboxes. Note that you need to select the same view in the view selector at the bottom of the page for this to work, as I mentioned in my post above.
I've attached a screenshot of the field settings page.
Comment #32
karens commentedAnd here is what the create content page looks like with the nodereference field I just created...
Comment #33
jarea commentedKarenS - thanks for the pointers. I didn't have nodereference activated. Works now as illustrated (thanks for the png too)
jarea
Comment #34
Ian Ward commented+1 This is awesome Mark! I had one issue when filtering, and I had not put in a title yet for the node, after clicking to filter the filter worked, but the validation was triggered, highlighting the title in red and explaining I must enter a title. I may need to update my install. This is really great!
Comment #35
mfredrickson commented@Karen-
First, thanks so much for reviewing. Greatly appreciated!
1) I think I can clear up the patch easily -- as you noted, those last two hunks were unnecessary. Thanks for trying it out.
2) That menu item is just a test-harness. It will not be a part of the final patch. It's just there to give people the opportunity to play with the form element, without writing any code.
4) Yeah - I've noticed that as well. There are a couple of options: use JavaScript to link the two views drop down selectors; move all of views control from the filed to the widget; have the widget rely on the field's choice, not a widget setting. I haven't decided which of these I like the best. Opinions anyone?
Thanks for posting those screen shots!
@DevSeed: There's not a lot I can do about the validation. This is standard drupal behavior. For example, start working on a node, leave out the title, and hit preview. You'll get the same messages. Anytime you submit a form, Drupal runs validation.
Thanks for testing this. Glad you like it. :-)
Comment #36
karens commentedOn the nodereference selector, I don't think the widget should control the field's allowed values, that's the opposite of the CCK way of doing things. The field needs to control things, so I would have the widget just use whatever view the field has selected. Don't know what you do if the field has not selected a view, and has instead checked specific content types, so somehow we need to force the field to make a selection of a view (which again is not good CCK procedure since the widget should not behave that way). So after rambling around, I think the widget must use the field's view selection, but I'm not quite sure of the 'right' way to force the field to use a view.
I ran into another problem on the nodereference selector. If the view has filters and the base view filters one way and you change the filters at runtime to filter something different, you end up with problems because the 'allowed' values are different than what is selected. I'm not quite sure how best to fix this. Test the issue by creating a view with a filter like content type that has one content type selected in the view itself and the filter exposed. As soon as you change the exposed filter to any other content type you have problems.
Comment #37
skor commentedSub
Comment #38
mfredrickson commented@Karen -- I've made the widget rely on the field view settings. I added a hook_form_alter to remove the type checkboxes if you use the views node finder, so there is no confusion. It's pretty clean.
I can confirm the second issue. The work around right now is to make the exposed filter optional and not use the filter defaults. In the long run, we're going to need to make the node reference field aware of filters. I'm working on another form element to pick views, modifying their filters and arguments. When that's ready, I think it would be much better than the current UI, and would allow us the opportunity to pass in filters from the widget, probably.
I'm happy with the current state of the widget, now I'm going back to the form element and going to try to make more of it views native.
Comment #39
moshe weitzman commentedAny further news on that form element? I am getting itchy to implement http://drupal.org/node/125810 but i'd just as soon piggy back on your work as much as possible.
Also, I read through the code and noticed:
- "Here we create a fake column for use in views.". Views recently got an alter hook hook when building the tables array so you often don't need to fake a column anymore. Just add the item to the existing table.
- you use dprint_r(). thats old school. We now abbreviate to dpr(). Also enjoy its friends, dsm() and dvm().
Comment #40
joe.murray commentedI need this for a project and will be taking what is available and working on it as necessary. Can you confirm that the sandbox version of two weeks ago should work with the DRUPAL-5 and HEAD versions of views?
Thanks for this great module.
Subscribing.
Comment #41
mfredrickson commented@moshe - thanks for looking it over. I haven't had much time to refine it lately, perhaps I can squeeze in some time later this week or next. I'm looking at some upcoming projects that will probably make heavy use of it.
@joe - the code should work with views >= 1.6-beta1 (no patches necessary). This would include current DRUPAL-5. I don't know if Earl is keeping HEAD synced with DRUPAL-5, but if he is, then the same statements apply.
Comment #42
mfredrickson commentedJust a note that the code in my sandbox now depends on http://drupal.org/node/141205
@moshe: thanks for the hook_alter idea. I've implemented it - plus I was able to significantly cut down on my code using the pre_view hook as well. I suspect there is more work that can be done in that area.
Comment #43
mfredrickson commentedHurrah. The module is now a patch. This is not to say it is completely working. There is one known bug left and one thing I'd like to do.
Bug: This patch includes an include/exclude filter that allows admins to pick specific nodes. It uses the views_node_selector element to page through options and select the nodes to choose. The problem is that it returns data that is more complex than just an array. As a result, views refuses to store it. I'm going to look at changing views to store serialized PHP in the filter value column, instead of comma delimited strings. While non-serialized data is nice, comma delimited data is still non-normalized and prevents us from having complex filters.
Todo: Provide a better default searching view, one that includes some basic exposed filters. Right now the the include/exclude filter uses the frontpage view, which is not a very complete look at the site.
Other wise, try it out!
There is only one change to the views api: plugins can now be 'hidden'. I did this to have a 'form' view type that would not appear on the views_ui edit pages. The get_views_style_plugin has a change to limit by displayable plugins.
Other changes are moderate. I will be attaching the necessary views_form.inc in my next comment.
Comment #44
mfredrickson commentedNew views_form.inc
Comment #45
yched commentedmfredrickson, I've been following your efforts on this with much interest from day one, but only took the actual time to test it a few weeks ago (shame), and fell immediately in love with it. This is an invaluable addition, which opens the door to a lot of cool UIs.
I'll make sure to help testing and reviewing this new patch as soon as time permits (close deadline on my side right now). Meanwhile, I just waited to voice my praise :-)
Comment #46
MacRonin commentedsubscribe
Comment #47
alanburke commentedsubscribe
Comment #48
infojunkieHi Mark,
I used your great patch to implement "bulk node operations", a feature that was also envisioned by Moshe a while back. You can find the thread here. I had to make a small change to your patch to enable the "select all" functionality present today in admin/content/node among others. Here's what I did:
In file views_form.inc, replace the line 295 that says
with
It would be great if you could incorporate that modification in your patch.
Thanks,
Karim
Comment #49
dharamgollapudi commentedSubscribing...
Comment #50
merlinofchaos commentedMark: I'd like to encourage you to get this patch to the point where I should be reviewing it. (I've been letting you guys work on it while it's in CNW status).
Second: Everyone should take a look at http://drupal.org/node/103171 -- this does something interesting. The patch that's currently there needs a lot of work, I think, but the basic approach looks like a decent idea. I'm afraid, however, that this approach and that approach may end up at odds, and I absolutely don't want that. I would like people to work together to make sure that both efforts can be used.
Getting Views to reasonably do forms is going to be a big deal.
Comment #51
mfredrickson commentedEarl: You posted a link to this issue. :-)
On the review aspect, the only part that doesn't work is the filter form for the include/exclude filter. What do you think about views storing filter values as serialized text? If that's ok, then getting this patch up to speed is trivial.
Comment #52
merlinofchaos commentedOops. That patch is at http://drupal.org/node/151868 -- sorry about that.
I'm leery about actually storing filter values. Why do we need to store them?
Comment #53
infojunkieI've completed the implementation of a sub-module called views_actions that uses the Views form element to allow selecting multiple nodes from a view and applying an action on the selection. It is currently available at http://groups.drupal.org/node/4725. Ideally, this code could be merged with Views Bonus Pack for example, but right now it completely relies on the form element patch and so its fate is bound to that of the patch.
Since the functionality offered by views_actions complements what's offered here, I'd appreciate that the people on this thread take a look at it and give me some feedback. Specifically, I'd appreciate hearing from mfredrickson and merlinofchaos to critique my approach and help me find the right packaging for the code.
FYI: I applied the Views form element patch to Views 4.7.x-1.6-beta5, it worked well as far as I could tell.
Comment #54
mfredrickson commented@merlin: on the subject of serialized filter values: I support storing the values returned from forms as serialized PHP for the following reasons
1. We already store non-normalized values in the form of comma delimted strings in a longtext column. Sure, these are are a little more readable than a:5{....} but they are not normalized for DB usage.
2. Forms need to be able to return more than just a single value or a an array of simple values. For example, let's say I'm doing a distance calculation to get all the nodes within X miles of a point. This form needs to have a center point (x,y) as well as a distance value. Any form is going to return something complex. Let's store that for the form instead of putting that burden on some other module.
3. Form values are going to be serialized when views are cached anyway. For views that can be cached all the time, there's no performance penalty.
4. The upgrade path is easy. We already have a longtext column to store filter values. An update hook can pull all the data out and serialize it.
Basically, we serialized data we get rich form data, and pay little cost in terms of performance or DB normalization.
Comment #55
merlinofchaos commentedNote that individual filters can, if they like, serialize their data themselves. There's a method to do this in the API docs, in fact, though it is a bit of a pain.
I can see adding value-type: serialized and doing an automatic serialize/unserialize on save if this is true; I think that would be better than automatically serializing all values. It's true, it's not normalized but in general other processes shouldn't be poking at these database values. And that'd be less intrusive than updating everyone's views databases.
Comment #56
harry slaughterPatch against views DRUPAL-5--1-6
Comment #57
harry slaughterNew version of views_form.inc that includes this patch: http://groups.drupal.org/files/views_actions.patch_.txt.
Required to run "Views Bulk Operations" http://drupal.org/project/views_bulk_operations - which is broken ATM :)
Comment #58
merlinofchaos commentedLet's start by adding some documentation to this patch. Let's get an @file which gives a rough idea of what we do. Also, let's put the functions most likely to tell you what the file does at the top; the first function in there is a private function. Not so good for getting a feel for what it does.
Comment #59
ray007 commentedsubscribing
Comment #60
harry slaughterThe views_bulk_operations module is indeed functional. Download the dev version here: Views Bulk Operations Module.
To get a working version yourself, you'll need to do the following:
0) Install Drupal 5.1 and views (DRUPAL-5--1-6); also install workflow and actions module for best demo (optional).
1) apply the patch in comment#56 to views DRUPAL-5--1-6
2) save the file in comment#57 to modules/views/views_form.inc
Gratuitous screenshot attached for marketing purposes.
Help testing appreciated.
Comment #61
harry slaughterLatest views_form.inc
Cleaned up and better documented.
Comment #62
harry slaughterChanging version value. The latest patch and views_form.inc file apply against views DRUPAL-5--1-6
Comment #63
merlinofchaos commentedFirst, I don't suppose you can convince your editor not to trim whitespace? I realize it's a flaw in MY editor that leaves the whitespace there invisibly, but it makes the patch a little more difficult. Only a little, so it's not a HUGE deal.
and
I'm philosophically opposed to the default view here. It seems extremely arbitrary, and unlikely. Can we eschew a default view and have a fail condition if a #view is needed and not provided instead?
I've been trying to get away from hard coding the type here. Instead, I've been relying on flags set in the plugin data. For example, 'needs table header' is used for the table type so that it knows it needs a header. That way other plugins can use the same basic ideas. Also, this means that the form style plugin only works on page views, and there may be use cases where simple forms may be used in blocks.
I may be wrong here, but it seems to me that if $titles == TRUE we're displaying, and if $titles == FALSE we need the full data. Also, we could probably be more efficient with array_filter in either case.
This is going to be really confusing to users. How are they to know that 'frontpage' is what this is limiting their nodes to? We probably need to create a way to include views specifically. This one might be more complex; I'd initially thought to just include all views, but at this point we may not actually know about all views. So instead, we probably need some way to add views to a list, and then each one of them is then given its own include_exclude filter.
Comment #64
mfredrickson commentedOn the default view: you last point is why it is included. For use in forms that are not user generated per-se, such as the include/exclude filter. Since this form is going to be repurposed for a bulk actions module, perhaps they can generate a useful default view: one that provides exposed filters for generic node level fields (title, created on, type) and otherwise shows all content.
On flags in plugin types: I like it. For starters, how about 'no_exposed_filters' (defaults to false) to remove exposed filters. I'll see if I can think of some others.
As for $titles == true/false, perhaps, I'll have to look again. Basically, I needed a way to filter out plugin types that should not be displayed to the user on views edit pages because they need additional, programmatic control (e.g. forms). I'm happy with any solution that achieves that.
Comment #65
pwolanin commentedsubscribe
Comment #66
moshe weitzman commentedthe bulk operations module depends on this patch. if anyone has time to work on it, that would be swell.
Comment #67
pwolanin commentedI'm planning to try to dive into it this weekend. I'll be looking for help on IRC, though.
Comment #68
wuf31 commentedsubscribing
Comment #69
amitaibusubscribing
Comment #70
mikeryanSubscribe
Comment #71
pwolanin commentedok, I'm starting to get an idea of what this does, but it seems that this patch doesn't really provide much of any functionality without an additional module that builds forms? Am I missing something?
If I select for a page "View Type:" of "View form" I just get a blank page. That doesn't seem right... Or is that what needs to be done so that another module can use it in a form?
Here's a new patch which includes the .inc file as well. Not modified at all except to put it all in one patch.
Comment #72
pwolanin commentedPerhaps this can be simplified a bit - is the added filter element necessary for the basic functionality? I can't even see that it works.
Comment #73
harry slaughtercomment #71 form_element_2.patch appears to be corrupt. please use the files from #57 and #61 if you'd like to patch views.
the style plugin currently provided by this patch indeed does nothing and should probably go away. this patch should not result in any visible changes to views. it should, instead, simply allow for a new form element to be used called 'views_node_selector', which when implemented by a module (such as: http://drupal.org/project/views_bulk_operations) will enable the node selector functionality we're all so anxious to see :)
see this screenshot for better understanding: http://drupal.org/files/issues/views_bulk_operations.png
Comment #74
pwolanin commentedWhile waiting for the trimmed down patch - playing with this with the VBO, or a my own very trimmed down version, everything looks pretty good.
Note - if there is no default style plugin, the #embeded attribute will always be true, and so can be eliminated, right?
Comment #75
pwolanin commentedThinking further about how to make this the most generally useful functionality - we should be able to pass in a list of checkboxes that are disabled, as well as passing in the ones that are checked by default.
To do this, however, it seems would require re-implementing these 2 functions:
http://api.drupal.org/api/function/expand_radios/5
http://api.drupal.org/api/function/expand_checkboxes/5
Comment #76
aclight commentedsubscribing
Comment #77
mfredrickson commentedLet me comment on two points of contention:
Plugin
The purpose of this patch is to provide a form element that formats a view (ie. a query and output render) into a form of either checkboxes or radios. Therefore, it is imperative that we receive a callback to theme the view - otherwise it will be turned into teasers, a list, a gmap, etc. Plugins are theme callbacks to achieve this goal.
The patch included a new setting for plugins that allowed them to be "hidden", i.e. not seen by the user on /admin/build/views/add. Has this fallen out of the patch? If so, it needs to go back in if the plugin remains.
I am open to other ideas on how to theme the view appropriately. This is actually the second version of the system. In the first I didn't use an output plugin and it was MUCH more complicated. It involved calling views_build_view('items'....) and then going through most of the same steps that occur in views_build_view('embed'...). Duplicated code sucks.
Potentially another option would be to have $view->type == 'form', like it does with block, page. This would then require changes to views_build_view, but would eliminate the plugin if people are comfortable with that.
Again, the plugin SHOULD NOT be visible to users. This was in the patch in #43 includes a guard against this.
Include/Exclude Filter
This is not a critical feature. However, we do need to recreate the functionality by modifying the query object during views running so that we include certain nids. E.g. add_where('n.nid IN (1,3,4,5,6,7,...)'
This is necessary so that we can fetch certain "missing" nodes. Missing nodes are the currently selected nodes that are not included the results from the view. For example, I'm on page 1 of a view and select nodes 1, 2, and 3. Then I page to page 2. At this point, we still need to display that 1,2, and 3 are selected, even though the view won't find them because they are in the previous page.
Any solution that can achieve this goal can replace the include exclude filter.
Removing the include/exclude filter also eliminates the need for a default view in the form element, another point of contention.
Conclusion
I think the plugin should stay. We just need to make sure the code I wrote to hide it's presence on the admin forms is still in the patch.
I think the include/exclude filter should go. More complicated than it is worth.
Comment #78
amitaibuSubscribe
Comment #79
pwolanin commentedok - this patch is a radical simplification and tries to more appropriately fit within the way Views normally works. However, I think all the essential functionality to make it relatively easy for a module to turn a view into a form is retained.
Note, it seems to me that for Views Bulk Operations module, it should be theming the entire view, rather than just making a plugin. In the Views module, the general theme function - theme_views_view() - produces this sort of output:
---
header
---
exposed filters
---
content - themed via plugin (a.k.a. depending on page_type or block_type)
---
footer
---
pager
---
So, instead of (or in addition to) the plugin in the VBO module, if you want control over display of the exposed filters and pager in VBO module, it seems that you should implement theme_views_view_admin_content().
Comment #80
pwolanin commentedHere's a minimal module that demonstrates the functionality of the patch - the _submit functions just use drupal_set_message() to show the values, they don't do anything else.
note- you need to save-as to get rid of the .info extension (needed to trick project into letting me upload a tarball)
Comment #81
harry slaughterAnother great way to try this out is with the views bulk operations module: http://drupal.org/project/views_bulk_operations
The latest version is designed to work with patch #79 (tks pwolanin)
If you're interested in helping test this patch and/or views bulk operations and need help setting it up, contact me. But all you need to do is apply patch #79 to views version DRUPAL-5--1-6 and install the VBO module.
Comment #82
hsfdrupal commentedI would very much like to use this on an intranet, but am unsure how to proceed. The patch file on comment #43 appears to be the most recent, but it is not against the current version of Views (current views.module is 1.166.2.43 and the patch references 1.166.2.41). How can I get this implemented now?
I have a CCK (purchase request) and the user has to select from a list of vendors. A vendor is a CCK in my system, and I currently use a Node Reference as a Select List when the user has to specify. It is unwieldy with 600 vendors though. I am hoping that this patch will allow me to show a View of the vendors instead, with filtering/search so the user can navigate the vendor list easily. Am I on the right track?
Thanks!
Comment #83
hsfdrupal commentedOops, never mind - I found the newer version of the patch by pwolanin, missed it the first time.
This is great functionality!! What are the odds of someone making the noderefselector use ajax to search the view instead of doing a page refresh? (I know, I want the world. . .)
Thanks so much for this!
Comment #84
harry slaughterI've been using patch #79 (and the views bulk operations module) in a dev environment for a couple weeks now. I've run into no problems.
This latest patch includes minimal changes to existing views code. I think it's more than ready to be included in the next beta release of views.
Comment #85
Bedestenlioglu commentedHi ,
I am a newbie and having problems in installing views bulk operations module. Currently. I am using
Drupal 5.2
CCK 5.x 1-6
views 5.x 1-6
As described in comment #84, I have applied the patch from #79 and copied the VBO from CVS repository directory to my drupal/sites/all/modules/view_VOB directory . There are now three files in the directory which are:
views_bulk_operations.css
views_bulk_operations.module
views_bulk_operations.info
The following warning is given as I attempted to list the module in drupal/administer/site building/modules :
warning: Error parsing sites/all/modules/views_VOB/views_bulk_operations.info on line 5 in C:\xampp\htdocs\drupal-5.2\includes\module.inc on line 195.
And VBO was not in module list.
Selda
Comment #86
Bedestenlioglu commentedsorry , I have changed the title by mistaken
Comment #87
pwolanin commented@Bedestenlioglu :if you are having problems with the VBO module, please file the issue there: http://drupal.org/project/issues/views_bulk_operations
Comment #88
harry slaughterThis patch and views bulk operations are not released. There is no support and they are not guaranteed to work. That being said, I am using both in a semi-production environment and they are stable. But you have to know what you're doing to get them both working.
Comment #89
pwolanin commentedComment #90
msameer commentedsubscribing...
Comment #91
harry slaughterI'm going to begin work on an alternate implementation of views forms: http://drupal.org/node/188276
Comment #92
spjsche commentedTrying to move to v5, as using subforms on v4.7.
Hopefully this could solve my problem.
Subscribing.
Comment #93
summit commentedsubscribing
greetings,
Martijn
Comment #94
rjleigh commentedIs this patch in Limbo, or will it eventually get committed? Since it was offered almost a year ago, I'm concerned that the views team really doesn't want to go this way.
Too bad, cause the idea behind the Views Bulk Operations mod is great, but I don't necessarily want to support it over time with a patch to each Views update.
Comment #95
pwolanin commented@rleigh - see #91. Apparently this isn't the "best" way to approach the problem. However, Harry seems not to have made much progress. Maybe I'll go ahead and make this a module - but it's unlikely to get updated for 6.x (i.e. Views2).
Comment #96
infojunkieWe're happy to announce that the Views Bulk Operations module no longer depends on this patch to run. We released today VBO-1.0-Beta 1 which is 100% patch-free! Great thanks go to pwolanin whose simplified patch was successfully integrated inside VBO instead of being applied to Views.
Comment #97
Jkello commentedSo is this patch still working? Still going forward. Just to clarify. Thanks.
Comment #98
pwolanin commented@JK_drupal - it seems essentially that this patch will not become part of views. See #91 and #96 above and my earlier comments. Since the patch made essentially no changes to the main views module, it can just be added on as a separate module for those that want to use it. I'll probably close this issue soon.
Comment #99
summit commentedHi,
Will it then not be smart to build the module to have it available for all (on Drupal 5 for instance at first)?
Happy Year-ending.
Greetings,
Martijn
Comment #100
pwolanin commented@Martijnhaan - this is essentially being maintained now as part of the VBO module. You can use the .inc file from there with your own module if you want to do something different.
Comment #101
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.