Problem/Motivation
If you have an entity with a link field that contains a root relative path to a managed file, the file usage is not tracked. E.g.: If a link field has a value like '/sites/default/files/foobar.pdf'. The file usage page for foobar.pdf will not show the entity with the link field as using the file.
This can be a common issue where content people need to link to a file in a standard link field with the default field widget. To do this, they cut and paste just the file path into the link field because that makes it site domain independent (works on dev, etc. sites).
Steps to reproduce
- Create a node type with a standard link field using the default link field widget.
- Upload or use an existing file to get the path part of the url to the file.
- Create a new node of the type from above
- Enter the root relative path in to the link field
- Save
- Check the file's entity usage info /admin/content/entity-usage/file/####
- The new node will not be listed as using the file
Proposed resolution
The problem is that the link plugin only tracks route based internal urls and does not handle the non route case.
The internal url handling in the link plugin's getTargetEntities method should go from:
$url = $link->getUrl();
$entity_info = $this->urlToEntity->findEntityIdByRoutedUrl($url);
$url = $link->getUrl();
if ($url->isRouted()) {
$entity_info = $this->urlToEntity->findEntityIdByRoutedUrl($url);
}
else {
$entity_info = $this->urlToEntity->findEntityIdByUrl($url->toString());
}
FYI - if the url used in the link field is a fully qualified url with a domain listed in the entity_usage config setting, it is tracked.
Remaining tasks
Put together patch.
User interface changes
n/a
API changes
n/a
Data model changes
n/a
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | entity_usage-3592109-link_plugin_track_root_files-2.patch | 653 bytes | cgmonroe |
Issue fork entity_usage-3592109
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
Comment #2
cgmonroe commentedHere's a quick patch to fix this. Sorry don't have the time to write the tests that probably should be included.
Comment #6
alexpottI've added test coverage. @cgmonroe thanks for the bug fix.
Comment #7
alexpott