Closed (fixed)
Project:
Flag
Version:
7.x-3.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
20 Oct 2011 at 14:59 UTC
Updated:
17 Oct 2013 at 21:53 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
miklThis patch needs to be updated work with the latest versions of flag.
Comment #2
joachim commentedThis looks like it should be done in hook_entity_property_info_alter(), as we're changing the properties of existing entities, not adding out own.
Comment #3
joachim commentedAlso, hook_entity_property_info()/alter() go in a .inc file -- see entity API.
Comment #4
joachim commentedTagging.
Comment #5
mh86 commentedRe-rolled patch for 3.x branch, fixing
Both properties use custom queries, as I couldn't find appropriate API functions that do the same in an efficient way. Maybe I've just missed them, or they might be a useful addition.
Comment #6
mh86 commentedoh, forgot about the separate .inc file...
Comment #7
mh86 commentedMoved the hook implementation and getter callbacks to flag.info.inc. Unfortunately the Entity API only includes this inc file for the property hook and not for the getter callbacks, thus I added a require_once to flag.module file.
Are there any other properties that would make sense?
Comment #8
joachim commentedIsn't there a Drupal API function for that?
Comment #9
mh86 commentedThere is one (module_load_include), but it makes a lot of unnecessary function calls for just including your own file.
Comment #10
joachim commentedI really don't like automatic requires/includes. They negate the whole point of having separate files.
Could we just have the getters in the .module file then?
Also could their docblocks look like:
* Entity metadata callback: returns the current user's shopping cart order.
Comment #11
joachim commentedComment #12
joachim commentedA few more things I've noticed:
I'd really like some commenting above each of the things we put into the $info array.
That's really ugly. If we're going to need this parameter juggling then I don't see the point of this helper function -- let's just fold it into the caller.
This will sort of work for global flags, but ideally I'd like a boolean for those.
Comment #13
grasmash commented@joachim
I'll work on an updated version of the patch, with your suggestions included, and flag count snippet from #1634620: Flag module integration?.
Comment #14
grasmash commentedI haven't actually used global flags, but my understanding that it adds a boolean flag to a node or user. So, there is no flag count for global flags-- it's just TRUE or FALSE, right?
I can modify the entities appropriately with a boolean property. Should we also add a property to specify WHO flagged the content?
Comment #15
grasmash commentedGiven that I'm currently using Flag 7.x-2.x, I'm going to start with a patch for that branch. Afterwards, I'll update the patch for 7.x-3.x, and submit it separately.
A number of changes:
'flag_' . $flag->name . '_flagged'under['user']['bundles']['user']['properties']for consistency.'flag_name' => $flag->name,with'data' => array('flag' => $flag),so that we can access all object properties.I'm just starting to test this, so I may post an update with bug fixes. For now, let me know if you disagree with any of the changes.
Comment #16
Scyther commentedStatus update
Comment #17
joachim commentedThis new patch doesn't seem like it's based on the earlier one, as we've lost a few things!
> I decided NOT to make a separate boolean property for global flags—it seems that the 'count' field will sufficiently handle global flags
Technically that's true, but I don't think it's good DX to have a property called foo_count that returns a boolean.
> Should we also add a property to specify WHO flagged the content?
That's not available for global flags.
This needs to be in an inc file like in the earlier patch.
$flag->types can be empty to mean the flag applies to all.
I was partway through a rework of the original patch myself, so I'll try to get round to finishing that this week.
Comment #18
grasmash commentedI can easily move new code into include file, and also create the boolean field. I'll test the boolean flags before the next submit. Are there any other necessary changes?
Comment #19
joachim commentedHere's my work in progress -- I was still at the stage of widening the scope of hook_entity_property_info_alter().
As I noted in my earlier comments, I'm not that keen on the helper function here, at least in its current form.
Comment #20
joachim commentedTagging as release blocker.
Comment #21
joachim commentedAssigning to myself; I have work in progress for this.
Comment #22
joachim commentedUpdated patch:
- moved the callbacks to the module file, as I don't like having to load a .inc file unconditionally
- change the getter callbacks to use our API rather than their own queries, as that way they benefit from caching
- removed the info helper, as I think it was just confusing to have that broken up into different functions. Creating the array then using it in several places works well though.
- finished boolean getter callback
Comment #23
joachim commentedCommitted.
Thanks everyone who worked on this :)
Comment #25
podarokuntag
Comment #26
gthing commentedPlaying with the latest patch and seeing some errors:
My thought was that if I installed this, then a search API view would have access to the flag that is attached to my content type. But I don't see a way to add the flag field or a relationship to the flag. Am I wrong or am I doing something wrong?
Comment #27
gthing commentedComment #28
joachim commented> Playing with the latest patch
What do you mean by the 'latest patch'? The patch above was committed ages ago; it's part of the code now.
> then a search API view would have access to the flag that is attached to my content type
I suspect that is out of the scope of this issue.
Comment #29
kenorb commentedIf you have any problems with the module, please raise the separate issue.
Comment #30
user654 commented.
Comment #31
joachim commentedYou may want #1362298: Independent views query backend flag links.