|
@@ -5,7 +5,8 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
use Drupal\Core\Template\Attribute;
|
|
use Drupal\Core\Template\Attribute;
|
|
-
|
|
|
|
|
|
+use Drupal\Core\Link;
|
|
|
|
+use Drupal\Core\Url;
|
|
|
|
|
|
// function popsu_preprocess_views_view_list(&$variables){
|
|
// function popsu_preprocess_views_view_list(&$variables){
|
|
// kint($variables);die();
|
|
// kint($variables);die();
|
|
@@ -133,48 +134,73 @@ function popsu_preprocess_views_view_grid(&$variables){
|
|
}
|
|
}
|
|
|
|
|
|
function popsu_preprocess_views_view_field(&$variables){
|
|
function popsu_preprocess_views_view_field(&$variables){
|
|
- // check if link to entoty option is true
|
|
|
|
|
|
+ // check if link to entity option is true
|
|
$settings = isset($variables['field']->options['settings']) ? $variables['field']->options['settings'] : false;
|
|
$settings = isset($variables['field']->options['settings']) ? $variables['field']->options['settings'] : false;
|
|
if ($settings && isset($settings['link_to_entity']) && $settings['link_to_entity']) {
|
|
if ($settings && isset($settings['link_to_entity']) && $settings['link_to_entity']) {
|
|
// get the entity and build the classes
|
|
// get the entity and build the classes
|
|
$entity = $variables['row']->_entity;
|
|
$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;
|
|
|
|
- }
|
|
|
|
|
|
+ // $entity_type = $entity->getEntityType();
|
|
|
|
+ if ($entity->getEntityType()->id() == "node" && $entity->id() == 5) {
|
|
|
|
+ // temporarely desactivate popsumonde link
|
|
|
|
+ // get the entity link and url
|
|
|
|
+ $link = $entity->toLink();
|
|
|
|
+
|
|
|
|
+ // // $url = $entity->toLink()->getUrl();
|
|
|
|
+ // $url = URL::fromUserInput('#');
|
|
|
|
+ // // update the url of the link
|
|
|
|
+ // $link->setUrl($url);
|
|
|
|
+
|
|
|
|
+ // overwrite the output
|
|
|
|
+ $variables['output'] = [
|
|
|
|
+ '#type' => 'html_tag',
|
|
|
|
+ '#tag' => 'span',
|
|
|
|
+ '#value' => $link->getText(),
|
|
|
|
+ '#attributes' => [
|
|
|
|
+ "class" => array(
|
|
|
|
+ $entity->getEntityTypeId(),
|
|
|
|
+ $entity->getEntityTypeId().'-'.$entity->bundle(),
|
|
|
|
+ $entity->getEntityTypeId().'-'.$entity->bundle().'-'.$entity->id(),
|
|
|
|
+ )
|
|
|
|
+ ]
|
|
|
|
+ ];
|
|
|
|
+
|
|
}else{
|
|
}else{
|
|
- $attributes = array(
|
|
|
|
- "class" => $new_classes
|
|
|
|
|
|
+ // build new classes
|
|
|
|
+ $new_classes = array(
|
|
|
|
+ $entity->getEntityTypeId(),
|
|
|
|
+ $entity->getEntityTypeId().'-'.$entity->bundle(),
|
|
|
|
+ $entity->getEntityTypeId().'-'.$entity->bundle().'-'.$entity->id(),
|
|
);
|
|
);
|
|
- }
|
|
|
|
- $url->setOption('attributes', $attributes);
|
|
|
|
|
|
+
|
|
|
|
+ // 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);
|
|
|
|
|
|
+ // update the url of the link
|
|
|
|
+ $link->setUrl($url);
|
|
|
|
|
|
- // overwrite the output
|
|
|
|
- $variables['output'] = $link->toRenderable();
|
|
|
|
|
|
+ // overwrite the output
|
|
|
|
+ $variables['output'] = $link->toRenderable();
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|