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?

4 Answers 4

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);
  }
}
3
  • This solution works but it wipes out all commas that are in the content of the field as well. Aug 16, 2017 at 15:25
  • Yes because it replaces the commas. I couldn't find any other working option!
    – Ismini
    Aug 16, 2017 at 15:32
  • See my answer below. Aug 16, 2017 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
1
  • 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, 2017 at 16:05
1

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

enter image description here

0

I was expecting the solution provided by @Achraf should've worked as I've been using the same thing for a decade! Surprisingly, the "MULTIPLE VALUES HANDLING" option is missing if I check "Use entity field rendering" at the view field option while using Drupal 9.4.8.

I've tried to improve the code snippet provided by @Ismini. In the following, apart from checking the Views ID, I'm also restricting it to a SPECIFIC DISPLAY & most importantly for me, to a SPECIFIC FIELD.

/**
 * Implements template_preprocess_views_view_field().
 */
function my_template_preprocess_views_view_field(&$variables) {
  /** @var \Drupal\views\ViewExecutable $view */
  $view = $variables['view'];
  if ($view->id() === 'my_views_id' && $view->current_display === 'my_current_display' && $variables['field']->field === 'my_field') {
    $output = str_replace(',', '', $variables['output']);
    $variables['output'] = \Drupal\views\Render\ViewsRenderPipelineMarkup::create($output);
  }
}

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.