ressources blocks in programmes #1295
This commit is contained in:
@@ -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'
|
24
web/modules/custom/popsu_link_block/popsu_link_block.module
Normal file
24
web/modules/custom/popsu_link_block/popsu_link_block.module
Normal 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:
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user