diff --git a/config/sync/block.block.reha_contenudelapageprincipale.yml b/config/sync/block.block.reha_contenudelapageprincipale.yml index 75b2781..3f4f0c7 100644 --- a/config/sync/block.block.reha_contenudelapageprincipale.yml +++ b/config/sync/block.block.reha_contenudelapageprincipale.yml @@ -9,7 +9,7 @@ dependencies: id: reha_contenudelapageprincipale theme: reha region: content -weight: -5 +weight: -6 provider: null plugin: system_main_block settings: diff --git a/config/sync/block.block.reha_onglets.yml b/config/sync/block.block.reha_onglets.yml index 76bd769..80de468 100644 --- a/config/sync/block.block.reha_onglets.yml +++ b/config/sync/block.block.reha_onglets.yml @@ -7,7 +7,7 @@ dependencies: id: reha_onglets theme: reha region: content -weight: -6 +weight: -5 provider: null plugin: local_tasks_block settings: diff --git a/config/sync/block.block.reha_prevnextblock.yml b/config/sync/block.block.reha_prevnextblock.yml new file mode 100644 index 0000000..a7287ee --- /dev/null +++ b/config/sync/block.block.reha_prevnextblock.yml @@ -0,0 +1,20 @@ +uuid: 5cc94347-dd4a-4c9f-896f-27367c9542ac +langcode: fr +status: true +dependencies: + module: + - reha_mod + theme: + - reha +id: reha_prevnextblock +theme: reha +region: content +weight: -8 +provider: null +plugin: prevnext_block +settings: + id: prevnext_block + label: 'PrevNext Block' + label_display: '0' + provider: reha_mod +visibility: { } diff --git a/web/modules/reha_mod/reha_mod.info.yml b/web/modules/reha_mod/reha_mod.info.yml index 1eab22a..66861a2 100644 --- a/web/modules/reha_mod/reha_mod.info.yml +++ b/web/modules/reha_mod/reha_mod.info.yml @@ -3,3 +3,5 @@ type: module description: Provides additional functionality for the site. package: Custom core_version_requirement: ^9 || ^10 +dependencies: + - drupal:block \ No newline at end of file diff --git a/web/modules/reha_mod/reha_mod.module b/web/modules/reha_mod/reha_mod.module index c5f0fd6..8346d5b 100644 --- a/web/modules/reha_mod/reha_mod.module +++ b/web/modules/reha_mod/reha_mod.module @@ -23,4 +23,5 @@ function reha_mod_form_node_operation_form_alter(&$form, \Drupal\Core\Form\FormS if($type === 'operation'){ $form['field_adresse']['widget'][0]['#type'] = 'container'; } -} \ No newline at end of file +} + diff --git a/web/modules/reha_mod/src/Plugin/Block/PrevNext.php b/web/modules/reha_mod/src/Plugin/Block/PrevNext.php new file mode 100644 index 0000000..b92e96e --- /dev/null +++ b/web/modules/reha_mod/src/Plugin/Block/PrevNext.php @@ -0,0 +1,85 @@ +getParameter('node'); + if ($node) { + $nodetype = $node->getType(); + if($nodetype === "site"){ + $numerodesite = $node->get('field_numero_site')->getString(); + $allSites = \Drupal::entityTypeManager()->getStorage('node') + ->loadByProperties(['type' => 'site', 'status' => 1, 'field_type_de_site' => 1]); + + + + usort($allSites, function($a, $b){ + $numA = $a->get('field_numero_site')->getString(); + $numB = $b->get('field_numero_site')->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_site')->getString(); + if($n === $numerodesite){ + $prevnode = $index - 1 >= 0 ? $allSites[$index - 1] : null; + $nextnode = $index + 1 < count($allSites) ? $allSites[$index + 1] : null; + break; + } + } + + } + $return = [ + '#cache' => [ + 'max-age' => 0, + ] + ]; + + if ($prevnode) { + $prev_link_title = Markup::create('Site pilote 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 ($nextnode) { + $next_link_title = Markup::create('Site pilote 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