Skip to content
Snippets Groups Projects
Commit ee4d43cb authored by Damian Lee's avatar Damian Lee Committed by Tim Plunkett
Browse files

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

parent 1c854a86
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -32,6 +32,7 @@ public function setUp() { ...@@ -32,6 +32,7 @@ public function setUp() {
function testTokenReplacement() { function testTokenReplacement() {
$view = views_get_view('test_tokens'); $view = views_get_view('test_tokens');
$view->setDisplay('page_1'); $view->setDisplay('page_1');
$this->executeView($view);
$expected = array( $expected = array(
'[view:name]' => 'Test tokens', '[view:name]' => 'Test tokens',
...@@ -39,6 +40,12 @@ function testTokenReplacement() { ...@@ -39,6 +40,12 @@ function testTokenReplacement() {
'[view:machine-name]' => 'test_tokens', '[view:machine-name]' => 'test_tokens',
'[view:title]' => 'Test token page', '[view:title]' => 'Test token page',
'[view:url]' => url('test_tokens', array('absolute' => TRUE)), '[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) { foreach ($expected as $token => $expected_output) {
......
...@@ -31,9 +31,9 @@ display: ...@@ -31,9 +31,9 @@ display:
relationship: none relationship: none
table: views_test_data table: views_test_data
pager: pager:
type: full
options: options:
offset: '0' items_per_page: 10
type: none
pager_options: { } pager_options: { }
display_plugin: default display_plugin: default
display_title: Master display_title: Master
......
...@@ -35,6 +35,30 @@ function views_token_info() { ...@@ -35,6 +35,30 @@ function views_token_info() {
'description' => t('The URL of the view.'), 'description' => t('The URL of the view.'),
'type' => 'url', '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; return $info;
} }
...@@ -79,6 +103,26 @@ function views_tokens($type, $tokens, array $data = array(), array $options = ar ...@@ -79,6 +103,26 @@ function views_tokens($type, $tokens, array $data = array(), array $options = ar
$replacements[$original] = url($path, $url_options); $replacements[$original] = url($path, $url_options);
} }
break; 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;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment