added ressources link block in programme's bottom
This commit is contained in:
parent
f24ba9e0db
commit
6b4e101f84
@ -116,6 +116,7 @@ variant_settings:
|
|||||||
weight: 0
|
weight: 0
|
||||||
uuid: 9c5741a0-e8e2-4895-88a7-c36d3825e33c
|
uuid: 9c5741a0-e8e2-4895-88a7-c36d3825e33c
|
||||||
context_mapping: { }
|
context_mapping: { }
|
||||||
|
link_title: Ressources
|
||||||
c80f54a0-8f21-4c56-8341-eab59b009329:
|
c80f54a0-8f21-4c56-8341-eab59b009329:
|
||||||
id: 'entity_field:node:field_document'
|
id: 'entity_field:node:field_document'
|
||||||
label: 'Pour aller plus loin'
|
label: 'Pour aller plus loin'
|
||||||
@ -133,6 +134,16 @@ variant_settings:
|
|||||||
uuid: c80f54a0-8f21-4c56-8341-eab59b009329
|
uuid: c80f54a0-8f21-4c56-8341-eab59b009329
|
||||||
context_mapping:
|
context_mapping:
|
||||||
entity: node
|
entity: node
|
||||||
|
f5f0169e-5c85-4b7e-b726-abd246152f83:
|
||||||
|
id: prog_ressource_link
|
||||||
|
label: 'Prog ressource link'
|
||||||
|
provider: popsu_link_block
|
||||||
|
label_display: '0'
|
||||||
|
region: bottom
|
||||||
|
weight: 0
|
||||||
|
uuid: f5f0169e-5c85-4b7e-b726-abd246152f83
|
||||||
|
context_mapping: { }
|
||||||
|
link_title: 'voir toutes les ressources de [node:title]'
|
||||||
id: panels_variant
|
id: panels_variant
|
||||||
uuid: 9752d3e8-fdc6-419d-95bb-079a2c3088b3
|
uuid: 9752d3e8-fdc6-419d-95bb-079a2c3088b3
|
||||||
label: null
|
label: null
|
||||||
|
@ -3,8 +3,10 @@
|
|||||||
namespace Drupal\popsu_link_block\Plugin\Block;
|
namespace Drupal\popsu_link_block\Plugin\Block;
|
||||||
|
|
||||||
use Drupal\Core\Block\BlockBase;
|
use Drupal\Core\Block\BlockBase;
|
||||||
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
use Drupal\Core\Url;
|
use Drupal\Core\Url;
|
||||||
use Drupal\Core\Link;
|
use Drupal\Core\Link;
|
||||||
|
// use Drupal\Core\Utility\Token;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a 'ProgRessourceLink' block.
|
* Provides a 'ProgRessourceLink' block.
|
||||||
@ -16,27 +18,63 @@ use Drupal\Core\Link;
|
|||||||
*/
|
*/
|
||||||
class ProgRessourceLink extends BlockBase {
|
class ProgRessourceLink extends BlockBase {
|
||||||
|
|
||||||
|
public function blockForm($form, FormStateInterface $form_state) {
|
||||||
|
$form = parent::blockForm($form, $form_state);
|
||||||
|
|
||||||
|
$config = $this->getConfiguration();
|
||||||
|
|
||||||
|
$form['link_title_wrapper'] = [
|
||||||
|
'#type' => 'container'
|
||||||
|
];
|
||||||
|
|
||||||
|
$form['link_title_wrapper']['link_title'] = [
|
||||||
|
'#type' => 'textfield',
|
||||||
|
'#title' => 'Link title',
|
||||||
|
'#default_value' => isset($config['link_title']) ? $config['link_title'] : "Ressources",
|
||||||
|
'#element_validate' => array('token_element_validate'),
|
||||||
|
'#token_types' => array('node'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$form['link_title_wrapper']['token_tree'] = array(
|
||||||
|
'#theme' => 'token_tree_link',
|
||||||
|
'#token_types' => array('node'),
|
||||||
|
'#show_restricted' => TRUE,
|
||||||
|
'#global_types' => FALSE,
|
||||||
|
'#weight' => 90,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function blockSubmit($form, FormStateInterface $form_state)
|
||||||
|
{
|
||||||
|
parent::blockSubmit($form, $form_state);
|
||||||
|
$values = $form_state->getValues();
|
||||||
|
$link_title = $values['link_title_wrapper']['link_title'];
|
||||||
|
$this->configuration['link_title'] = $link_title;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function build() {
|
public function build() {
|
||||||
|
$config = $this->getConfiguration();
|
||||||
$build = [];
|
$build = [];
|
||||||
$node = \Drupal::routeMatch()->getParameter('node');
|
$node = \Drupal::routeMatch()->getParameter('node');
|
||||||
if ($node instanceof \Drupal\node\Entity\Node) {
|
if ($node instanceof \Drupal\node\Entity\Node) {
|
||||||
// You can get nid and anything else you need from the node object.
|
|
||||||
$nid = $node->id();
|
$nid = $node->id();
|
||||||
|
// $title = $config["link_title"];
|
||||||
|
$token_service = \Drupal::token();
|
||||||
|
$title = $token_service->replace($config["link_title"], array('node' => $node));
|
||||||
$url = Url::fromRoute("view.centre_de_ressources.page_1");
|
$url = Url::fromRoute("view.centre_de_ressources.page_1");
|
||||||
$url->setRouteParameter("programme", $nid);
|
$url->setRouteParameter("programme", $nid);
|
||||||
$url->setOption('attributes', array("class"=>array('prog-ressources-link')));
|
$url->setOption('attributes', array("class"=>array('prog-ressources-link')));
|
||||||
$build['prog_ressource_link'] = array(
|
$build['prog_ressource_link'] = array(
|
||||||
'#title' => "Ressources",
|
'#title' => $title,
|
||||||
'#type' => 'link',
|
'#type' => 'link',
|
||||||
'#url' => $url,
|
'#url' => $url
|
||||||
);
|
);
|
||||||
|
|
||||||
$t="t";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return $build;
|
return $build;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user