Problem/Motivation

file_get_file_references has a parameter $field which is described as:

 @param \Drupal\Core\Field\FieldDefinitionInterface|null $field
    (optional) A field definition to be used for this check. If given,
    limits the reference check to the given field. Defaults to NULL.

When passing in a field definition the logic within the function is actually comparing this field to field storage definitions instead of the field instances.

Passing in a storage definition is not permitted by the type hint - but removing this type hint and passing in field storage instead of field config does return the correct response.

Steps to reproduce

See patch

Proposed resolution

In #3035352: [PP-1] Deprecate file_get_file_references(). Move the logic to file.usage service it is proposed to deprecate this function and move to a service.

I have looked through core and there are no usages on this param.

I have search in contrib and was unable to find any attempt to use a non NULL value for this param.

Rather than fix, it might be an option to just drop this param as part of #3035352: [PP-1] Deprecate file_get_file_references(). Move the logic to file.usage service

Remaining tasks

  1. Agree on approach

User interface changes

N/a

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

Issue fork drupal-3361361

Command icon 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:

Comments

ericgsmith created an issue. See original summary.

ericgsmith’s picture

StatusFileSize
new1.79 KB

mxr576 made their first commit to this issue’s fork.

mxr576’s picture

Issue summary: View changes

I have also bumped into this issue recently and after some forensic analyses my gut says that the $field based filtering was never worked as expected in 8.x.

Back to the future history:
* https://github.com/drupal/core/commit/8aa449c8248e87e3f675503be1da462c8c... - nothing to see here, just use DI
* https://github.com/drupal/core/commit/de8bb2efaa607caf1d913288ca160f64c4... - Maybe this is where it all got broken, or even before...?

And we also have this CR related to the last commit: https://www.drupal.org/node/2260037

I have proposed a fix for it, I am uncertain at this point if this should be dropped or not, but should be fixed before ##3035352: [PP-1] Deprecate file_get_file_references(). Move the logic to file.usage service if it stays.

mxr576’s picture

Status: Active » Needs review
mxr576’s picture

Functional JS tests fail for no valid reason on the CI, so that can be ignored.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs steps to reproduce

Haven’t reviewed but this needs steps. Just saying see patch doesn’t count :)

mxr576’s picture

Yeah, well, that is part of the original description which I haven't changed, I have only fixed some typos and links.

That said, it is also true, since unless something changed in contrib since the issue was opened, the only code that calls the function and uses the $field parameter is in the test that proves that issue exists.

have search in contrib and was unable to find any attempt to use a non NULL value for this param.

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.