Skip to main content
added 144 characters in body
Source Link
florian_drupal
  • 375
  • 1
  • 5
  • 18

I want to alter url of a field and his display. The field is a taxonomy label with link to the entity. The default url is : taxonomy/term/{tid}

I wanto to chage with : my_specific_page?technologie={tid} (used to prepopulate exposed filter)

I tried with :

function MYTHEME_preprocess_field__field_technologie(&$variables, $hook){
  $element = $variables['element'];

  foreach ($variables['items'] as $item) {

    $route_name = 'entity.node.canonical';
    $params     = 39;

    $options = [
      'query' => ['technologie' => 27],
    ];
    $url = Url::fromRoute($route_name, array('node' => $params), $options);

    $item['content']['#url'] = $url;
  }
}

I think i need to replace routeName attribut, but how ?

Content type : "manage field" Content type : "manage field" Content type : "manage display" Content type : "manage display" Kint result $variables['element'] enter image description herekint

I want to alter url of a field and his display. The field is a taxonomy label with link to the entity. The default url is : taxonomy/term/{tid}

I wanto to chage with : my_specific_page?technologie={tid} (used to prepopulate exposed filter)

I tried with :

function MYTHEME_preprocess_field__field_technologie(&$variables, $hook){
  $element = $variables['element'];

  foreach ($variables['items'] as $item) {

    $route_name = 'entity.node.canonical';
    $params     = 39;

    $options = [
      'query' => ['technologie' => 27],
    ];
    $url = Url::fromRoute($route_name, array('node' => $params), $options);

    $item['content']['#url'] = $url;
  }
}

I think i need to replace routeName attribut, but how ?

enter image description here

I want to alter url of a field and his display. The field is a taxonomy label with link to the entity. The default url is : taxonomy/term/{tid}

I wanto to chage with : my_specific_page?technologie={tid} (used to prepopulate exposed filter)

I tried with :

function MYTHEME_preprocess_field__field_technologie(&$variables, $hook){
  $element = $variables['element'];

  foreach ($variables['items'] as $item) {

    $route_name = 'entity.node.canonical';
    $params     = 39;

    $options = [
      'query' => ['technologie' => 27],
    ];
    $url = Url::fromRoute($route_name, array('node' => $params), $options);

    $item['content']['#url'] = $url;
  }
}

I think i need to replace routeName attribut, but how ?

Content type : "manage field" Content type : "manage field" Content type : "manage display" Content type : "manage display" Kint result $variables['element'] kint

edited title
Link
florian_drupal
  • 375
  • 1
  • 5
  • 18

How to alterreplace url of taxonomy label linked to the entitylink?

Source Link
florian_drupal
  • 375
  • 1
  • 5
  • 18

How to alter url of taxonomy label linked to the entity?

I want to alter url of a field and his display. The field is a taxonomy label with link to the entity. The default url is : taxonomy/term/{tid}

I wanto to chage with : my_specific_page?technologie={tid} (used to prepopulate exposed filter)

I tried with :

function MYTHEME_preprocess_field__field_technologie(&$variables, $hook){
  $element = $variables['element'];

  foreach ($variables['items'] as $item) {

    $route_name = 'entity.node.canonical';
    $params     = 39;

    $options = [
      'query' => ['technologie' => 27],
    ];
    $url = Url::fromRoute($route_name, array('node' => $params), $options);

    $item['content']['#url'] = $url;
  }
}

I think i need to replace routeName attribut, but how ?

enter image description here