2

I'm working on a D8 project. I have a webform with multiple fields and one of those is a taxonomy term. The taxonomy term consist of the title and a file upload field. The admin uploads a file in the taxonomy, and in the webform selects which file/s should be visible to the end user.

In order to display those files to the user I created a webform submission view where I get the specific field. The point is that the field might return multiple values (taxonomy terms) which are separated by comma.

How can I remove that comma? In D7 you could choose the separator in mulivalue field but now I can't find something similar.

EDIT: The last idea was to change the output in the template file. So in views-view-field.html.twig I try to replace the comma with space in the output of the field.

{% set output = output|replace({(',') : (' '),}) %}

What I get is the html of the view with a lot of debug informations but the view is not rendered as it should. I get something like <!-- THEME DEBUG --> <!-- THEME HOOK: 'webform_element_base_html' --> <!-- FILE NAME SUGGESTIONS: *

Any idea why?

2

Finally, I found the solution. I'm not sure if is the best, but it works.

function MY_THEME_preprocess_views_view_field(&$variables){
  $view = $variables['view'];

  if ($view->id() == 'VIEW_ID'){
    $output = str_replace(',', '', $variables['output']);
    $variables['output'] = \Drupal\views\Render\ViewsRenderPipelineMarkup::create($output);
  }
}
  • This solution works but it wipes out all commas that are in the content of the field as well. – Achraf JEDAY Aug 16 '17 at 15:25
  • Yes because it replaces the commas. I couldn't find any other working option! – Ismini Aug 16 '17 at 15:32
  • See my answer below. – Achraf JEDAY Aug 16 '17 at 15:39
1

You are seeing <!-- THEME DEBUG --> because Twig debug is enabled in either your sites/default/services.yml or sites/development.services.yml. You can disable Twig debug as follows:

services.yml

parameters:
  twig.config:
    debug: false
  • Yes, I know, but the point is that in the block I still get printed the html as a string and not the files as I should. – Ismini Jul 3 '17 at 16:05
1

You can change or remove the separator from the view configuration of the field:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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