- 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.

Comments

berdir’s picture

The 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...

yched’s picture

views 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()]

swentel’s picture

swentel’s picture

Issue summary: View changes

rephrase

andypost’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new16.05 KB

Is this issue valid? Constants are in EntityStorageControllerInterface
Suppose it make sense to remove FIELD_ prefix

Status: Needs review » Needs work

The last submitted patch, 4: 2081513-4.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review

4: 2081513-4.patch queued for re-testing.

yched’s picture

See 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 ;-)

berdir’s picture

4: 2081513-4.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 4: 2081513-4.patch, failed testing.

plopesc’s picture

Status: Needs work » Needs review
StatusFileSize
new20.65 KB

Hello
Replaced FIELD_LOAD_* constants by boolean flag.
Removed QueryInterface::age() and created a new method QueryInterface::loadRevisions().

Regards

Status: Needs review » Needs work

The last submitted patch, 10: remove_field_load_constants-2081513-10.patch, failed testing.

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new19.81 KB
new4.03 KB

In 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.

Status: Needs review » Needs work

The last submitted patch, 12: 2081513-field_load-constants-12.patch, failed testing.

alexpott’s picture

Discussed 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 in file_get_file_references() looks very broken.

berdir’s picture

Priority: Normal » Major

Yes, only usages in file and views are remaining I think.

Anyone up for reroll?

berdir’s picture

Issue tags: +Needs reroll, +Novice

Tagging as novice for the reroll.

siva_epari’s picture

Issue tags: -Needs reroll, -Novice
StatusFileSize
new10.83 KB

Patch rerolled

siva_epari’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 18: 2081513-field_load-constants-18.patch, failed testing.

berdir’s picture

Issue tags: +Needs reroll, +Novice

That 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 :)

andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll, -Novice +API clean-up
StatusFileSize
new8.76 KB

I think better to use $load_revisions as param name, because it mans to load all revisions on not

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/modules/file/file.module
@@ -1431,13 +1427,13 @@ function file_icon_map($mime_type) {
-function file_get_file_references(FileInterface $file, FieldDefinitionInterface $field = NULL, $age = EntityStorageInterface::FIELD_LOAD_REVISION, $field_type = 'file') {
+function file_get_file_references(FileInterface $file, FieldDefinitionInterface $field = NULL, $load_revisions = TRUE, $field_type = 'file') {
...
-  if (!isset($references[$file->id()][$age])) {
-    $references[$file->id()][$age] = array();
+  if (!isset($references[$file->id()][$load_revisions])) {
+    $references[$file->id()][$load_revisions] = array();

@@ -1470,7 +1466,7 @@ function file_get_file_references(FileInterface $file, FieldDefinitionInterface
-                $references[$file->id()][$age][$field_name][$entity_type_id][$entity->id()] = $entity;
+                $references[$file->id()][$load_revisions][$field_name][$entity_type_id][$entity->id()] = $entity;

@@ -1479,7 +1475,7 @@ function file_get_file_references(FileInterface $file, FieldDefinitionInterface
-  $return = $references[$file->id()][$age];
+  $return = $references[$file->id()][$load_revisions];

+++ b/core/modules/file/src/FileAccessControlHandler.php
@@ -62,7 +62,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A
-    return file_get_file_references($file, NULL, EntityStorageInterface::FIELD_LOAD_REVISION, NULL);
+    return file_get_file_references($file, NULL, TRUE, NULL);

This 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?

alexpott’s picture

This 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.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 22: get_rid_of_field_load-2081513-22.patch, failed testing.

andypost’s picture

@Berdir does the issue still makes sense for 8.0?

andypost’s picture

Version: 8.0.x-dev » 8.1.x-dev

8.1 material, but needs BC now

alexpott’s picture

Title: Get rid of FIELD_LOAD_* constants ? » Deprecate FIELD_LOAD_* constants

Chaning title to reflect new aim

berdir’s picture

Wondering 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).

berdir’s picture

Priority: Major » Normal

That 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.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

@Berdir now revision api in core any idea how to clean-up this?

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +stale-issue-cleanup

Thank 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!

longwave’s picture

#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?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

smustgrave’s picture

Can they be enums?

berdir’s picture

Status: Postponed (maintainer needs more info) » Active

> 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.

berdir’s picture

Title: Deprecate FIELD_LOAD_* constants » [pp-1] Deprecate FIELD_LOAD_* constants
berdir’s picture

Status: Active » Postponed