- Those constants are used for "field loading" logic. This used to be part of a public API (field_attach_load() & friend), but this logic is now internal to the storage controllers, and there is no external facing API for those operations.
So the storage controllers using those constants is fine, but external code referring to them feels like messing with something you're not supposed to know.
- Even within storage controllers: the rest of the entity loading code rather uses a boolean $load_revision flag, and "translates" it to one of the constants when doing "field stuff":
protected function attachLoad(&$queried_entities, $load_revision = FALSE) {
$this->loadFieldItems($queried_entities, $load_revision ? FIELD_LOAD_REVISION : FIELD_LOAD_CURRENT);
Looks like two different systems talking to each other - which *was* the case, but is now a bit absurd within one single class / class hierarchy.
Comment | File | Size | Author |
---|---|---|---|
#22 | get_rid_of_field_load-2081513-22.patch | 8.76 KB | andypost |
Comments
Comment #1
BerdirThe actual usage is internal.
I guess the problem are the places that happen to use it from the outside, like EFQ (should really be a different constant, as it has a different meaning), maybe use loadRevisions() instead of age(constant)?
Then there's views integration, no idea what that is exactly doing and that file reference stuff...
Comment #2
yched CreditAttribution: yched commentedviews integration is just about using some arbitrary key in the exposed views data. Current code uses the constants for some sort of consistency reason, but it could totally use its own arbitrary keys.
[edit: the constants actually don't even end up in the exposed data, they're just used as a way to structure the code that builds the data. Could totally use 'current' / 'revision' keys instead, this doesn't get out of field_views_field_default_views_data()]
Comment #3
swentel CreditAttribution: swentel commentedMarked #2029709: Convert FIELD_LOAD_CURRENT to a constant on some class/interface as a dupe of this.
Comment #3.0
swentel CreditAttribution: swentel commentedrephrase
Comment #4
andypostIs this issue valid? Constants are in
EntityStorageControllerInterface
Suppose it make sense to remove
FIELD_
prefixComment #6
andypost4: 2081513-4.patch queued for re-testing.
Comment #7
yched CreditAttribution: yched commentedSee the OP. The intent of the issue is rather to get rid of the constants entirely, and move to boolean $load_revision flags like the upstream layers of EntityStorageController.
I don't think renaming the constants is really valuable per se - at worst, since they are only used by the field loading layers currently, I'd probably be in favor of keeping the FIELD_ prefix if we don't get rid of the constants ;-)
Comment #8
Berdir4: 2081513-4.patch queued for re-testing.
Comment #10
plopescHello
Replaced FIELD_LOAD_* constants by boolean flag.
Removed
QueryInterface::age()
and created a new methodQueryInterface::loadRevisions()
.Regards
Comment #12
longwaveIn field.views.inc I found the use of FALSE/TRUE as array keys entirely unintuitive, and this also seems to be the cause of the test failure. Instead it seems safe to use strings here, as they are only ever referred to inside the same function; the attached patch uses 'current' and 'revision' here.
Comment #15
alexpottDiscussed this issue with @Berdir in IRC as it is related to #2458543: Entity query age(EntityStorageInterface::FIELD_LOAD_REVISION) only gets current revision ID. That issue makes this one much simpler and also makes the constant have even less meaning and relevance. So this is a followup of that issue.
Also the use of the
$age
param infile_get_file_references()
looks very broken.Comment #16
BerdirYes, only usages in file and views are remaining I think.
Anyone up for reroll?
Comment #17
BerdirTagging as novice for the reroll.
Comment #18
siva_epari CreditAttribution: siva_epari commentedPatch rerolled
Comment #19
siva_epari CreditAttribution: siva_epari commentedComment #21
BerdirThat reroll happened a bit early, #2458543: Entity query age(EntityStorageInterface::FIELD_LOAD_REVISION) only gets current revision ID was not yet committed. Let's try again :)
Comment #22
andypostI think better to use
$load_revisions
as param name, because it mans to load all revisions on notComment #23
alexpottThis is just swapping the param name - fine but it actually does not do anything. Which is a bug. And looking at FileAccessControlHandler - is this a security issue?
Comment #24
alexpottThis issue is a major task so we need to outline how it fits within the allowable Drupal 8 beta criteria. Can someone add Drupal 8 beta phase evaluation template to the issue summary.
Comment #27
andypost@Berdir does the issue still makes sense for 8.0?
Comment #28
andypost8.1 material, but needs BC now
Comment #29
alexpottChaning title to reflect new aim
Comment #30
BerdirWondering what we want to do exactly? There are two remaining uses for that constant:
1. file_get_file_references() very strange left-over that uses that constant in a completely unrelated way. I guess we could add new constants with the same value, but I'd rather just move the whole function to a service with a better API and deprecate the old function completely.
2. (apparently) completely internal usage in views_field_default_views_data(). We could just stop using them there I think and instead use a string or so. Or we could just keep them and deprecate anyway.
1. would need a separate issue I think and this would be blocked on that, after that we could just deprecate the constants and either update 2. to use something else or don't care and assume the whole function will sooner or later be rewritten or moved and deprecated as a whole (e.g. there's the pending issue of integrating per field type views data into EntityViewsData).
Comment #31
BerdirThat said, whatever we do, I don't think this is a major anymore. Usage of this was far more widespread when this issue was created and I think the most problematic/confusing one was in entity queries. But any usage in storage handlers and entity query has been refactored away in other issues.
And one remaining public usage in an API function that is weird on its own isn't a major problem IMHO.
Comment #34
andypost@Berdir now revision api in core any idea how to clean-up this?