getCurrentLanguage()->getId(); $query = \Drupal::entityQuery('taxonomy_term') // ->sort('weight', 'DESC') // ->sort('name', 'DESC') ->condition('vid', 'entrees'); $tids = $query->execute(); // $terms = entity_load_multiple('taxonomy_term', $tids); // $terms = \Drupal::entityManager()->getStorage('taxonomy_term')->loadMultiple($t‌​erms); $terms = Term::loadMultiple($tids); $ordered_terms = []; foreach ($terms as $term) { // remove masqué $sid = WorkflowManager::getCurrentStateId($term, 'field_workflow'); if($sid == 'generique_masque') continue; // translate the term $term = \Drupal::service('entity.repository')->getTranslationFromContext($term, $language); $name = $this->stripAccent($term->getName()); $ordered_trans_terms[$name] = $term; } ksort($ordered_trans_terms); // dsm($terms); foreach ($ordered_trans_terms as $name => $term) { $tid = $term->id(); $entree = array( 'tid'=>$tid ); // term link $url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term'=>$tid]); $url->setOptions(array( 'attributes' => array( 'class' => ['term-'.$tid, 'term-link'], 'tid'=>$tid, 'selector' => 'entree-term-link-'.$tid, 'data-drupal-link-system-path' => $url->getInternalPath() ) )); $entree['term_link'] = Link::fromTextAndUrl($term->getName(), $url); // index link $url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term'=>$tid]); $url->setOptions(array( 'attributes' => array( 'class' => ['index-link', 'ajax-link'], 'viewmode'=>'index', 'tid'=>$tid, 'selector' => 'entree-index-link-'.$tid, 'data-drupal-link-system-path' => $url->getInternalPath() ) )); $entree['index_link'] = Link::fromTextAndUrl('index', $url); // notice-link $url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term'=>$tid]); $url->setOptions(array( 'attributes' => array( 'class' => ['notice-link', 'ajax-link'], 'viewmode'=>'notice', 'tid'=>$tid, 'selector' => 'entree-notice-link-'.$tid, 'data-drupal-link-system-path' => $url->getInternalPath() ) )); $entree['notice_link'] = Link::fromTextAndUrl('notice', $url); $entree['description'] = $term->get('description')->value; $entrees[] = $entree; } return array ( '#theme' => 'blockentrees', '#entrees_items' => $entrees, '#attached'=>array( 'library' => array('edlp_corpus/corpus'), 'drupalSettings' => array( 'basepath' => base_path() ) ) ); } private function stripAccent($str){ return strtr( utf8_decode($str), utf8_decode('àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ'), 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY'); } }