updated core to 7.58 (right after the site was hacked)
This commit is contained in:
12
sites/all/modules/examples/pager_example/pager_example.info
Normal file
12
sites/all/modules/examples/pager_example/pager_example.info
Normal file
@ -0,0 +1,12 @@
|
||||
name = Pager example
|
||||
description = Demonstrates a page with content in a pager
|
||||
package = Example modules
|
||||
core = 7.x
|
||||
files[] = pager_example.test
|
||||
|
||||
; Information added by Drupal.org packaging script on 2017-01-10
|
||||
version = "7.x-1.x-dev"
|
||||
core = "7.x"
|
||||
project = "examples"
|
||||
datestamp = "1484076787"
|
||||
|
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This is an example describing how a module can implement a pager in order
|
||||
* to reduce the number of output rows to the screen and allow a user
|
||||
* to scroll through multiple screens of output.
|
||||
*
|
||||
* See:
|
||||
* @link http://drupal.org/developing/api/database Database API @endlink
|
||||
* @link http://drupal.org/node/508796 Extenders @endlink
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup pager_example Example: Pager
|
||||
* @ingroup examples
|
||||
* @{
|
||||
* Example of a results pager.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function pager_example_help($path, $arg) {
|
||||
switch ($path) {
|
||||
case 'examples/pager_example':
|
||||
return '<p>' . t('The layout here is a themed as a table with a default limit of 10 rows per page. The limit can be changed in the code by changing the limit to some other value. This can be extended to add a filter form as well so the user can choose how many they would like to see on each screen.') . '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function pager_example_menu() {
|
||||
$items['examples/pager_example'] = array(
|
||||
'title' => 'Pager example',
|
||||
'description' => 'Show a page with a long list across multiple pages',
|
||||
'page callback' => 'pager_example_page',
|
||||
'access callback' => TRUE,
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the pager query.
|
||||
*
|
||||
* Uses the date_formats table since it is installed with ~35 rows
|
||||
* in it and we don't have to create fake data in order to show
|
||||
* this example.
|
||||
*
|
||||
* @return array
|
||||
* A render array completely set up with a pager.
|
||||
*/
|
||||
function pager_example_page() {
|
||||
// We are going to output the results in a table with a nice header.
|
||||
$header = array(
|
||||
array('data' => t('DFID')),
|
||||
array('data' => t('Format')),
|
||||
array('data' => t('Type')),
|
||||
);
|
||||
|
||||
// We are extending the PagerDefault class here.
|
||||
// It has a default of 10 rows per page.
|
||||
// The extend('PagerDefault') part here does all the magic.
|
||||
$query = db_select('date_formats', 'd')->extend('PagerDefault');
|
||||
$query->fields('d', array('dfid', 'format', 'type'));
|
||||
|
||||
// Change the number of rows with the limit() call.
|
||||
$result = $query
|
||||
->limit(10)
|
||||
->orderBy('d.dfid')
|
||||
->execute();
|
||||
|
||||
$rows = array();
|
||||
foreach ($result as $row) {
|
||||
// Normally we would add some nice formatting to our rows
|
||||
// but for our purpose we are simply going to add our row
|
||||
// to the array.
|
||||
$rows[] = array('data' => (array) $row);
|
||||
}
|
||||
|
||||
// Create a render array ($build) which will be themed as a table with a
|
||||
// pager.
|
||||
$build['pager_table'] = array(
|
||||
'#theme' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#empty' => t('There are no date formats found in the db'),
|
||||
);
|
||||
|
||||
// Attach the pager theme.
|
||||
$build['pager_pager'] = array('#theme' => 'pager');
|
||||
|
||||
return $build;
|
||||
}
|
||||
/**
|
||||
* @} End of "defgroup pager_example".
|
||||
*/
|
57
sites/all/modules/examples/pager_example/pager_example.test
Normal file
57
sites/all/modules/examples/pager_example/pager_example.test
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Simpletest case for pager_example module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Functionality tests for the pager example module.
|
||||
*
|
||||
* @ingroup pager_example
|
||||
*/
|
||||
class PagerExampleTestCase extends DrupalWebTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Pager Example',
|
||||
'description' => 'Verify the pager functionality',
|
||||
'group' => 'Examples',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
// Enable the module.
|
||||
parent::setUp('pager_example');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the functionality of the example module.
|
||||
*/
|
||||
public function testPagerPage() {
|
||||
// No need to login for this test.
|
||||
$this->drupalGet('examples/pager_example');
|
||||
$this->assertText('next', 'Found next link');
|
||||
$this->assertText('last', 'Found last link');
|
||||
|
||||
// On the first page we shouldn't see the first
|
||||
// or previous links.
|
||||
$this->assertNoText('first', 'No first link on the first page');
|
||||
$this->assertNoText('previous', 'No previous link on the first page');
|
||||
|
||||
// Let's go to the second page.
|
||||
$this->drupalGet('examples/pager_example', array('query' => array('page' => 1)));
|
||||
$this->assertText('next', 'Found next link');
|
||||
$this->assertText('last', 'Found last link');
|
||||
|
||||
// On the second page we should also see the first
|
||||
// and previous links.
|
||||
$this->assertText('first', 'Found first link');
|
||||
$this->assertText('previous', 'Found previous link');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user