Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
isLocal() uses $this->uri, but that's a FieldItemList object, it should use $this->getFileUri()
I can possibly also be simplified a lot by using \Drupal\Core\StreamWrapper\StreamWrapperManager::getViaUri() and then getType().
Comment | File | Size | Author |
---|---|---|---|
#4 | file_entity-2846057-4.patch | 646 bytes | pifagor |
#2 | file_entity-2846057-2.patch | 7.79 KB | pifagor |
Comments
Comment #2
pifagorPatch. Was unable to verify, test pliz
Comment #3
BerdirThanks.
this is different, $file here is the return value of file_scan_directory, pretty sure those are stdClass objects and shouldn't be change.
Same for all other references except the one in isLocal(). You really only need to change that one.
Comment #4
pifagornew patch
Comment #5
BerdirThanks, this is what I did in our project as a replacement of isLocal(), which is think is much easier to read:
$stream_wrapper = \Drupal::service('stream_wrapper_manager')->getViaUri($file->getFileUri());
if ($stream_wrapper && $stream_wrapper->getType() & StreamWrapperInterface::LOCAL) {
Want to try and replace the current implementation with something like that? We could put \Drupal::service('stream_wrapper_manager') in a separate method so we can document the return value and get proper method autocomplete.
Comment #6
BerdirComment #7
dsdeiz CreditAttribution: dsdeiz commentedCurious if other methods need to be changed as well. I see 3 methods using the same logic:
isReadable()
isWritable()
isLocal()
isLocal()
seems to be the only one not using$this->getFileUri()
. Should others be changed as well or just specificallyisLocal()
? Also thought about accessing thestream_wrapper_manager
service using dependency injection although I see a lot of other services accessed from\Drupal::service()
.