You are here

public function EntityBrowserWidgetContext::getArgument in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/argument_default/EntityBrowserWidgetContext.php \Drupal\entity_browser\Plugin\views\argument_default\EntityBrowserWidgetContext::getArgument()

Return the default argument.

This needs to be overridden by every default argument handler to properly do what is needed.

Overrides ArgumentDefaultPluginBase::getArgument

File

src/Plugin/views/argument_default/EntityBrowserWidgetContext.php, line 97

Class

EntityBrowserWidgetContext
The entity browser widget context argument default handler.

Namespace

Drupal\entity_browser\Plugin\views\argument_default

Code

public function getArgument() {
  $current_request = $this->view
    ->getRequest();
  $context_key = $this->options['context_key'];
  $argument = $this->options['fallback'];

  // Check if the widget context is available.
  if (!empty($context_key) && $current_request->query
    ->has('uuid')) {
    $uuid = $current_request->query
      ->get('uuid');
    if ($storage = $this->selectionStorage
      ->get($uuid)) {
      if (isset($storage['widget_context']) && !empty($storage['widget_context'][$context_key])) {
        $value = $storage['widget_context'][$context_key];
        if (is_string($value)) {
          $argument = $value;
        }
        elseif (is_array($value)) {
          $non_scalar = array_filter($value, function ($item) {
            return !is_scalar($item);
          });
          if (empty($non_scalar)) {
            $conjunction = $this->options['multiple'] == 'and' ? ',' : '+';
            $argument = implode($conjunction, $value);
          }
        }
      }
    }
  }
  return $argument;
}