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} */ public function build() { // $config = $this->getConfiguration(); $build = []; $node = \Drupal::routeMatch()->getParameter('node'); if ($node instanceof \Drupal\node\Entity\Node) { // check if programme if($node->bundle() == 'programme'){ // if yes get id // todo set the hardcoded nid number as a parameter somewhere $nid = $node->id() == 6 ? $node->id() : false; } if($nid){ $title = "Le Palmarès Palpite"; $url = Url::fromRoute('entity.node.canonical'); // todo make the the hardcoded target nid as a parameter somewhere (recorded on the node ?) $url->setRouteParameter("node", 912); $url->setOption('attributes', array("class"=>array('prog-palpite-link'))); $build['prog_palpite_link'] = array( '#title' => $title, '#type' => 'link', '#url' => $url ); } } return $build; } }