1

I have a custom content entity (service) with a 'file' field defined by:

$fields['file'] = BaseFieldDefinition::create('file')
  ->setLabel(t('File'))
  ->setSettings([
    'file_extensions' => 'pdf',
    'file_directory' => 'sel',
    'description_field' => TRUE,
  ])
  ->setDisplayOptions('view', [
    'type' => 'file',
  ])
  ->setDisplayOptions('form', [
    'type' => 'file',
  ])
  ->setDisplayConfigurable('form', TRUE)
  ->setDisplayConfigurable('view', TRUE);

A classic CRUD form allows me to create a service: enter image description here Lets say I upload a file with spaces in its name. As you can see if I hover the file name in the form, the link appears to be http://jdp8:8888/sites/default/files/sel/name%20with%20spaces.pdfwith space replaced by %20 and the link works: enter image description here
So far, so good...

I have a View to display this content entity: enter image description here The 'file' field is rendered as a '•' with a link to the file that allows to open the content of the file (a .pdf file) in another window.
When the file name contains spaces, it is rendered as http://jdp8:8888/sites/default/files/sel/name%2520with%2520spaces.pdf with %2520instead of %20.
And of course the links leads to a The requested page was not found error.

I have recently updated Drupal to 8.9.13.
Before I was running Drupal 8.9.1 and I am pretty sure that it was working.

Any idea on what is going wrong? Is it Drupal? Is it Views?

As I suspect Views (everywhere else, it works), here is the way the file field is handled in the view: enter image description here

2
  • Related stackoverflow.com/q/16084935/2199525
    – leymannx
    Commented Mar 22, 2021 at 9:00
  • 1
    I had seen this post and it helped to understand the double encoding thing but I didn't see how it can help to solve my problem. I edited my question to add details on how the link is handled in the view.
    – gbmapo
    Commented Mar 22, 2021 at 15:42

1 Answer 1

2

I found a kind of workaround: I wrote {{ file__target_id|replace({'%20': " "}) }} in the definition of 'file' field in the view. enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.