Commit ee4d43cb authored by damiankloip's avatar damiankloip Committed by tim.plunkett
Browse files

Issue #1817938 by damiankloip: Added more tokens to views.tokens.inc.

parent 1c854a86
......@@ -32,6 +32,7 @@ public function setUp() {
function testTokenReplacement() {
$view = views_get_view('test_tokens');
$view->setDisplay('page_1');
$this->executeView($view);
$expected = array(
'[view:name]' => 'Test tokens',
......@@ -39,6 +40,12 @@ function testTokenReplacement() {
'[view:machine-name]' => 'test_tokens',
'[view:title]' => 'Test token page',
'[view:url]' => url('test_tokens', array('absolute' => TRUE)),
'[view:total-rows]' => (string) $view->total_rows,
'[view:base-table]' => 'views_test_data',
'[view:base-field]' => 'id',
'[view:items-per-page]' => '10',
'[view:current-page]' => '1',
'[view:page-count]' => '1',
);
foreach ($expected as $token => $expected_output) {
......
......@@ -31,9 +31,9 @@ display:
relationship: none
table: views_test_data
pager:
type: full
options:
offset: '0'
type: none
items_per_page: 10
pager_options: { }
display_plugin: default
display_title: Master
......
......@@ -35,6 +35,30 @@ function views_token_info() {
'description' => t('The URL of the view.'),
'type' => 'url',
);
$info['tokens']['view']['base-table'] = array(
'name' => t('Base table'),
'description' => t('The base table used for this view.'),
);
$info['tokens']['view']['base-field'] = array(
'name' => t('Base field'),
'description' => t('The base field used for this view.'),
);
$info['tokens']['view']['total-rows'] = array(
'name' => t('Total rows'),
'description' => t('The total amount of results returned from the view. The current display will be used.'),
);
$info['tokens']['view']['items-per-page'] = array(
'name' => t('Items per page'),
'description' => t('The number of items per page.'),
);
$info['tokens']['view']['current-page'] = array(
'name' => t('Current page'),
'description' => t('The current page of results the view is on.'),
);
$info['tokens']['view']['page-count'] = array(
'name' => t('Page count'),
'description' => t('The total page count.'),
);
return $info;
}
......@@ -79,6 +103,26 @@ function views_tokens($type, $tokens, array $data = array(), array $options = ar
$replacements[$original] = url($path, $url_options);
}
break;
case 'base-table':
$replacements[$original] = $view->storage->base_table;
break;
case 'base-field':
$replacements[$original] = $view->storage->base_field;
break;
case 'total-rows':
$replacements[$original] = count($view->result);
break;
case 'items-per-page':
$replacements[$original] = (int) $view->getItemsPerPage();
break;
case 'current-page':
$replacements[$original] = (int) $view->getCurrentPage() + 1;
break;
case 'page-count':
// If there are no items per page, set this to 1 for the division.
$per_page = $view->getItemsPerPage() ?: 1;
$replacements[$original] = (int) ceil(count($view->result) / $per_page);
break;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment