The D8 version lets you create a view of flaggings, which is especially useful now that they're fieldable. Ideally you'd be able to create a relationship back to the flagged entity.
| Comment | File | Size | Author |
|---|---|---|---|
| #76 | 2723703-76.patch | 1.42 KB | tbsiqueira |
| #73 | 2723703-73.patch | 1.45 KB | kimberleycgm |
| #72 | 2723703-72.patch | 19.52 KB | kimberleycgm |
| #72 | interdiff-2723703-66-72.diff | 4.51 KB | kimberleycgm |
| #66 | 2723703-66.patch | 21.09 KB | martin107 |
Issue fork flag-2723703
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 5.x
changes, plain diff MR !165
- 2723703-add-relationship-to
changes, plain diff MR !90
Comments
Comment #2
ksenzeeThis is basically a copy of the way comment module makes its relationships available. There's a TODO in the patch about whether we should only create relationships for entities that currently have flags. If we leave it as is, there are a lot of relationships in the UI, most of which might well be pointless. But if we only create relationships for entities with flags, you'll have to clear the views cache before you can add a relationship for a flag on a new entity. I'm also no Views API expert so if I'm doing it all wrong feel free to tell me so.
Comment #3
berdirEach flag type has a specific target entity type. If you just switch to loop over flag types and get their entity type ID (and check if you haven't already defined that, as there are possibly multiple flag types with the same entity type) then you should only get those that matter.
And AFAIK, we already clear the views cache when changing flag types, so that should work too.
Comment #4
joachim commented> If you just switch to loop over flag types and get their entity type ID (and check if you haven't already defined that, as there are possibly multiple flag types with the same entity type) then you should only get those that matter.
Yup.
Also, the relationship handler should let you filter on the actual flag, the same way that the Flaggable -> Flagging relationship does.
Comment #5
chx commentedThat's a good start however joining a string and an int is affront to all scalability gods whether comment does it or not.
Comment #7
chx commentedBother!
Comment #8
berdirSee node_update_8001() for an example on how to add a new base field.
Comment #9
joachim commentedWhy do we need two entity ID fields?
Comment #10
jibran@chx and @ksenzee we don't need new basefield at all we have all the data we need in
{flagging}table. I'll take look at it later tonight or during this weekend if it's not that urgent. I was trying to achieve that in https://github.com/socketwench/flag-drupal8/pull/127/files until we moved to d.o in #2410011: add a views_data handler and changed the scope of the issue.This will be more less like DER base field views integration #2548395: Provide views relationships for DER base fields. We even have core ready for this #2378729: JoinPluginBase doesn't allow extra conditions on left table. ;-)
Comment #11
chx commentedEdit: deleted. This patch is too complex. A simpler one is posted below.
Comment #12
joachim commentedReally don't want this. Either we have the join as it is, or we convert the field to int (and then don't allow config entities to be flagged). I prefer the latter option.
Comment #13
chx commentedEdit: deleted.
Comment #14
chx commentedEdit: deleted.
Comment #15
chx commentedBut if you really dislike this solution I can regress to what comment does and just join a string to an int.
Comment #16
joachim commented> Determines if an entity type is using an integer-based ID definition.
Arrrgh!
> But if you really dislike this solution I can regress to what comment does and just join a string to an int.
If it's good enough for core! And comment will encounter scalability issues long before flag does. So hopefully code can clean up its mess in due course.
EDIT: errrrm this comment just looks really weird now :/
Comment #17
chx commentedEdit: deleted.
Comment #18
chx commentedEdit: deleted.
Comment #19
chx commentedThis is the minimal patch. It's enough for now.
Comment #20
chx commentedActually, this is better.
Comment #21
jibranWe can add a reverse relationship as well.
Comment #22
chx commentedThat is already done in
flag_views_data_alter. I found a bug, however: extra needs to be flag id and not entity type.Comment #23
socketwench commentedComment #24
chx commentedUUuuuuuuh needs tests. Yes. It does :P If someone gets to this, don't forget to assign yourself. I will do when I get to writing a test for this.
Comment #25
socketwench commentedDouble period here.
Comment #26
socketwench commentedComment #27
socketwench commentedWIP patch.
Comment #28
socketwench commentedComment #29
socketwench commentedAdded flagging view with content relationship and test.
Comment #30
socketwench commentedRemoved the extra period.
Comment #31
martin107 commentedFixed a couple of trivial nits.
Comment #32
joachim commentedMistake in the title surely?
Comment #33
joachim commentedNo need to specify NULL here.
This is sound, but it is more limiting than providing one relationship per flaggable entity type.
I can imagine a site builder making a list of flaggings, and having several node flags, and wanting to include node data for both those flags.
With one relationship per flag, the node fields are then separate per flag. They'd need to faff with theming or field rewrites to collate them.
Comment #34
joachim commentedComment #35
chx commentedFor 2., while we have "like" flags and "subscription" flags you are right that filtering on the flag_id can make that happen but the other way around it can't so yes it needs to be per entity type.
For 1., yes you need to specify NULL here, check the doxygen:
Comment #36
joachim commented> An array of entity IDs, or NULL to load all entities.
Yes, but IIRC the NULL is the default value for the optional parameter.
Comment #37
chx commentedAh, you are right, of course.
public static function loadMultiple(array $ids = NULL);.Comment #38
dunebl#31 apply with one warning
Comment #39
zenimagine commented#31 work for me
Comment #40
joachim commented#31 needs work, as detailed in #33.
Comment #41
zenimagine commented1) The flag link does not work with the patch.
2) There are no "flag type" filtering criteria.
Comment #42
joachim commented> 1) The flag link does not work with the patch.
Can you explain in what way? Isn't it just that the flag link field expects to be on a flaggable entity type base table and doesn't work on flagging base table? IIRC there is a bug open for that.
> 2) There are no "flag type" filtering criteria.
I wouldn't have thought that is needed. Can you explain the use case please?
Comment #43
zenimagine commented1) If I add in the fields of my view the field "Link of the flag" or "Link to delete Flagging", the link does not appear.
2) I have several flag:
- favorite flag.
- report flag .
- follow flag.
I created a flag view to display the reported entity.
This view displays all flagged entities. While I wish to have only flag type report.
Comment #44
joachim commented> 1) If I add in the fields of my view the field "Link of the flag" or "Link to delete Flagging", the link does not appear.
Right, as I say, those are incorrectly implemented as they make assumptions about the base tables they are on. That shouldn't hold up this patch.
> I created a flag view to display the reported entity.
Ok so you need to add a filter for the flag type to the view as a whole. Doesn't that exist?
Comment #45
zenimagine commented1) Thank you, but the answer is too technical for me.
2) There is no filter for the flag type.
The patch does not work with the latest dev. Here is the messsage in "composer" :
Comment #46
zenimagine commented1) On my screenshot, users have flagged (with a personal flag) the content "my". How can I, as administrator, remove the personal flags (without resetting the flag type) ?
2) Sorry, it works as expected. I added "type flag" when using "Report content".
3) When a comment is flagged, if I click on the title of the comment it displays the parent node. How to go directly on the comment ?
Comment #47
joachim commented> The patch does not work with the latest dev. Here is the messsage in "composer" :
I'm afraid I'm not going to support use of composer with Flag -- I have enough problems of my own getting composer to work.
> 1) On my screenshot, users have flagged (with a personal flag) the content "my". How can I, as administrator, remove the personal flags (without resetting the flag type) ?
I don't understand the question and how it relates to the screenshot, and that's more of a support request rather than work on this issue.
> 3) When a comment is flagged, if I click on the title of the comment it displays the parent node. How to go directly on the comment ?
No idea. That's to do with Views and Comment modules, not Flag.
Please don't use issues that are about getting work done on Flag into support requests, thanks!
Comment #48
zenimagine commentedThe patch does not work if the field is an entity rendered.
TypeError: Argument 1 passed to Drupal\views\Plugin\views\field\RenderedEntity::getEntityTranslation() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in /home/www.domaine.com/public_html/web/core/modules/views/src/Plugin/views/field/RenderedEntity.php on line 108 inComment #49
zenimagine commentedComment #50
zenimagine commentedwould you have an idea of what would create the problem ?
Comment #51
zenimagine commentedI created flags:
- Follow the group
- Follow the shop
And a subscriptions view.
This view lists all the entities to which the user has subscribed.
I encounter two problem with this view:
- the user does not see the type of flag (only the administrator can see).
- can not display the group name.
Comment #52
joachim commented> Please don't use issues that are about getting work done on Flag into support requests, thanks!
Comment #53
zenimagine commentedMy problem is with this question, because I applied the patch to get a relationship with the groups in my view.
Comment #54
joachim commentedRight, but posting screenshots of your own specific case doens't help with fixing the problem. Particularly when they're in a different language (I happen to speak French fluently, but I can't figure out what those fields in your screenshot are, because I am not familiar with the translations of the English names of the various Views fields).
If you want to help, get a dev site set up, try to reproduce the problem in the simplest way possible. Then debug and report your findings.
Comment #55
zenimagine commentedI applied patch #22
The problem is that it creates several identical relationship.
As in the screenshot.
Comment #56
zenimagine commentedDo you have a patch for adding this feature to the dev version? Thank you
Comment #57
zenimagine commentedComment #58
smokrisHere's an attempt to address the issues mentioned in #33.
Comment #59
smokrisRe-added the tests from #31. And fixed a couple code style issues.
Comment #60
g089h515r806 commented#59 patch works correctly.
Comment #61
g089h515r806 commentedThis is a very useful feature. change priority to major.
Comment #62
oriol_e9gTests has 1 fail.
Comment #63
martin107 commentedA) I think the new test needs converting to a functional test
If only to move the test from the
Drupal\flag\Tests
namespace into
Drupal\Tests\flag\Functional
B) phpcs --standard=Drupal src/Tests/FlaggingViewTest.php
raises a few minor problems.
Comment #64
martin107 commentedchanges as described in #63
Comment #65
martin107 commentedI will clean up the phpcs error in the morning
Comment #66
martin107 commentedIn Drupal8 all the required definitions to generate a new module is in the *.info.yml
Empty *.module files are redundant.
In terms of review from me.
like other comments above .. I can also confirm that the new view in visible and has survived my attempts to break it
The modernised tests look like they contain all the assertions needed to function as a early warning system.
so I think this is ready. . and will be a welcome addition to the project.
Comment #67
g089h515r806 commented2723703-66.patch works well.
Comment #68
joachim commentedIsn't this available injected already?
There is a method on EntityViewsData that gets this IIRC.
That seems.... weird.
Also, see my comments in #33.
Comment #69
akshitggrwl commentedIn the latest patch, the relationship for bundable entities for each bundle type.
The table value for type field in extra sections is hard coded to 'node_field_data', which results in error for non node entity types. It should be something like 'table' => $base . '_flagging',
Comment #70
berdirAgreed, this doesn't seem ready.
Comment #71
dgaspara commented#66 Also works for me. Thanks!
Comment #72
kimberleycgmI've implemented the suggestions #33 and #68:
- adding the relationship per entity type, rather than per flag
- reusing the injected service
- using the \Drupal\views\EntityViewsData::getViewsTableForEntityType method
- removed the per-bundle relationship
Still in testing my side but seems to be working well so far. Have tested with a flagging view displaying multiple node type and comment type flaggings, and the fields are pulling through as expected.
@todo:
- more testing
- update the tests in the patch (haven't got round to this yet)
Comment #73
kimberleycgmFixed issue with previous patch where the relationship didn't know which entity type was correct. Removed the tests for now as they're no longer valid until updated.
Comment #74
ptmkenny commentedComment #75
b_sharpe commented#73 works great
Comment #76
tbsiqueiraWe (Open Social) were originally using patch #31, because we will not update to the new patch, for now, I'm re-rolling patch #31 without tests, this way it will be a valid patch for D9.
Comment #77
aharown07 commented73 vs 76 (formerly 31): Looks like there are a couple of different patches here and it's not clear to me what the merits of one vs. the other are, just looking at #73 and #76. Recommendations?
Edit: looks like 73... am I right?
Comment #78
tbsiqueiraHi @aharown07, yes you are right, as of now patch #73 is the most updated one, I only re-rolled version #31 because I wanted to keep the same code as before, but I needed to remove the tests.
Comment #79
chucksimply commented#73 works great on Drupal 9.5.10.
Comment #81
very_random_man commentedPatch in #73 works well for D10.2.
Comment #82
ivnishNeeds reroll to MR, needs tests how it works
Comment #85
prem suthar commentedRe-rolled The Patch #73 with The MR. Please review
Comment #86
prem suthar commentedComment #87
ivnishStill needs tests
Comment #88
ivnishComment #90
deaom commentedCan't change the MR branch to 5.x so rebased to 8.x with updated tests that are passing. Needs review.
Comment #91
ivnishComment #96
ivnishThanks! Merged!