123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- use Drupal\Core\Template\Attribute;
- 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);
-
- }
- }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);
- }
- }
- }
- };
- function popsu_preprocess_region(&$variables) {
- if (isset($variables['region'])) {
- $variables['attributes']['class'][] = $variables['region'].'_container';
- }
-
-
-
-
-
- }
- function popsu_preprocess_views_view_field(&$variables){
-
- $settings = isset($variables['field']->options['settings']) ? $variables['field']->options['settings'] : false;
- if ($settings && isset($settings['link_to_entity']) && $settings['link_to_entity']) {
-
- $entity = $variables['row']->_entity;
-
-
- $new_classes = array(
- $entity->getEntityTypeId(),
- $entity->getEntityTypeId().'-'.$entity->bundle(),
- $entity->getEntityTypeId().'-'.$entity->bundle().'-'.$entity->id()
- );
-
-
- $link = $entity->toLink();
- $url = $entity->toLink()->getUrl();
-
- $url->setOption('set_active_class', true);
-
- $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);
-
- $link->setUrl($url);
-
- $variables['output'] = $link->toRenderable();
- }
- }
|