From 92c9819fdb8d25cd502d0281c093db40b0f31ed2 Mon Sep 17 00:00:00 2001 From: bach Date: Wed, 28 Aug 2024 18:54:23 +0200 Subject: [PATCH] Site prev next --- composer.json | 1 + composer.lock | 57 ++++++++++++- config/sync/core.extension.yml | 1 + ...age_variant.node_view-panels_variant-0.yml | 14 +++ config/sync/quick_node_clone.settings.yml | 8 ++ config/sync/user.role.admin.yml | 5 ++ config/sync/user.role.editeur.yml | 2 + .../q2d_mod/src/Plugin/Block/PrevNextSite.php | 85 +++++++++++++++++++ 8 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 config/sync/quick_node_clone.settings.yml create mode 100644 web/modules/custom/q2d_mod/src/Plugin/Block/PrevNextSite.php diff --git a/composer.json b/composer.json index 136f7b5..363af7b 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,7 @@ "drupal/page_manager": "^4.0@RC", "drupal/panels": "^4.8", "drupal/paragraphs": "^1.17", + "drupal/quick_node_clone": "^1.18", "drupal/simple_sitemap": "^4.1", "drupal/social_media_links": "^2.9", "drupal/yaml_editor": "^1.2", diff --git a/composer.lock b/composer.lock index 7a681cc..52697a7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "79223df96df990c3b850f7ecb6441e64", + "content-hash": "e8b3c553a92e6d3283d8e7a0a0a7d159", "packages": [ { "name": "asm89/stack-cors", @@ -6286,6 +6286,61 @@ "source": "https://git.drupalcode.org/project/profile" } }, + { + "name": "drupal/quick_node_clone", + "version": "1.18.0", + "source": { + "type": "git", + "url": "https://git.drupalcode.org/project/quick_node_clone.git", + "reference": "8.x-1.18" + }, + "dist": { + "type": "zip", + "url": "https://ftp.drupal.org/files/projects/quick_node_clone-8.x-1.18.zip", + "reference": "8.x-1.18", + "shasum": "ab17077eccb24e5c651fedc5056a50051882a13d" + }, + "require": { + "drupal/core": "^8.8 || ^9 || ^10" + }, + "require-dev": { + "drupal/group": "^1 || ^2 || ^3", + "drupal/paragraphs": "1.x-dev" + }, + "type": "drupal-module", + "extra": { + "drupal": { + "version": "8.x-1.18", + "datestamp": "1707833857", + "security-coverage": { + "status": "covered", + "message": "Covered by Drupal's security advisory policy" + } + } + }, + "notification-url": "https://packages.drupal.org/8/downloads", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "vilepickle", + "homepage": "https://www.drupal.org/u/vilepickle", + "role": "Maintainer" + }, + { + "name": "Neslee Canil Pinto", + "homepage": "https://www.drupal.org/u/neslee-canil-pinto", + "role": "Maintainer" + } + ], + "description": "Quickly clone a node with regular fields.", + "homepage": "https://www.drupal.org/project/quick_node_clone", + "support": { + "source": "https://git.drupalcode.org/project/quick_node_clone", + "issues": "https://www.drupal.org/project/issues/quick_node_clone" + } + }, { "name": "drupal/redirect", "version": "1.9.0", diff --git a/config/sync/core.extension.yml b/config/sync/core.extension.yml index d1c5737..9450a7b 100644 --- a/config/sync/core.extension.yml +++ b/config/sync/core.extension.yml @@ -91,6 +91,7 @@ module: pathologic: 0 persistent_login: 0 q2d_mod: 0 + quick_node_clone: 0 redis: 0 responsive_image: 0 search_api: 0 diff --git a/config/sync/page_manager.page_variant.node_view-panels_variant-0.yml b/config/sync/page_manager.page_variant.node_view-panels_variant-0.yml index 6e1c025..9a51733 100644 --- a/config/sync/page_manager.page_variant.node_view-panels_variant-0.yml +++ b/config/sync/page_manager.page_variant.node_view-panels_variant-0.yml @@ -9,6 +9,7 @@ dependencies: - ctools_block - node - panels + - q2d_mod - views id: node_view-panels_variant-0 label: Sites @@ -188,6 +189,19 @@ variant_settings: - '' html_id: '' css_styles: '' + 585c2156-c9db-4940-8382-0744350facf6: + id: prevnextsite_block + label: 'PrevNext Site Block' + label_display: '0' + provider: q2d_mod + context_mapping: { } + region: third + weight: 0 + uuid: 585c2156-c9db-4940-8382-0744350facf6 + css_classes: + - '' + html_id: '' + css_styles: '' page_title: '' layout: layout_threecol_25_50_25 layout_settings: diff --git a/config/sync/quick_node_clone.settings.yml b/config/sync/quick_node_clone.settings.yml new file mode 100644 index 0000000..9f767e7 --- /dev/null +++ b/config/sync/quick_node_clone.settings.yml @@ -0,0 +1,8 @@ +_core: + default_config_hash: 6XRelHPjACQVOo9yRQMmbXt-ysCA2Pt6l762bxQQbdw +langcode: fr +exclude: + node: { } + paragraph: { } +text_to_prepend_to_title: 'Clone of' +clone_status: false diff --git a/config/sync/user.role.admin.yml b/config/sync/user.role.admin.yml index 81e41af..606cffe 100644 --- a/config/sync/user.role.admin.yml +++ b/config/sync/user.role.admin.yml @@ -18,6 +18,7 @@ dependencies: - filter - locale - node + - quick_node_clone - system - toolbar _core: @@ -35,6 +36,10 @@ permissions: - 'administer nodes' - 'administer users' - 'change own username' + - 'clone actualite content' + - 'clone partenaire content' + - 'clone site content' + - 'clone static content' - 'create actualite content' - 'create content translations' - 'create partenaire content' diff --git a/config/sync/user.role.editeur.yml b/config/sync/user.role.editeur.yml index 0c737c7..2329451 100644 --- a/config/sync/user.role.editeur.yml +++ b/config/sync/user.role.editeur.yml @@ -15,6 +15,7 @@ dependencies: - filter - locale - node + - quick_node_clone - system - toolbar id: editeur @@ -27,6 +28,7 @@ permissions: - 'access site in maintenance mode' - 'access toolbar' - 'administer nodes' + - 'clone site content' - 'create actualite content' - 'create content translations' - 'create partenaire content' diff --git a/web/modules/custom/q2d_mod/src/Plugin/Block/PrevNextSite.php b/web/modules/custom/q2d_mod/src/Plugin/Block/PrevNextSite.php new file mode 100644 index 0000000..5481e00 --- /dev/null +++ b/web/modules/custom/q2d_mod/src/Plugin/Block/PrevNextSite.php @@ -0,0 +1,85 @@ +getParameter('node'); + if ($node) { + $nodetype = $node->getType(); + if($nodetype === "site"){ + $num = $node->get('field_numero')->getString(); + $allSites = \Drupal::entityTypeManager()->getStorage('node') + ->loadByProperties(['type' => 'site', 'status' => 1]); + + + + usort($allSites, function($a, $b){ + $numA = $a->get('field_numero')->getString(); + $numB = $b->get('field_numero')->getString(); + if ($numA == $numB) { + return 0; + } + return ($numA < $numB) ? -1 : 1; + }); + $prevnode = null; + $nextnode = null; + foreach($allSites as $index => $site){ + $n = $site->get('field_numero')->getString(); + if($n === $num){ + $prevnode = $index - 1 >= 0 ? $allSites[$index - 1] : null; + $nextnode = $index + 1 < count($allSites) ? $allSites[$index + 1] : null; + break; + } + } + + $return = [ + '#cache' => [ + 'max-age' => 0, + ] + ]; + + if (isset($prevnode)) { + $prev_link_title = Markup::create('Précédent'); + $prev_options = ['absolute' => FALSE, 'attributes' => ['class' => 'prev-site']]; + $prev_link_object = Link::createFromRoute($prev_link_title, 'entity.node.canonical', ['node' => $prevnode->id()], $prev_options); + $return[] = $prev_link_object->toRenderable(); + } + + if (isset($nextnode)) { + $next_link_title = Markup::create('Suivant'); + $next_options = ['absolute' => FALSE, 'attributes' => ['class' => 'next-site']]; + $next_link_object = Link::createFromRoute($next_link_title, 'entity.node.canonical', ['node' => $nextnode->id()], $next_options); + $return[] = $next_link_object->toRenderable(); + } + } + } + + return $return; + // return [ + // '#markup' => $this->t('Hello, World!'), + // ]; + } + public function getCacheMaxAge() { + return 0; + } +} \ No newline at end of file