Forgive me if this is a dup, but a search didn't turn up anything. I am a 2.x user right now, but I am not seeing this in 3.x either. Close if I am wrong.
Right now, you can configure the ability to show the flag links on teasers and on node pages (view mode == 'full' is probably more accurate description).
If you are using Entity View Modes, or are implementing a hook_entity_info_alter(), you can't use the UI to configure what view modes get the flag links.
Ideally, the flag options form should use entity_get_info() to get all of the view modes for the entity type in question, and build the form from there. flag_link() and flag_entity_view() (and probably a few other places) would then need to be adjusted accordingly.
In the short term, I would love to figure out the best method for adding flag links to my non-standard view modes.
Comment | File | Size | Author |
---|---|---|---|
#50 | Selection_001.png | 115.43 KB | chrisjlee |
#50 | Selection_002.png | 67.42 KB | chrisjlee |
#50 | Selection_003.png | 58.62 KB | chrisjlee |
#47 | interdiff.txt | 2.34 KB | chrisjlee |
#47 | 1871426-add-flag-links-to-any-view-mode-47.patch | 16.25 KB | chrisjlee |
Comments
Comment #1
joachim CreditAttribution: joachim commentedSeems like a reasonable feature to add, and your suggested implementation sounds like the way to do it. If you were able to work on this that would be great!
There are a few complications from the fact that for nodes, the view modes are currently hardcoded as separate properties:
It should be simple to change that UI to a single checkbox and then a dependent set of checkboxes for the view modes. This should be done in the parent class where there's already 'show_on_entity'. The node-specific checkboxes in flag_node can then be removed.
However, we have the problem of converting people's existing flags to their settings are preserved. That's going mean adding to FlagUpdate_2 to handle this. It'll also mean that anyone running on 3.0 alphas will lose their current show_on_teaser/show_on_node setting, which is a shame, but I guess that's what alpha releases entail...
Comment #2
mpdonadioYeah, I would have submitted a patch, but the UI threw me a bit.
The actual mechanics of handling the additional view modes should be easy; all of that is isolated fairly well in the code.
I'm thinking that those two options could be kept as is to preserve backward compatibility, and then the options for the non-standard view modes could be kept in their own options (maybe a single serialized one). Still not totally sure about the best way to handle it.
I'll try to submit a patch in the next few weeks.
Comment #3
joachim CreditAttribution: joachim commented> the options for the non-standard view modes could be kept in their own options (maybe a single serialized one).
All the flag configuration options are serialized anyway. Once you define them in options(), saving them to the flag config is taken care of for you, as is unpacking them when the flag object is loaded from the DB.
> those two options could be kept as is to preserve backward compatibility
That's not really the Drupal way... :)
Better to break compatibility for a clean system that keep lots of legacy junk.
We currently have 300-odd users of the 3.x branch, which is not that many in the grand scheme of things.
Comment #4
joachim CreditAttribution: joachim commented> I'll try to submit a patch in the next few weeks.
Looking forward to it!
Feel free to ask any questions if you get stuck on anything :)
Comment #5
joachim CreditAttribution: joachim commentedTagging and upping priority. Let's make this a release blocker, as we need it in before release if it's getting in this time round!
Comment #6
joachim CreditAttribution: joachim commentedFolding #1793756: rename uses_hook_link() into this.
Comment #7
alexweber CreditAttribution: alexweber commentedPatch attached that does what joachim proposed in #1:
Caveat: Tests fail because of an unrelated error:
Update: Apparently the tests pass without this patch, will look into it.
I've tested this quickly with nodes and profile2 profiles and it works as expected. Either way I think its a solid start! :)
Comment #9
alexweber CreditAttribution: alexweber commentedUpdated patch that fixes one of the 2 failing tests (still throws a notice) but the other still crashes and burns.
I'm going to need some help on this... I believe that the error has to do with how we're checking for properties in the saved flag object. Using debug() I found that the properties are actually set properly in the flag but checking $flag->$property doesn't work. This is likely due to how the flag view mode settings are stored (as an array) but then again I could be wrong.
Can someone advise or take it from here?
Thanks! :)
Comment #11
joachim CreditAttribution: joachim commentedThe $edit array that gets posted to the admin form is then massaged into data that can be compared with the saved flag:
Hence these bits:
become a proper array:
You'll need to do the same to 'show_on_view_modes'.
We'll also need code adding to the FlagUpdate_3 class, to convert the various old properties to the new ones.
Also, I am now wondering if we need the 'show_on_entity' property as well as 'show_on_view_modes'? It seems redundant to me -- what happens if you select 'show_on_entity' and no view modes?
Comment #12
alexweber CreditAttribution: alexweber commented@joachim, you are right regarding the last part about show on entity but not on view modes, maybe we can just have it as a dummy checkbox in the UI to show/hide the view mode options or better still we could just get rid of it entirely. please advise!
Thanks for the help with the tests, now I see it :)
Did the rest look ok?
Hopefully I'll be able to roll a new patch in a couple hours.
Comment #13
alexweber CreditAttribution: alexweber commentedTaking the liberty since I'm knee-deep in this. if its not ok just unassign. New patch should be ready in a couple hours max.
Comment #14
alexweber CreditAttribution: alexweber commentedOk, as per #11:
Note: I think its kinda confusing that we have a separate "show_on_profile" setting and behavior for user flags because the user can now chose between that one and the new per view mode "Show on User account view mode".
Regardless the patch works and tests should pass :)
Comment #15
joachim CreditAttribution: joachim commentedHmm I've been pondering about whether we need the 'show on entity' or not, as it occurred to me that on single-view mode entities (eg user) it'll look silly otherwise.
However, I think this is solved by making the view modes options a group of checkboxes like this:
Another thing I think should be changed is the property name 'show_on_view_modes'. I'd rather this was 'show_in_links'.
Other than that, I think this looks good.
Comment #16
joachim CreditAttribution: joachim commentedComment #17
alexweber CreditAttribution: alexweber commentedDone! :)
Comment #18
joachim CreditAttribution: joachim commentedI've just realized this needs a hook_update_N() to convert flags stored in the database. Sorry, should have realized sooner!
Comment #19
alexweber CreditAttribution: alexweber commentedhmm good catch, I assumed that's what the FlagUpdate_3 bit was for, ok ill try to do this asap!
Comment #20
alexweber CreditAttribution: alexweber commented@joachim,
Ok, I finally got around to this! :)
Apologies for taking a couple days to get around to this and fingers crossed for the testbot! :)
Comment #21
joachim CreditAttribution: joachim commentedSorry, that's not going to work... parts of FlagUpdate_3 have already been run on database flags at this point.
You do raise an interesting way of doing this in future, though! Although what's been happening on 3.x development is that each change to flag object structure has required a new hook_update_N() and a tweak to the FlagUpdate class, so they've not been in sync at all. It's not a very elegant system, but there's not much point in improving it, as I presume D8's config system will take care of all that.
The current logic is that the link is shown on all view modes. So the most correct update procedure would be to enable it for all view modes.
There's no need for special handling, as entity_get_into() gives us all view modes for any entity.
Comment #22
alexweber CreditAttribution: alexweber commented> Sorry, that's not going to work... parts of FlagUpdate_3 have already been run on database flags at this point.
Hmm, I see, so do I just duplicate the logic there in the update hook?
> You do raise an interesting way of doing this in future, though!
Hah, that's what I thought that was class was there for...
Comment #23
alexweber CreditAttribution: alexweber commented@joachim, can you please elaborate so I can get this done! :) Thanks!
Comment #24
joachim CreditAttribution: joachim commented> Hmm, I see, so do I just duplicate the logic there in the update hook?
Yup, pretty much.
Load all flags, go through them all, tweak the properties structure, save each flag again.
Comment #25
alexweber CreditAttribution: alexweber commentedDone deal, thanks! Will get to this in a few hours hopefully!
Comment #26
alexweber CreditAttribution: alexweber commentedOk, new patch does 2 things:
Hopefully this should be good to go! :)
Comment #27
joachim CreditAttribution: joachim commentedHmm I had a flag I was pretty sure was set to show on nodes for full and teaser, but after running the update 'Display on Full content view mode' wasn't enabled.
I'll wipe by database and have another go at it tomorrow.
Comment #28
alexweber CreditAttribution: alexweber commentedsounds good, I'm pretty sure it works here :)
Comment #29
joachim CreditAttribution: joachim commentedThe 'page' view mode for nodes is actually called 'full', same as other entities. This is what wasn't working in my update.
This is actually causing extra view modes to lose the flag. In my case, the view mode provided by Diff module, which is possibly undesirable anyway, but other modules might provide view modes we don't know about - DS, for instance.
Could you check these are right in the update class as well please? (It's a pain to have to have it in two places, I know :( -- should all go away for D8!)
Comment #30
alexweber CreditAttribution: alexweber commented> This is actually causing extra view modes to lose the flag. In my case, the view mode provided by Diff module, which is possibly undesirable anyway, but other modules might provide view modes we don't know about - DS, for instance.
I'm not sure what you mean here? What did you want me to do with the show_on_comment block? Get rid of it?
Comment #31
joachim CreditAttribution: joachim commentedIt needs the same processing as show_on_entity, so probably lump it in:
Comment #32
alexweber CreditAttribution: alexweber commentedDone, fixed in .install and copied changes over the the update class.
Comment #33
joachim CreditAttribution: joachim commentedStill doesn't work.
Try chucking this at the end of flag_form():
The problem the use of isset(). These should be !empty, as the flag object's options() sets the property to FALSE if it's not set when loading the flag.
Comment #34
joachim CreditAttribution: joachim commentedHi alexweber!
Do you still have time to work on this to get it ready, or should I unassign you? I think it's nearly there! :)
Comment #35
alexweber CreditAttribution: alexweber commentedHi joachim, sorry I've been kinda busy lately. I'll work on this the next few days, thanks!
Comment #36
alexweber CreditAttribution: alexweber commented@joachim, I'm sorry after like a billion patches it doesn't look like I'm going to be able to drive this one home due to a severe lack of time. Apologies for the hold up...
Comment #37
joachim CreditAttribution: joachim commentedNo problem.
You've done a ton of work on this one and lots of other issues on flag too -- thank you very much for all your help!
Comment #38
alexweber CreditAttribution: alexweber commentedMy pleasure! :)
Comment #39
socketwench CreditAttribution: socketwench commentedSo what *does* need to be done? My manual testing has revealed no issues...
Comment #40
joachim CreditAttribution: joachim commentedSee #33.
Comment #41
socketwench CreditAttribution: socketwench commentedComment #42
joachim CreditAttribution: joachim commentedI think you've misunderstood that comment!
#33 is debug code that shows the problem. The actual problem is explained at the end of that comment:
> The problem the use of isset(). These should be !empty, as the flag object's options() sets the property to FALSE if it's not set when loading the flag.
Those need changing in 2 places: the hook_update_N(), and the flag export converter.
Comment #43
chrisjlee CreditAttribution: chrisjlee commented@joachim:
Which is currently the working patch? #32?
Comment #44
joachim CreditAttribution: joachim commentedYup. Ignore #41. #32 needs just a little bit of extra work.
Comment #45
chrisjlee CreditAttribution: chrisjlee commentedGoing to do babysteps as per feedback suggested in #33.
Hoping for feedback please. Would this be the right direction ?
Comment #46
joachim CreditAttribution: joachim commentedThat looks right. The same change needs to be made in the update class, FlagUpdate_3.
Thanks for tackling this! :)
Comment #47
chrisjlee CreditAttribution: chrisjlee commented@Joachim: No problem. Thanks for the quick and clear feedback. I think this should take care of the other changes as you requested.
Let's see if testbot likes it.
Also, that should be it as a grep shows no results:
$ grep -nr --exclude='interdiff.txt' 'isset(\$flag->show_on' .
Comment #48
chrisjlee CreditAttribution: chrisjlee commentedPatch seems to work on the settings form. But i must be missing something I can't figure out how to add flag markers fields on the different view modes.
Comment #49
joachim CreditAttribution: joachim commentedYou should have a set of checkboxes for the view modes on your flag settings form, IIRC.
Comment #50
chrisjlee CreditAttribution: chrisjlee commentedI thought i did check that box and enabled those settings you speak of.
I spawned a simplytest.me instance with this patch. You can see the screenshots and details of my findings:
I created a flag added a field to the flag (a boolean) and checked and enabled all the view modes (because one is not enough :) )
This allowed me to enable flags on the field page
However, there is flag on the view mode :(
Comment #51
joachim CreditAttribution: joachim commentedThis patch is still keeping all the flags output in the entity links.
If you want flag output as pseudofields so you can order them on the field admin UI, there's a follow-up issue for that!
Comment #52
chrisjlee CreditAttribution: chrisjlee commented@joachim: Ah I see. Thanks. Well then the patch works perfectly.
Found the followup issue: #1892930: Placement of flag links as pseudofields
Comment #52.0
chrisjlee CreditAttribution: chrisjlee commentedUpdated issue summary.
Comment #53
joachim CreditAttribution: joachim commentedI've tested the upgrade path with flags on:
- node full page only
- node teaser only
- node both full page and teaser
- comment
All settings upgrade as expected.
Committed and pushed. Thanks to everyone who's helped with this, and especially huge huge thanks to alexweber for the tremendous amount of work he did on this patch!
git commit -m "Issue #1871426 by alexweber, chrisjlee: Added ability to set display of flag links on specific view modes." --author="alexweber "
Comment #54
joachim CreditAttribution: joachim commentedChanged record filed: http://drupal.org/node/1990790
Comment #56
alexweber CreditAttribution: alexweber commented@joachim I only just saw this, awesome! Thanks for the props and glad the patch made it in!!
Comment #56.0
alexweber CreditAttribution: alexweber commentedUpdated issue summary.