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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

We 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.

good_man’s picture

I'll see what I can do for the patch, you began working on this feature in views3?

dawehner’s picture

Not really #792044: Allow for field grouping is the issue

good_man’s picture

aha 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?

good_man’s picture

Okay 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() ?

good_man’s picture

Status: Active » Needs review
FileSize
3.23 KB

Here 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?

good_man’s picture

Category: support » feature
FileSize
3.23 KB
good_man’s picture

Why the previous two patches have not been tested?

merlinofchaos’s picture

There 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.

good_man’s picture

No sorry I didn't clarify well, my question question why qa.drupal.org didn't autotested it?

merlinofchaos’s picture

Oh! 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.

good_man’s picture

Sorry again, it's newbie testing question. Anyhow, take your time reviewing patches and thanks for the great effort.

dawehner’s picture

Just 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.

good_man’s picture

I'm sorry but I didn't understand your point?

dawehner’s picture

Okay 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 :)

merlinofchaos’s picture

Status: Needs review » Needs work

This 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?

good_man’s picture

Title: Add Ajax button » Add Views UI Ajax forms hook
Version: 6.x-2.9 » 7.x-3.x-dev
Status: Needs work » Needs review
FileSize
579 bytes

uhh 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)?

dawehner’s picture

Status: Needs review » Needs work

If 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?

good_man’s picture

How it's possible to do that in drupal_alter?

a separate topic to describe what I want to accomplish here #1149604: Fields View Grouping

good_man’s picture

By using drupal_alter you mean something like this:

  drupal_alter('views_ui_ajax_forms', $forms);

Then I can use:

  hook_views_ui_ajax_forms_alter();

?

Is better in performance? or just simpler?

dawehner’s picture

It's definitive simpler and it's a common pattern in drupal.

good_man’s picture

I'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.

jdufaur’s picture

+1 subscribe

rooby’s picture

Status: Needs work » Needs review
FileSize
2.45 KB

Here 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.

rooby’s picture

Whoopsie, there is a mistake in the doco in that one.
This one is better.

Chris Matthews’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

The 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.

Checking patch includes/admin.inc...
Hunk #1 succeeded at 2875 (offset 94 lines).
Checking patch views.api.php...
error: while searching for:
}

/**
 * This hook allows to alter the commands which are used on a views ajax
 * request.
 *

error: patch failed: views.api.php:1067
error: views.api.php: patch does not apply
Andrew Answer’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
2.4 KB

Patch rerolled.

renatog’s picture

Status: Needs review » Reviewed & tested by the community

I 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?

DamienMcKenna’s picture

Thanks everyone, let's add it to the next release.

DamienMcKenna’s picture

Title: Add Views UI Ajax forms hook » Add Views UI AJAX forms hook
Status: Reviewed & tested by the community » Fixed

Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.