token_embed_views.module in Token Embed Views 7
Same filename and directory in other branches
Module to embed views using tokens
File
token_embed_views.moduleView source
<?php
/**
* @file
* Module to embed views using tokens
*/
/**
* Implements hook_token_info().
*/
function token_embed_views_token_info() {
$info['types']['views'] = array(
'name' => t('Views'),
'description' => 'Tokens to embed views.',
);
$info['tokens']['views']['embed'] = array(
'name' => t('Embed views'),
'description' => t('Embed views using tokens. The following values may be appended to the token: view-name:display-id:arg1/arg2/arg3'),
'dynamic' => TRUE,
);
return $info;
}
/**
* Implements hook_tokens().
*/
function token_embed_views_tokens($type, $tokens, array $data = array(), array $options = array()) {
if ($type == 'views') {
$replacements = array();
foreach ($tokens as $token => $key) {
// Extract info.
$args = explode(':', $token);
// Remove the first element out as its not a required parameter for the views.
$token_name = array_shift($args);
// Fetch the view with all args passed to it.
$replacements[$key] = call_user_func_array('views_embed_view', $args);
}
return $replacements;
}
}
Functions
Name![]() |
Description |
---|---|
token_embed_views_tokens | Implements hook_tokens(). |
token_embed_views_token_info | Implements hook_token_info(). |