Closed (fixed)
Project:
Flag
Version:
8.x-4.x-dev
Component:
Flag core
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
27 Jan 2016 at 10:02 UTC
Updated:
20 Feb 2016 at 09:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
chx commentedThere's some minor generic cleanup added as well.
Comment #3
jibran+1 to this.
Can we add asserts for target_type and entity properties as well?
Comment #4
chx commentedMost certainly we can!
Comment #5
chx commentedWrong patch, not enough asserts.
Comment #6
jibranPerfect thanks @chx
Comment #7
chx commentedAnd a very subtle bug fixed -- it is extremely unlikely this will ever come up: if the entity_id is removed then flagged_entity wasn't removed.
Comment #8
chx commentedComment #9
jibranNice. Still RTBC.
Comment #10
joachim commentedThanks for working on this.
dynamic_entity_reference looks like it might be viable at some point in the future. My concern with it previously was the support for Views, but that looks like it might be ok now. Though we probably don't want to be adding a dependency on a module that's not yet stable, so waiting till it lands in core seems best.
Not sure what this change is for.
Not sure what this change is for.
Could be worded a bit more clearly -- see other parts of the code such as docblocks for examples.
I'm not sure there's any point in doing this. A flagging applies to one entity only. The only way it can stop applying to that entity is when it is deleted when the entity is unflagged.
The entity_id property will always be a single ID. Choice of variable name seems odd here.
The entity_id property can't ever be empty.
Could we have some comments to explain what's being tested here please?
Comment #11
chx commented1. Simplifying
2. EntityManager is deprecated
3. I will see what I can do
4. It's the standard way of doing things. There's nothing in the codebase to move a flagging to a different entity. Yes it makes no sense but it does work code wise.
5. Well, it IS an item list, always. That's just how things are. One long or not, it's always an item list.
6. In a normal course of things, no
7. Sure, I will add a comment
In general, just because the module doesn't do certain things, nothing stops the entity treated as a generic entity and who knows what might happen. Better to be fully coded, there isn't a lot to it.
Comment #12
joachim commented1. See #2461673: replace FlagService::getFlagById() with Flag::load() where I proposed changing this across the whole module, and #2461661: [meta] refactor and trim down FlagService for reasons I was given not to do that. You're welcome to argue the case for this on #2461661: [meta] refactor and trim down FlagService.
> 2. EntityManager is deprecated
Good point. Can this be fixed in a separate task please? I prefer to keep clean-up commits separate for a history that's easier to understand.
> 4. It's the standard way of doing things. There's nothing in the codebase to move a flagging to a different entity. Yes it makes no sense but it does work code wise.
Moving a flagging to a different entity is a violation of Flag's application logic. We don't provide code for it, and we don't support it. I don't want this code in, because:
a. developers may see it and think that we DO support that, and then write code to do that which breaks
b. developers may see it and think that we DO support that, but haven't completely implemented it, and file feature requests/bug reports requesting that we do.
c. future maintainers of flag will be confused why that code is there, when we don't support that
If you feel it's necessary to prevent future confusion, add a onChange() method which only calls the parent onChange() and has a comment to explain why we don't need to handle a change to a flagging entity's flagged entity.
Comment #13
chx commentedIf you remove the onChange then
will not work.
Comment #14
joachim commentedCode that calls Flagging::create() should be passing in the required values at that point:
We don't yet enforce this but we might -- see #2640944: Move flagging integrity checks from service to Flagging::save() and unflagging checks to a better place. which is related.
Comment #15
chx commentedVery small patch, with comments.
Comment #17
joachim commentedBy the way, do calculated fields not lazy-load (lazy-calculate) their value, the way they do with Entity API wrappers on d7?
Comment #18
chx commentedSo
_field_create_entity_from_idscreates an entity with just the ids and sets the rest after,onChangeis mandatory for the UI. Here's a simple solution: if you send in entity_id for the first time, we set flagging_entity to the entity_id . If you try to change either after, it will throw an exception on you.The constructor covers load and possible unit tests, the onChange method covers create + set after. We are golden.
Edit: The reason we need two code paths:
ContentEntityStorageBase::doCreatecalls the constructor with an empty array for$valuesso we need the isset check in the constructor. After this empty trick, it callsContentEntityStorageBase::initFieldValueswhich triggersonChange.SqlContentEntityStorage::mapFromStorageRecords(which is fired during load) calls the constructor with the values and does not callContentEntityStorageBase::initFieldValuesandonChangeis never triggered. I have no idea why but this is how it is.Comment #19
jibranThis is ready imo.
Comment can be removed.
Comment #20
chx commentedRemoved.
Comment #21
joachim commentedLooks good.
Just one thing -- I was reading up on setComputed(), and saw this:
Does that mean that we don't need to define this in both baseFieldDefinitions() and bundleFieldDefinitions()?
Comment #22
chx commentedThis is how core does it in Comment and I would rather not move from how core does it (we've seen above it's better to keep in line) and anyways it's simply nicer to see all the fields together.
Comment #24
joachim commentedFair enough. 'Follow core's pattern' is a principle I frequently follow as well :)
Committed. Thanks!