<?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;
  }

}
