<?php

use \Drupal\Core\Url;
use \Drupal\Component\Utility\Unicode;

function template_preprocess_edlp_compositions_list(&$vars){

  $vars['compositions'] = array (
    '#theme' => 'item_list',
    '#items' => [],
  );
  foreach($vars['composition_entities'] as $entity){
    // get the url
    $url = Url::fromRoute('entity.composition.canonical', ['composition' => $entity->id()], ['absolute' => TRUE]);
    $title = $entity->getName();
    $vars['compositions']['#items'][] = array(
      '#title' => $title,
      '#type' => 'link',
      '#url' => $url,
      '#options'=>array(
        'attributes' => array(
          'data-drupal-link-system-path' => $url->getInternalPath(),
          'nid' => $entity->id(),
          'class' => ['composition-link'],
          'title'=>$title,
        ),
      ),
    );
  }

  $vars['compositions']['#items'][] = array(
    '#title' => t('New composition'),
    '#type' => 'link',
    '#url' => $vars['new_composition_url'],
    '#options'=>array(
      'attributes' => array(
        'data-drupal-link-system-path' => $vars['new_composition_url']->getInternalPath(),
        'class' => ['new-composition-link']
      ),
    ),
  );
}
