- 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 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 commentedMarked #2029709: Convert FIELD_LOAD_CURRENT to a constant on some class/interface as a dupe of this.
Comment #3.0
swentel commentedrephrase
Comment #4
andypostIs this issue valid? Constants are in
EntityStorageControllerInterfaceSuppose it make sense to remove
FIELD_prefixComment #6
andypost4: 2081513-4.patch queued for re-testing.
Comment #7
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
$ageparam 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 commentedPatch rerolled
Comment #19
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_revisionsas 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?
Comment #48
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #49
longwave#30 still stands today, the weirdness is that the constants are defined in core then used once in file.module and once in Views, but these uses could probably be swapped to self-contained constants in each of those cases; it doesn't make much sense to share them. Neither of the things in #30 has happened in the time since that was posted, though. Maybe we just make those issues, postpone this on them happening, and wait another ten years?
Comment #51
smustgrave commentedCan they be enums?
Comment #52
berdir> Maybe we just make those issues, postpone this on them happening, and wait another ten years?
the file module usage is deprecated in #1452100: Private file download returns access denied, when file attached to revision other than current.
views is just a purely internal array key, enum isn't a good fit for that, I'd just duplicate the constants into that class and then deprece them here. Could be done in the same issue too once file.module is done.
Which happens to be exactly what I wrote in 2015, reading up, sadly the rewriting part of that code didn't happen beside moving it into a service.
Comment #53
berdirComment #54
berdir