1 EntityReferenceSelectionHandlerViews.inc protected EntityReferenceSelectionHandlerViews::handleArgs($args)

Handles arguments for views.

Replaces tokens using token_replace().

Parameters

array $args: Usually $this->field['settings']['handler_settings']['view']['args'].

Return value

array: The arguments to be send to the View.

File

core/modules/entityreference/plugins/selection/EntityReferenceSelectionHandlerViews.inc, line 198

Class

EntityReferenceSelectionHandlerViews
Entity handler for Views.

Code

protected function handleArgs($args) {
  // Parameters for token_replace().
  $data = array();
  $options = array('clear' => TRUE);

  if ($entity = $this->entity) {
    // For new entities, entity and revision id are not set. This leads to
    // * token replacement emitting PHP warnings
    // * views choking on empty arguments
    // We workaround this by filling in '0' for these IDs
    // and use a clone to leave no traces of our unholy doings.
    $info = entity_get_info($this->instance['entity_type']);
    if (!isset($entity->{$info['entity keys']['id']})) {
      $entity = clone $entity;
      $entity->{$info['entity keys']['id']} = '0';
      if (!empty($info['entity keys']['revision'])) {
        $entity->{$info['entity keys']['revision']} = '0';
      }
    }

    $data[$info['token type']] = $entity;
  }
  // Replace tokens for each argument.
  foreach ($args as $key => $arg) {
    $args[$key] = token_replace($arg, $data, $options);
  }
  return $args;
}