In trying to integrate nodewords (which adds HTML META tags to node, and preferable to each page), I'm stumbling on the following problem:

In hook_form_alter() I can add my META tags form to the panel creation/editing form. There I also add an extra #submit handler to save the META tags connected to that panel. The problem is that when a new panel is created, my extra #submit handler has no easy access to the did of newly created panel. This is because in panels_save_panels() you do a db_next_id(), but this new did is not saved in $form_values so my handler can use it.

There are a number of solutions to this, one prettier then the other (or should I say uglier).

1. In my nodewords handler I could do a SELECT max(did) FROM {panels_info}. This is inherintly a race condition waiting to happen.

2. In my nodewords handler I could do a SELECT did FROM {panels_info} WHERE path = '%s' (I do receive the path of the newly created panel). This will fail if there are two panels with the same path (I don't know if panels.module allows that).

3. As a combination of the two, I could do a SELECT did FROM {panels_info} WHERE path = '%s' ORDER BY did DESC LIMIT 1.

4. It would however be cleaner if panels would save the did of a newly created panel in $form_values. Although a bit of a hack, this is possible with:

...
$panels->did = db_next_id("{panels_info_id}");
global $form_values;
$form_values['did'] = $panels->did;
...

5. Converting panels into nodes by themselves also solves the problem as I can then use the well tested hook_nodeapi().

6. You could create a hook_panelsapi() similar to hook_nodeapi().

At the moment I'm thinking of just implementing 3 (which doesn't need a panels code change), but I don't feel too comfortable about it. If you have any thoughts about the subject, please let me know.

BTW: I have the same problem adding my META tags form elements to newly created views (of the views.module), so it is a more general FAPI problem for which probably solutions will be found, but not in 4.7 or 5.

BTW: I would love to see the avoid drupal_goto in a submit hook issue resolved too. This is needed if I want to keep track of panels that get deleted, so I can delete my assigned META tags.

CommentFileSizeAuthor
#3 panels.nodewords.patch.txt1.14 KBRobrecht Jacques

Comments

merlinofchaos’s picture

Aye, I saw it and I'll take care of that.

For this, I am willing to set the value. However, we can use form_set_value() rather than touching global $form_values, I believe.

If you submit a patch you've tested, I'll probably be able to get this in more quickly for you.

Robrecht Jacques’s picture

Great!

I'll submit a patch tomorrow (while finalising the support in nodewords). Using form_set_value() if possible, but I thought that one could only use that function in the validate handlers, not in the submit handlers. I'll check and test.

Robrecht Jacques’s picture

Status: Active » Needs review
StatusFileSize
new1.14 KB

Attached patch implements the needed functionality to be able to attach META tags to the panels edit form. This includes the avoid drupal_goto in a submit hook patch.

I don't set it to "patch (ready to be committed)" because I think another tester would be great, but I believe it works and has no side-effects.

Robrecht Jacques’s picture

BTW: I couldn't get it to work with form_set_value as I don't have access to the $form in a form-#submit handler, only to $form_values.

merlinofchaos’s picture

Status: Needs review » Fixed

Committed. Will go out in today's 1.1 release.

Anonymous’s picture

Status: Fixed » Closed (fixed)