If computed view argument is empty the default value or action is not used

Created on 18 January 2018, almost 7 years ago
Updated 24 August 2024, 3 months ago

Problem/Motivation

If you pass an empty string as argument, the argument is applied to the view query while an argument with value NULL is not.

Example:

      $arguments = [ 
        0 => '', // is processed in query
        1 => NULL, // is skipped and default argument or default action is used
        2 => 'foo' // is processed in query
      ];

      /** @var \Drupal\views\ViewExecutable $view */
      $view = Views::getView($target_id);
      $view->setArguments($arguments);
      $view->preExecute();
      $view->execute();

An empty string as argument could be an result of a token replacement like this:

$value = '[node:field_with_no_user_input]';
$token_data = [$entity->getEntityTypeId() => $entity];
$token_service = \Drupal::token();
$arguments[] = $token_service->replace($value, $token_data);

Of course I could check the argument if it is empty before passing it to the view but shouldn't this be handled in the view's _buildArguments function?

Proposed resolution

I think an empty view argument should be handled the same way like a NULL argument. Or am I missing something?

๐Ÿ› Bug report
Status

Needs review

Version

10.2 โœจ

Component
Viewsย  โ†’

Last updated about 2 hours ago

Created by

๐Ÿ‡ฉ๐Ÿ‡ชGermany pminf Nuremburg (Germany), formerly Dresden

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024