Currently hook_popups() supports two sorts of popups: ones to be generated on a particular page and ones to be generated on a particular form. However, there are other use cases that might require more flexibility. For example, a popup to edit a node title. Here we would need to be able to add this popup to any node being displayed.

How best to approach this? One way might be to emulate what actions does with hooks.


      'hooks' => array(
        'nodeapi' => array('presave'),
        'comment' => array('insert', 'update'),
      ),

Obviously this sort of data can't easily be encoded in an array key like a path or form id can. But we could do something like this:



function mymodule_popups() {
  $items = array();
  $items['my/path'] = array(
    '#my-id',
  );
  // Numerical index for other than paths and form ids.
  $items[] = array(
    '#my-other-id' => array(
      '#hooks' => array(
        'nodeapi' => array('view'),
      ),
    ),
  );
  return $items;
}

Comments

starbow’s picture

I am having trouble wrapping my brain around this one.

For something like editing a node title, I think we are better off trying to get edit-in-place going, vs moving it into a popup.

Can you give me another use case or two?

sunilchai’s picture

Category: feature » support

Hi ,

I had a button and when ever i click on the button i want the popup to be enabled with some form and fileds.

Is that possible using the pop up module?? if so how can i achieve that.

hoping for the earliest reply,

Thanks and regards,
sunilchai..

2ndChanceTech’s picture

Wouldn't it be possible to simply have custom form templates, that are limited to just the fields you want, then have popup dialogs load the form using that template?

Haven't tried in 6, but it was possible in 5x with hook_form_alter. You could then just create a .tpl that contains the fields you need editable.

It's a good amount of work, but probably the only way to do per field editing in a pop-up (atleast that's how it was done in 5.x)

scottrigby’s picture

Hi starbow,
Re #1, another use case would be when a module adds a link to node->$links

For instance, I made a small module that adds a link to create a child content type in the $links of a parent content type.

In order to get the popup functionality working the way I want, I borrowed from popups_admin.module, and played with some of the Options from the README. However I can only do this on a per-path basis. This is how I got it to work on node/2:

/**
 * hook_popups
 * This implements hook_popups, defined in popups_get_popups.
 */
function popups_addnodelink_popups() {
  return array(
    'node/2' => array( //example node
      '#node-2 a:contains('. t('Add new event') .')' => array( // Add Event link
        'additionalJavascript' => array('misc/collapse.js'),
        'reloadWhenDone' => TRUE,
      ),
    ),
  );
}

Unfortunately it doesn't seem to work with something like:

    'node/'. $node->nid => array( //example node

Which I would need in order to get this to work on all nodes that contain this string.
This is why my issue seems to relate to nedjo's original support request - because it needs to apply to any node being displayed.
Does this make sense? Is there another way to do this?

starbow’s picture

@scottrigby: it is both exciting and humbling to see all the ways people want to use this module that I never considered :)
How about something like:

function popups_addnodelink_nodeapi($node, $op) {
  if ($op == 'view') {
    popups_add_popups(array(
      'a:contains('. t('Add new event') .')' => array( // Add Event link
        'additionalJavascript' => array('misc/collapse.js'),
        'reloadWhenDone' => TRUE,
      ),
    );
  }
}
scottrigby’s picture

hi starbow -- thanks!

Ok, I tried this code in my custom module -- and I just get a blank white screen :?
I've been trying to see where there may be some error and so far can't find it :(
If you have any time to look at this again, I'd appreciate it -- This would be really great to get working :)

Edit: sorted :) See below...

scottrigby’s picture

ok, got it :p

function popups_addnodelink_nodeapi($node, $op) {
  if ($op == 'view') {
    popups_add_popups(array(
      'a:contains('. t('Add new event') .')' => array( // Add Event link
        'additionalJavascript' => array('misc/collapse.js'),
        'reloadWhenDone' => TRUE,
      ),
    ));
  }
}

And guess what? it works!

scottrigby’s picture

@ starbow: Is there a way to use wildcards when specifying the path of the link?

So instead of:

      'a[href$=node/7]' => array( // specific link path
        'additionalJavascript' => array('misc/collapse.js'),
        'reloadWhenDone' => TRUE,
      ),

something like this?

      'a[href$=node/'. $n .']' => array( // specific link path
        'additionalJavascript' => array('misc/collapse.js'),
        'reloadWhenDone' => TRUE,
      ),

Where $n is either a node of a particular type, a child of the current node, or something else. Is something like this possible?

starbow’s picture

Category: support » feature

I am glad that worked for you.
Wildcards are not currently supported. Feel free to open it as a new feature request.

starbow’s picture

Status: Active » Fixed

I have added a single wildcard in rc6. '*' means all pages. Not as clean as a new hook, but it works and it is simple.

scottrigby: This do not address your request. Rereading #8, I actually don't know what you are asking for. And a new issue thread is definitely a better place to discuss it.

scottrigby’s picture

Hi Starbow - great that you were able to add this :)

To clarify #6... (at least the part that relates to this issue):
* In popups_admin.module (from popups-6.x-1.1-rc5), on line 29 is the first instance of specifying a popup based on the link path:
'#tabs-wrapper a[href$=admin/build/block/add]', // Add Block

Building upon your nodeapi support, what I was hoping is to be able to give a wildcard to a link path, so if I have a list of nodes on a certain page such as node/2, node/35, node/10... etc, we could specify a popup on all of these links by writing something like this:
'a[href$=node/*]', // view node
This is just a generic example. But it sounds like the wildcard you just added would do the trick for this? Could you clarify how this wildcard is used if different than the example just above? :)

starbow’s picture

The wildcard I have introduced is for adding the rule to the page.

What you want is 'a[href^=node/]'
You should look at the docs for jQuery selectors: http://docs.jquery.com/Selectors/attributeStartsWith#attributevalue

Status: Fixed » Closed (fixed)

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