protected function EntityReference_SelectionHandler_Views::handleArgs in Entity reference 7
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.
2 calls to EntityReference_SelectionHandler_Views::handleArgs()
- EntityReference_SelectionHandler_Views::getReferencableEntities in plugins/
selection/ EntityReference_SelectionHandler_Views.class.php - Implements EntityReferenceHandler::getReferencableEntities().
- EntityReference_SelectionHandler_Views::validateReferencableEntities in plugins/
selection/ EntityReference_SelectionHandler_Views.class.php - Validate that entities can be referenced by this field.
File
- plugins/
selection/ EntityReference_SelectionHandler_Views.class.php, line 201
Class
- EntityReference_SelectionHandler_Views
- Entity handler for Views.
Code
protected function handleArgs($args) {
if (!module_exists('token')) {
return $args;
}
// Parameters for token_replace().
$data = array();
$options = array(
'clear' => TRUE,
);
if ($entity = $this->entity) {
// D7 HACK: 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;
}