I've defined a like/dislike flag for certain comments in a site. I show the flag link manually in a special view, not in the comment template. Everything works fine but I'm having an issue: The flag link is also shown when previewing the comments (only when previewing the comments, not when they are finally published).

The wrong flag link appears in the link section of the comment:

<ul class="links inline">
    <li class="flag-like first last">
        <span>
            <span class="flag-wrapper flag-like flag-like-">
                <a href="/flag/unflag/like/?destination=comment/reply/15/150&amp;token=EOG4SfsupPtX3wKSUpeB48ddiPO_Xcq-x9Unxhh6WZY" title="" class="flag unflag-action flag-link-toggle" rel="nofollow">Ya no me gusta</a>
                <span class="flag-throbber">&nbsp;</span>
            </span>
        </span>
    </li>
</ul>	

I know I can hide it using CSS but it looks like a bug for me.

Regards.

Comments

melissavdh’s picture

I too am seeing this issue. The flag is set to appear by default on nodes of a certain type. The flag is appearing when I preview a comment on a node of a different content type. I have checked the settings of the flag and there is nothing there that indicates this node will show the flag for the comment preview. Intriguingly the flag is not showing on the comments for the node, just on a comment when it is previewed.

I am using Drupal 7.15 and Flag 7.x-2.0-beta7.

joachim’s picture

Status: Active » Postponed (maintainer needs more info)

These doesn't sound like they're the same issue, as the original post is about a comment flag, and the 1st comment makes it sound like it's to do with a node flag.

@melissavdh: if that's the case, please could you file a new issue?

@NoRandom: I can't reproduce your problem. I have disabled the 'Display link under comment' option and the comment flag does not show on preview for me.

Please could you check you have disabled that?

NoRandom’s picture

Thanks, joachim, it worked but now it seems more a bug to me, let me explain:

As you said, deactivating "Display link under comment" worked. The problem is I was seeing the "like" link for a content type wich had the like flag deactivated in "Bundles" section.

Regards.

joachim’s picture

Title: unwanted flag shown in comment preview » comment preview shows all comment flags regardless of subtype settings
Version: 7.x-2.0 » 7.x-3.x-dev
Status: Postponed (maintainer needs more info) » Active

> The problem is I was seeing the "like" link for a content type wich had the like flag deactivated in "Bundles" section.

Ok, that's a bug I can see too.

joachim’s picture

Title: comment preview shows all comment flags regardless of subtype settings » node and comment preview shows flags not assigned to their particular bundle

Ok this is a problem that nodes have too -- and I'm surprised it's not been reported before!

The problem is that flag->access() only does the check on flag applicability if there is an entity ID. With an entity in preview before it is properly created, the ID is NULL.

And while we have type_access() precisely to deal with special cases, the whole of the access() system deals with IDs, so once we're inside it, we've no way of getting the entity that's being previewed.

The only thing I can envisage at the moment is:

a) replumb access() to take either an entity or an entity ID, which is going to be messy
b) disable flags on previews

I'm leaning towards b) right now, at least as a stopgap to get us to launch 3.0.

joachim’s picture

On second thoughts, we should be able to fix this by storing the previewed entity in the flag's internal object cache, which applies_to_entity_id() looks in.

alexweber’s picture

My personal opinion: disabling flags on previews seems like a much cleaner and simpler way to handle this particular error. I can't see any good reason why we'd want to be able to flag entity previews...

joachim’s picture

This is fixed by using $flag->remember_entity with a dummy entity id, so it's a fairly simple fix.

You can't flag entity previews, but the idea is to show you the entity as it would look like, including the flag links that would be rendered on it.

Should wait till after #1871426: Ability to add flag links to any view mode is in for a patch, as they will likely clash (and that one in turn is waiting until I don't have flu any more...)

alexweber’s picture

@joachim gotcha, get well soon! :)

joachim’s picture

Status: Active » Fixed
StatusFileSize
new2.02 KB

Here's the patch.

It's a bit of a faffy fix, as we're doing the same thing in 3 places: the entity form, the entity links, and now the pseudofield link.

As a follow-up, it might be nice to refactor the entity link and pseudofield link to both use flag_create_link().

Issue #1892372 by joachim: Fixed node and comment preview showing flags not assigned to their particular bundle.

Status: Fixed » Closed (fixed)

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