Skip to content
Snippets Groups Projects
Commit 083a338b authored by Daniele Piaggesi's avatar Daniele Piaggesi
Browse files

first commit

parents
No related branches found
No related tags found
No related merge requests found
<?php
/**
* @file
* prevnext.admin.inc
*/
/**
* Previous/Next Settings Form Callback
*/
function prevnext_settings($form, &$form_state) {
$form['prevnext_enabled_nodetypes'] = array(
'#title' => t('Enabled Node Types'),
'#description' => t('Check node types enabled for Previous/Next'),
'#type' => 'checkboxes',
'#options' => _prevnext_types_as_options(),
'#default_value' => variable_get('prevnext_enabled_nodetypes', array())
);
return system_settings_form($form);
}
/**
* Helper: Retrieve all node types and create an option list with them.
*/
function _prevnext_types_as_options() {
$node_types = node_type_get_types();
$options = array();
foreach ($node_types as $type => $info) {
$options[$type] = $info->name;
}
return $options;
}
\ No newline at end of file
name = Previous Next
description = Add a "Previous/Next" variables to a node
core = 7.x
version = 7.x-1.0
\ No newline at end of file
<?php
/**
* @file
*
* prevnext.module
*/
/**
* Implements hook_permission().
*/
function prevnext_permission() {
return array(
'access prevnext settings' => array(
'title' => t('Access to Previous/Next Settings page')
),
);
}
/**
* Implements hook_menu().
*/
function prevnext_menu() {
$items = array();
$items['admin/config/user-interface/prevnext'] = array(
'title' => 'Previous/Next',
'description' => 'Enable bundles that will use previous/next',
'page callback' => 'drupal_get_form',
'page arguments' => array('prevnext_settings'),
'access arguments' => array('access prevnext settings'),
'file' => 'prevnext.admin.inc',
'file path' => drupal_get_path('module', 'prevnext') . '/include',
'type' => MENU_NORMAL_ITEM
);
return $items;
}
/**
* Implements hook_node_view().
*/
function prevnext_node_view($node, $view_mode, $langcode) {
$enabled_nodetypes = array_filter(variable_get('prevnext_enabled_nodetypes', array()));
if (in_array($node->type, $enabled_nodetypes)) {
$extrafields = field_extra_fields_get_display('node', $node->type, $view_mode);
$prevnext = _prevnext_get_prevnext($node, $langcode);
if (isset($extrafields['prevnext_previous']) && !empty($extrafields['prevnext_previous']['visible']) && !empty($prevnext['prev'])) {
$node->content['prevnext_previous'] = array(
'#markup' => theme('prevnext_previous', array(
'previous' => 'node/' . $prevnext['prev'],
))
);
}
if (isset($extrafields['prevnext_next']) && !empty($extrafields['prevnext_next']['visible']) && !empty($prevnext['next'])) {
$node->content['prevnext_next'] = array(
'#markup' => theme('prevnext_next', array(
'next' => 'node/' . $prevnext['next'],
))
);
}
}
}
/**
* Implements hook_theme().
*/
function prevnext_theme($existing, $type, $theme, $path) {
return array(
'prevnext_previous' => array(
'variables' => array(
'previous' => NULL
),
'template' => 'prevnext-previous',
'path' => $path . '/templates'
),
'prevnext_next' => array(
'variables' => array(
'next' => NULL
),
'template' => 'prevnext-next',
'path' => $path . '/templates'
)
);
}
/**
* Implements hook_field_extra_fields().
*/
function prevnext_field_extra_fields() {
$enabled_nodetypes = array_filter(variable_get('prevnext_enabled_nodetypes', array()));
if (!empty($enabled_nodetypes)) {
$extra = array();
foreach ($enabled_nodetypes as $key => $value) {
$extra['node'][$key]['display']['prevnext_previous'] = array(
'label' => t('Previous'),
'description' => t('Previous node indicator'),
'weight' => 50
);
$extra['node'][$key]['display']['prevnext_next'] = array(
'label' => t('Next'),
'description' => t('Next node indicator'),
'weight' => 50
);
}
return $extra;
}
}
/**
* Helper: Retrieve previous/next nodes
*/
function _prevnext_get_prevnext($node, $language) {
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->propertyCondition('language', $language)
->propertyCondition('type', $node->type);
$result = $query->execute();
$nids = array();
foreach ($result['node'] as $result_nids) {
$nids[$result_nids->nid] = $result_nids->nid;
}
$key = array_search($node->nid, $nids);
return array(
'prev' => !empty($nids[$key-1]) ? $nids[$key-1] : '',
'next' => !empty($nids[$key+1]) ? $nids[$key+1] : '',
);
}
<?php print $next ?>
\ No newline at end of file
<?php print $previous ?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment