function _viewfield_get_view_args in Viewfield 7.3
Same name and namespace in other branches
- 6.2 viewfield.module \_viewfield_get_view_args()
- 6 theme/viewfield.theme.inc \_viewfield_get_view_args()
- 7.2 viewfield.module \_viewfield_get_view_args()
Perform argument replacement
1 call to _viewfield_get_view_args()
- viewfield_pre_render in ./
viewfield.module - #pre_render callback for a viewfield field.
File
- ./
viewfield.module, line 504 - Defines a field type to display a view.
Code
function _viewfield_get_view_args($vargs, $entity_type, $entity) {
$args = array();
if (!empty($vargs)) {
$pos = 0;
while ($pos < strlen($vargs)) {
$found = FALSE;
// If string starts with a quote, start after quote and get everything
// before next quote.
if (strpos($vargs, '"', $pos) === $pos) {
if (($quote = strpos($vargs, '"', ++$pos)) !== FALSE) {
// Skip pairs of quotes.
while (!(($ql = strspn($vargs, '"', $quote)) & 1)) {
$quote = strpos($vargs, '"', $quote + $ql);
}
$args[] = str_replace('""', '"', substr($vargs, $pos, $quote + $ql - $pos - 1));
$pos = $quote + $ql + 1;
$found = TRUE;
}
}
elseif (($comma = strpos($vargs, ',', $pos)) !== FALSE) {
// Otherwise, get everything before next comma.
$args[] = substr($vargs, $pos, $comma - $pos);
// Skip to after comma and repeat
$pos = $comma + 1;
$found = TRUE;
}
if (!$found) {
$args[] = substr($vargs, $pos);
$pos = strlen($vargs);
}
}
list($entity_id) = entity_extract_ids($entity_type, $entity);
// If we have an entity_id, proceed with token extraction/replacement.
// In the case of a preview on a new entity, entity_id is NULL.
if (!empty($entity_id)) {
$entities = entity_load($entity_type, array(
$entity_id,
));
$token_data = array(
$entity_type => $entities[$entity_id],
);
foreach ($args as $key => $value) {
$args[$key] = token_replace($value, $token_data);
}
}
}
return $args;
}