#1608878: Add CTools dropbutton to core made me realize that the "drop button" (I didn't know it was called that) was actually a reusable component, and exists in ctools. That is cool.
What would be even nicer is if I could use it in a View. Admin views frequently have columns for "view", "edit", "delete", "flag", "add to nodequeue", etc. that take up a ton of visual space. Merging them into a single column is possible, but gets ugly fast since you have random strings separated by a / or something.
Ideally, it would be possible to take a series of such string fields and compress them into a single drop button column. Then we could build administrative views that offer all sorts of operations in a single space-saving column.
In IRC, Earl indicated that it "shouldn't be that hard to implement". Famous last words, I know. :-)
Comment | File | Size | Author |
---|---|---|---|
#31 | views-dropbutton_field-1608920-28.patch | 11.83 KB | Anybody |
| |||
#29 | Users.png | 43.99 KB | joelpittet |
#28 | interdiff-1608920-23-28.txt | 3.01 KB | rudiedirkx |
#28 | views-dropbutton_field-1608920-28.patch | 11.83 KB | rudiedirkx |
#27 | interdiff-1608920-23-27.txt | 2.58 KB | rudiedirkx |
Comments
Comment #1
dawehnerEarl was right.
Attached a patch and a view to test this feature.
Comment #2
tim.plunkettThis looks promising :)
How are these different?
Might as well split this over two lines.
$ops? Also, why not just return theme()?
Comment #3
bojanz CreditAttribution: bojanz commentedOh, following (and will review later).
I currently create a new handler for each group of contextual links I need to show in a dropbutton (order, node, product), having a generic solution would be awesome.
Comment #4
dawehnerAssign to myself to work on that on the train.
Comment #5
dawehnerSo here is a total rework which uses the full power of inheritance etc.
Thanks for the review, you are right, i changed this points.
Comment #6
dawehnerThe new view
Comment #8
dawehner#5: 1608920-dropdown-field-1608920.patch queued for re-testing.
Comment #9
dawehnerThis time a better working version, sorry removed something exactly before creating the patch.
Comment #10
damiankloip CreditAttribution: damiankloip commentedYes, that patch looks better. That seems to be working as expected now.
Comment #11
bojanz CreditAttribution: bojanz commented#destination should be #description.
I tried and couldn't get it to work.
I added "Commerce Product: Edit" and "Commerce Product: Delete" fields (both just output a link by returning l($text, $link)...)
I then added the dropbutton field (tried with contextual as well), and selected those two fields.
Got broken links that had the entire HTML as the label, generated like this:
I probably missed something, but I expected that to work.
Furthermore, in Commerce and related modules, we have handlers that do something like this:
So my ideal handler would be entity-type-agnostic, and call menu_contextual_links() for me.
The url ('admin/commerce/product') could be taken from the field definition, or the handler could do something like this:
(Unsure if that's considered abuse of entity_uri(). Would work for products, orders, nodes... Not sure about other entity types).
That's my perspective (which doesn't need to affect the work here of course), with a touch of bikeshedding.
Comment #12
bojanz CreditAttribution: bojanz commentedAlso note that regardless of the implementation, we need to add the dropbutton CSS when the field is used so that it actually looks the same as in Views admin.
Something like:
Comment #13
dawehnerUps right... this happens if you use the autocompletion of your ide.
The current patch assumes that you create links in the way views create links which means that you set $this->options['alter']['path'].
Once you have that $this->get_links() can work as expected and return something like
array(array('href' => ...)). This structure is needed both by contextual links and ctools dropbutton. In theory though both ways should be supported. At least there should be a way to support multiple links from a single field.
What about adding a checkbox to add the js/css or not.
Regarding the idea of using menu_contextual_links i think once we support multiple links from a single field we could build an additional field handler for that. We can't support just links like that, because people will come up with crazy views-configured custom links.
Comment #14
dawehnerAh maybe the css works for me already because i use the rubik admin theme, will check that later.
Comment #15
dawehnerping
Comment #16
helior CreditAttribution: helior commentedRe-rolling; Fixed that typo mentioned in #11 and added an option to add css to match the style of drop-buttons in the views admin.
Does someone have an example of a field that does this?
Comment #17
willieseabrook CreditAttribution: willieseabrook commented#16 applies against 7.x-3.4 and is working great thanks guys.
Re the use case - I needed the functionality for a commerce site also - customer is unhappy with the clutter caused by various hyperlinks in the orders list.
I could also use this in a bunch of other places, so this is great functionality to add.
Comment #18
willieseabrook CreditAttribution: willieseabrook commentedHmm, any reason why the options form doesn't inherit the parent?
I want to be able to give the table column a label!
should be:
Comment #19
geek-merlin* tested this patch
* added code from #18 which totally makes sense
* found a flaw: if a field is NOT linked it will instead be linked to frontpage. fixed that.
please test so we can get this in finally!
Comment #20
JvE CreditAttribution: JvE commentedI'm loving it.
Comment #21
JvE CreditAttribution: JvE commentedExternal links should probably not get a destination query.
Comment #22
geek-merlingee, yes!
(will test as i find time...)
Comment #23
solotandem CreditAttribution: solotandem commentedI was glad to find this issue with a solid patch.
My use case requires more of the URL options, like query arguments and alt titles, that are exposed on a views field. So, to utilize those options, the attached patch copies code from
views_handler_field::render_as_link()
.Comment #24
AnybodyWhao the patch works great and this is really an important feature!!
Do you think it makes sense to put this into views or should we better create a separate module (first) because it may need a lot of time to get this into views? Or has someone already done this via a module // or is it impossible?
Thanks a lot for your great work guys!
Comment #25
AnybodyI've just written a contrib sandbox module based on the patch which makes it possible to test and use the functionality while the patch is not part of views. I think some people will be happy about it. Furthermore I used the same names as in the patch so when the day comes where the patch makes it into the views release you should just be able to remove the module and everything should work fine.
If anyone of you would like to have maintainer access, please contact me. I'd be happy :)
Thanks a lot for your great work!
Sandbox: https://www.drupal.org/sandbox/anybody/views_ctools_dropdown
Comment #26
rudiedirkx CreditAttribution: rudiedirkx commentedPatch works great, but:
$form['fields']
inviews_handler_field_links::options_form()
should be#required
.Comment #27
rudiedirkx CreditAttribution: rudiedirkx commentedFixed 2/3 issues:
#required
Patch & interdiff attached.
Did not fix:
Comment #28
rudiedirkx CreditAttribution: rudiedirkx commentedAlso added
options_submit()
to clean up unselected options from form state, because we don't want unselected options to be exported etc.Comment #29
joelpittetThis is awesome. The absolute positioning would be great but this definitely is a nice improvement, but I'd suggest a follow-up.
Comment #30
colanWe've recently switched our testing from the old qa.drupal.org to DrupalCI. Because of a bug in the new system, #2623840: Views (D7) patches not being tested, older patches must be re-uploaded. On re-uploading the patch, please set the status to "Needs Review" so that the test bot will add it to its queue.
If all tests pass, change the Status back to "Reviewed & tested by the community". We'll most likely commit the patch immediately without having to go through another round of peer review.
We apologize for the trouble, and appreciate your patience.
Comment #31
AnybodyRe-uploaded #28 as of #30.
Comment #32
AnybodyComment #34
colanThanks!
Comment #35
tstoecklerIn D8 this already exists since #1826604: Add a dropbutton field handler to Views. Feel free to re-open if I'm missing anything.