Skip to content
Snippets Groups Projects
Commit 04b40e20 authored by Adriano Cori's avatar Adriano Cori Committed by Adriano
Browse files

Issue #3206140 by aronne: PrevNext name

parent a7a02602
No related branches found
No related tags found
No related merge requests found
{
"name": "drupal/prevnext",
"type": "drupal-module",
"description": "Add a 'Previous - Next' links to the node display.",
"description": "Add a 'Previous/Next' links to the node display.",
"keywords": ["Drupal"],
"license": "GPL-2.0+",
"homepage": "https://www.drupal.org/project/prevnext",
......
name: Previous & Next
name: PrevNext
type: module
description: Add a "Previous/Next" links to the node display.
core_version_requirement: ^8 || ^9 || ^10
......
......@@ -5,12 +5,12 @@
* Contains prevnext.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use \Drupal\Core\Url;
use \Drupal\Core\Cache\Cache;
use Drupal\node\Entity\Node;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;
/**
* Implements hook_help().
......@@ -23,7 +23,7 @@ function prevnext_help($route_name, RouteMatchInterface $route_match) {
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Add a &quot;Previous/Next&quot; links to the node display.') . '</p>';
return $output;
default:
}
}
......@@ -33,7 +33,7 @@ function prevnext_help($route_name, RouteMatchInterface $route_match) {
*/
function prevnext_theme($existing, $type, $theme, $path) {
$themes = [];
$themes['prevnext'] = [
'variables' => [
'direction' => '',
......@@ -42,10 +42,8 @@ function prevnext_theme($existing, $type, $theme, $path) {
'url' => '',
'void' => TRUE,
],
// Note that there is no need to indicate the template name, in absence of
// it the system will assume "prevnext.html.twig", inside "templates" dir.
];
return $themes;
}
......@@ -54,10 +52,10 @@ function prevnext_theme($existing, $type, $theme, $path) {
*/
function prevnext_entity_extra_field_info() {
$extra = [];
$config = \Drupal::config('prevnext.settings');
$enabled_nodetypes = $config->get('prevnext_enabled_nodetypes');
if (!empty($enabled_nodetypes)) {
foreach ($enabled_nodetypes as $bundle_key => $bundle_name) {
if (!empty($bundle_name)) {
......@@ -74,7 +72,7 @@ function prevnext_entity_extra_field_info() {
}
}
}
return $extra;
}
......@@ -82,40 +80,42 @@ function prevnext_entity_extra_field_info() {
* Implements hook_ENTITY_TYPE_view().
*/
function prevnext_node_view(array &$build, Node $node, EntityViewDisplayInterface $display, $view_mode) {
// Checking if current node is configured for prevnext or not.
$config = \Drupal::config('prevnext.settings');
$enabled_nodetypes = $config->get('prevnext_enabled_nodetypes');
if (empty($enabled_nodetypes[$node->getType()])) {
return;
}
/** @var \Drupal\prevnext\PrevnextService $prevnext */
/** @var \Drupal\prevnext\PrevNextService $prevnext */
$prevnext = \Drupal::service('prevnext.service');
$previous_next = $prevnext->getPreviousNext($node);
if ($display->getComponent('prevnext_previous')) {
$build['prevnext_previous'] = [
'#theme' => 'prevnext',
'#direction' => 'previous',
'#text' => t('Previous'),
'#nid' => $previous_next['prev'],
'#url' => Url::fromUserInput('/node/' . $previous_next['prev'])->toString(),
'#url' => Url::fromUserInput('/node/' . $previous_next['prev'])
->toString(),
'#void' => empty($previous_next['prev']),
];
}
if ($display->getComponent('prevnext_next')) {
$build['prevnext_next'] = [
'#theme' => 'prevnext',
'#direction' => 'next',
'#text' => t('Next'),
'#nid' => $previous_next['next'],
'#url' => Url::fromUserInput('/node/' . $previous_next['next'])->toString(),
'#url' => Url::fromUserInput('/node/' . $previous_next['next'])
->toString(),
'#void' => empty($previous_next['next']),
];
}
// Once these links will be cached inside the node rendered output, we will
// add a custom cache tag to allow invalidation of all these cached info
// later (for example when a new node of this type is created).
......
prevnext.admin_settings:
path: '/admin/config/user-interface/prevnext'
defaults:
_form: '\Drupal\prevnext\Form\PrevnextSettingsForm'
_title: 'Previous - Next Settings'
_form: '\Drupal\prevnext\Form\PrevNextSettingsForm'
_title: 'PrevNext Settings'
requirements:
_permission: 'administer prevnext'
services:
prevnext.service:
class: Drupal\prevnext\PrevnextService
class: Drupal\prevnext\PrevNextService
arguments: ["@entity_type.manager"]
......@@ -6,11 +6,11 @@ use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class PrevnextSettingsForm.
* Class PrevNextSettingsForm.
*
* @package Drupal\prevnext\Form
*/
class PrevnextSettingsForm extends ConfigFormBase {
class PrevNextSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
......@@ -34,7 +34,7 @@ class PrevnextSettingsForm extends ConfigFormBase {
$form['prevnext_enabled_nodetypes'] = [
'#title' => $this->t('Enabled Node Types'),
'#description' => $this->t('Check node types enabled for Previous/Next'),
'#description' => $this->t('Check node types enabled for PrevNext'),
'#type' => 'checkboxes',
'#options' => node_type_get_names(),
'#default_value' => !empty($config->get('prevnext_enabled_nodetypes')) ? $config->get('prevnext_enabled_nodetypes') : [],
......
......@@ -7,11 +7,11 @@ use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
/**
* Class PrevnextService.
* Class PrevNextService.
*
* @package Drupal\prevnext
*/
class PrevnextService implements PrevnextServiceInterface {
class PrevNextService implements PrevNextServiceInterface {
/**
* The entity type manager.
......@@ -28,7 +28,7 @@ class PrevnextService implements PrevnextServiceInterface {
public $prevnext;
/**
* PrevnextService constructor.
* PrevNextService constructor.
*
* @param EntityTypeManagerInterface $entityTypeManager
* The entity type manager instance.
......
......@@ -5,11 +5,11 @@ namespace Drupal\prevnext;
use Drupal\node\Entity\Node;
/**
* Interface PrevnextServiceInterface.
* Interface PrevNextServiceInterface.
*
* @package Drupal\prevnext
*/
interface PrevnextServiceInterface {
interface PrevNextServiceInterface {
/**
* Retrieves previous and next nids of a given node, if they exist.
......
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