While working on #891708: Fix the vertical tab's summary I noticed we have an ungly hack, in flag_node::replace_tokens(), to make [node:type] and [node:title] tokens work for nodes that aren't yet saved (e.g. node/add/story). Why ugly? (1) it took me a while to figure out its purpose; (2) it's confusing to see a node-type passed instead of nid.

This patch gets rid of this hack. Although it doesn't make the code shorter (nor longer), I think it's worth it. Nate, if you don't think so, let's just close this issue.

Comments

joachim’s picture

Status: Needs review » Needs work
+++ flag.module
@@ -382,19 +382,25 @@ function flag_field_extra_fields() {
-          '#title' => $flag->get_label('flag_short', $form['#node_type']->type),
+          '#title' => $flag->get_label('flag_short', 'bogus'),

I don't understand much about the flag object's caching system at all, but I wonder: what happens here if there happens to be a node type on the system called 'bogus'?

joachim’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev

Upping the version.

joachim’s picture

Status: Needs work » Closed (won't fix)

On further reflection, it seems to me that this patch adds more workaround code than it removes, and while currently the hack code is in just one place where it seems fairly well documented, the workaround code the patch adds is scattered around.

Therefore, as (I assume) the current system works, I think I prefer it to the proposed change. Hence this is wontfix, sorry.

joachim’s picture

Status: Closed (won't fix) » Needs work

Reopening this, as it affects #1784402: fold handling of node forms into hook_field_attach_form(), remove hook_form_alter() for node forms.

It seems to me that we could get rid of this entirely. On D7, a node form actually has a proto-node in $form['#node'] which presumably can be used for tokens. So we could pass that rather than fake up our own node object.

The only hurdle is that the whole get_label() system works on entity IDs rather than entities...

joachim’s picture

Ok now having read the patch AGAIN, I finally see what it's getting at.

Changing get_label() so it passes around full entities is going to be a major piece of work, and also it's going to run into all sorts of trouble in places where we don't have the full entity, such as Views.

Therefore this setting of fake or new entities into the flag cache is the best thing to do.

joachim’s picture

Status: Needs work » Needs review
StatusFileSize
new3.24 KB

Updated patch for D7.

It turns out now we have a flag_entity class, we don't need any special token handling for node at all.

joachim’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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