ressources blocks in programmes #1295

This commit is contained in:
2021-07-01 21:57:21 +02:00
parent c7075326ef
commit 67b02aac45
25 changed files with 640 additions and 48 deletions

View File

@@ -0,0 +1,5 @@
name: 'popsu_link_block'
type: module
description: 'Create a block with dynamic link'
core_version_requirement: ^8.8 || ^9
package: 'Popsu'

View File

@@ -0,0 +1,24 @@
<?php
/**
* @file
* Contains popsu_link_block.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function popsu_link_block_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the popsu_link_block module.
case 'help.page.popsu_link_block':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Create a block with dynamic link') . '</p>';
return $output;
default:
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Drupal\popsu_link_block\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Url;
use Drupal\Core\Link;
/**
* Provides a 'ProgRessourceLink' block.
*
* @Block(
* id = "prog_ressource_link",
* admin_label = @Translation("Prog ressource link"),
* )
*/
class ProgRessourceLink extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$build = [];
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\Entity\Node) {
// You can get nid and anything else you need from the node object.
$nid = $node->id();
$url = Url::fromRoute("view.centre_de_ressources.page_1");
$url->setRouteParameter("programme", $nid);
$url->setOption('attributes', array("class"=>array('prog-ressources-link')));
$build['prog_ressource_link'] = array(
'#title' => "Ressources",
'#type' => 'link',
'#url' => $url,
);
$t="t";
}
return $build;
}
}