130 lines
3.7 KiB
Plaintext
130 lines
3.7 KiB
Plaintext
<?php
|
|
/*
|
|
* @files
|
|
* Theme Template Funtions
|
|
*/
|
|
|
|
use Drupal\Core\Template\Attribute;
|
|
|
|
/* implements template_preprocess_views_view() */
|
|
|
|
// function popsu_preprocess_views_view(&$vars) {
|
|
// $view = $vars['view'];
|
|
// kint($view);die();
|
|
// }
|
|
|
|
|
|
/* implements template_preprocess_views_view_unformatted() */
|
|
|
|
function popsu_preprocess_views_view_unformatted(&$variables) {
|
|
|
|
$view = $variables['view'];
|
|
if($view->id() == "programmes"){
|
|
$rows = $variables['rows'];
|
|
foreach ($rows as $id => $row) {
|
|
$variables['rows'][$id]['attributes'] = new Attribute();
|
|
$c = $variables['rows'][$id]['content']["#row"]->nid;
|
|
$variables['rows'][$id]['attributes']->addClass("popsu-node-".$c);
|
|
//kint($variables['rows'][$id]['content']["#row"]->nid);
|
|
}
|
|
}
|
|
// else{
|
|
// if ($view->current_display == "block_1") {
|
|
// $rows = $variables['rows'];
|
|
// foreach ($rows as $id => $row) {
|
|
// $variables['rows'][$id]['attributes'] = new Attribute();
|
|
// $c = $variables['rows'][$id]['content']["#row"]->nid;
|
|
// $variables['rows'][$id]['attributes']->addClass("popsu-node-".$c);
|
|
// }
|
|
// }
|
|
|
|
}
|
|
};
|
|
|
|
/* implements template_preprocess_region() */
|
|
|
|
function popsu_preprocess_region(&$variables) {
|
|
|
|
if (isset($variables['region'])) {
|
|
$variables['attributes']['class'][] = $variables['region'].'_container';
|
|
}
|
|
// if ($variables['region'] == 'footer_bottom_right') {
|
|
// if ($node = \Drupal::routeMatch()->getParameter('node')) {
|
|
// $t = $node->getType();
|
|
// }
|
|
// }
|
|
}
|
|
|
|
// function popsu_preprocess_field(&$variables){
|
|
// $v = $variables;
|
|
// }
|
|
|
|
|
|
|
|
// function popsu_theme_suggestions_views_view_alter(array &$suggestions, array $variables) {
|
|
// $v = $variables;
|
|
// $suggestions[] = 'views_view__headerView';
|
|
// }
|
|
|
|
/**
|
|
* Implements hook_preprocess_block().
|
|
*/
|
|
|
|
function popsu_preprocess_views_view_fields(&$variables){
|
|
|
|
$entity = $variables['row']->_entity;
|
|
if($entity->hasField('field_programme')){
|
|
$target_id = $entity->get('field_programme')->getString();
|
|
// kint($variables);die();
|
|
// $variables['row']['attributes'] = new Attribute();
|
|
// $variables['row']['attributes']->addClass("pouet-node-".$target_id);
|
|
}
|
|
|
|
}
|
|
|
|
function popsu_preprocess_views_view_field(&$variables){
|
|
// check if link to entoty option is true
|
|
$settings = isset($variables['field']->options['settings']) ? $variables['field']->options['settings'] : false;
|
|
if ($settings && isset($settings['link_to_entity']) && $settings['link_to_entity']) {
|
|
// get the entity and build the classes
|
|
$entity = $variables['row']->_entity;
|
|
|
|
// build new classes
|
|
$new_classes = array(
|
|
$entity->getEntityTypeId(),
|
|
$entity->getEntityTypeId().'-'.$entity->bundle(),
|
|
$entity->getEntityTypeId().'-'.$entity->bundle().'-'.$entity->id(),
|
|
);
|
|
|
|
|
|
|
|
// get the entity link and url
|
|
$link = $entity->toLink();
|
|
$url = $entity->toLink()->getUrl();
|
|
|
|
// set the active_class option to the url
|
|
$url->setOption('set_active_class', true);
|
|
|
|
// add new classes to the url (without overwriting existing once)
|
|
$options = $url->getOptions();
|
|
if(isset($options['attributes']) && $attributes = $options['attributes']){
|
|
if(isset($attributes['class']) && $classes = $attributes['class']){
|
|
$attributes['class'] += $new_classes;
|
|
}else{
|
|
$attributes['class'] = $new_classes;
|
|
}
|
|
}else{
|
|
$attributes = array(
|
|
"class" => $new_classes
|
|
);
|
|
}
|
|
$url->setOption('attributes', $attributes);
|
|
|
|
// update the url of the link
|
|
$link->setUrl($url);
|
|
|
|
// overwrite the output
|
|
$variables['output'] = $link->toRenderable();
|
|
}
|
|
}
|