Hello,
I'm trying to add a button (I'm building it as a module for sure) next to "rearrange" and "add" buttons in views edit screen. I've accomplish this goal by overriding preprocess functions and template views-ui-edit-item.tpl
Well, so far so good, the problem is with the link of the button, when I click this button I should get a page or ajax form to modify some fields, like "rearrange" button link "admin/build/views/nojs/rearrange/$view->name/$display->id/$type", well rearrange button adds itself via "views_ui_ajax_forms" function in admin.inc. hooof long story, well I don't want ever to edit views' code, but the problem is "views_ui_ajax_forms" can't be overridden or something like that, is it possible to do this without editing admin.inc?
Thanks in advanced.
Reference:
http://stackoverflow.com/questions/3279080/drupal-views-module-group-fie... (I'm Khaled)
P.S. Semantic Views doesn't support this, also, I don't want to make it as style plugin.
Comment | File | Size | Author |
---|---|---|---|
#27 | views-ajax_forms_alter-882772-27.patch | 2.4 KB | Andrew Answer |
|
Comments
Comment #1
dawehnerWe could add a alter hook.
I see the problem that the views ui is not very extendable. Every patch which helps here is fine.
For you question at stackoverflow, there is already a feature request for views3.
Comment #2
good_man CreditAttribution: good_man commentedI'll see what I can do for the patch, you began working on this feature in views3?
Comment #3
dawehnerNot really #792044: Allow for field grouping is the issue
Comment #4
good_man CreditAttribution: good_man commentedaha I see, I want first to implement it in 2.x, what do you think?
Another thing is I'm a little lost defining hooks in views, how do you define them? I only see hooks in docs.php is that where they are defined or just for docs?
Comment #5
good_man CreditAttribution: good_man commentedOkay I see it now, you make all hooks as dynamic function, anyhow what is the benefit? I mean why not using the traditional hook_foo_bar() ?
Comment #6
good_man CreditAttribution: good_man commentedHere is my first patch, hope will pass all tests.
There is now a new hook called: 'hook_views_ui_ajax_form' which collects forms info from all modules that implement it. Views module implement this hook via 'views_views_ui_ajax_form' to add it's forms and buttons (e.g. display, remove-display, rearrange).
There is a small issue that I want to discuss, is there any need for caching the results of that hook? for example the previous views_ui_ajax_forms was called four times inside admin.inc but this hook is only for Views UI so only few users will use it, is it worth caching?
Comment #7
good_man CreditAttribution: good_man commentedComment #8
good_man CreditAttribution: good_man commentedWhy the previous two patches have not been tested?
Comment #9
merlinofchaos CreditAttribution: merlinofchaos commentedThere are 3 pages of issues marked 'needs review' in Views. You're asking why nobody has looked at your patch after only 3 days. Please be patient.
Comment #10
good_man CreditAttribution: good_man commentedNo sorry I didn't clarify well, my question question why qa.drupal.org didn't autotested it?
Comment #11
merlinofchaos CreditAttribution: merlinofchaos commentedOh! qa.drupal.org only does testing on modules configured with tests. Mostly that's Drupal core and some smaller modules.
Views does not have much in the way of automated tests, so hasn't been added to the auto testing framework.
Comment #12
good_man CreditAttribution: good_man commentedSorry again, it's newbie testing question. Anyhow, take your time reviewing patches and thanks for the great effort.
Comment #13
dawehnerJust some thoughts
* this allows to extend the ui in a way which is how views handles it's ui
There should be perhaps some documentation about this hook.
Comment #14
good_man CreditAttribution: good_man commentedI'm sorry but I didn't understand your point?
Comment #15
dawehnerOkay as you see views injects it's forms via views_ajax_forms so it's natural to let other modules inject with the same method.
A documentation for this hook would be cool :)
Comment #16
merlinofchaos CreditAttribution: merlinofchaos commentedThis patch seems too complicated for something that is essentially just adding a hook so that you can add totally new ajax forms. Plus, I don't really like renaming functions for no immediately obvious reason.
Can we simplify this?
Comment #17
good_man CreditAttribution: good_man commenteduhh it was really a complex bad patch, here is another version.
@dereine: is the one-line comment enough? or you want to document it elsewhere (e.g. views.api.php)?
Comment #18
dawehnerIf possible all hooks should be included into the views.api.php file.
I'm wondering why a plain drupal_alter does not help you here?
Comment #19
good_man CreditAttribution: good_man commentedHow it's possible to do that in drupal_alter?
a separate topic to describe what I want to accomplish here #1149604: Fields View Grouping
Comment #20
good_man CreditAttribution: good_man commentedBy using drupal_alter you mean something like this:
Then I can use:
?
Is better in performance? or just simpler?
Comment #21
dawehnerIt's definitive simpler and it's a common pattern in drupal.
Comment #22
good_man CreditAttribution: good_man commentedI'll wait for a reply on #1149604: Fields View Grouping, then if you don't need such an addition (added performance and complexity), then I don't mind closing this issue without committing.
Comment #23
jdufaur CreditAttribution: jdufaur commented+1 subscribe
Comment #24
rooby CreditAttribution: rooby commentedHere is a new version for latest dev that uses drupal_alter().
My use case is actually for adding forms, not altering existing ones, and being able to add forms to views_ui_ajax_forms() seems like the cleanest way.
Comment #25
rooby CreditAttribution: rooby commentedWhoopsie, there is a mistake in the doco in that one.
This one is better.
Comment #26
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 5 year old patch in #25 to admin.inc and views.api.php does not apply to the latest views 7.x-3.x-dev and if still applicable needs reroll.
Comment #27
Andrew Answer CreditAttribution: Andrew Answer as a volunteer commentedPatch rerolled.
Comment #28
renatogI applied and really works well.
The patch include the new hook alter
views_ui_ajax_forms_alter
and it's well documented at views.api.php+1 to RTBC, thanks a lot for your contribution
I think we can commit and include in Plan for Views 7.x-3.26. Anyone against?
Comment #29
DamienMcKennaThanks everyone, let's add it to the next release.
Comment #31
DamienMcKennaCommitted.