diff --git a/web/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php b/web/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php index db19052..383174c 100644 --- a/web/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php +++ b/web/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php @@ -137,7 +137,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#title' => $this->t('View arguments'), '#default_value' => $default, '#required' => FALSE, - '#description' => $this->t('Provide a comma separated list of arguments to pass to the view.'), + '#description' => t('Provide a comma separated list of arguments to pass to the view.') . '
' . t('This field supports tokens.'), ); } else { @@ -213,7 +213,7 @@ protected function initializeView($match = NULL, $match_operator = 'CONTAINS', $ public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) { $handler_settings = $this->configuration['handler_settings']; $display_name = $handler_settings['view']['display_name']; - $arguments = $handler_settings['view']['arguments']; + $arguments = $this->handleArgs($handler_settings['view']['arguments']); $result = array(); if ($this->initializeView($match, $match_operator, $limit)) { // Get the results. @@ -244,7 +244,7 @@ public function countReferenceableEntities($match = NULL, $match_operator = 'CON public function validateReferenceableEntities(array $ids) { $handler_settings = $this->configuration['handler_settings']; $display_name = $handler_settings['view']['display_name']; - $arguments = $handler_settings['view']['arguments']; + $arguments = $this->handleArgs($handler_settings['view']['arguments']); $result = array(); if ($this->initializeView(NULL, 'CONTAINS', 0, $ids)) { // Get the results. @@ -288,4 +288,32 @@ public static function settingsFormValidate($element, FormStateInterface $form_s */ public function entityQueryAlter(SelectInterface $query) { } + /** + * Handles replacing tokens in arguments for views. + * + * Replaces tokens using Token::replace. + * + * @param array $args + * An array of arguments that may contain tokens. + * + * @return array + * The arguments to be sent to the View. + */ + protected function handleArgs($args) { + $token_service = \Drupal::token(); + $options = array( + 'clear' => TRUE, + ); + + $data = array(); + if ($this->configuration['entity']) { + $data = array($this->configuration['entity']->getEntityTypeId() => $this->configuration['entity']); + } + + // Replace tokens for each argument. + foreach ($args as $key => $arg) { + $args[$key] = $token_service->replace($arg, $data, $options); + } + return $args; + } }