Skip to main content
Commonmark migration
Source Link

TL:DR; you need to overwrite the link_generator to change this behavior.

Drupal 8 uses the link generator for this. You can take a look at

Drupal\Core\Utility\LinkGenerator::generate if you want to know the code behind it all.

The key part is this:

elseif ($url->isRouted() && $url->getRouteName() === '<nolink>') {
  $generated_link = new GeneratedNoLink();
  unset($attributes['href']);
}

If you take a look at GeneratedNoLink you will see

/**
 * This class holds a <span> generated from the <nolink> route.
 */
class GeneratedNoLink extends GeneratedLink {

  /**
   * {@inheritdoc}
   */
  const TAG = 'span';

}

So you need to implement your own no link class and not unset the href and everything should be fine. Doing so you more or less need to copy most of the logic in Drupal\Core\Utility\LinkGenerator::generate to determine when no link should be used.

##Note

Note

Links/urls can be generated in various ways, some use link_generator, some use url_generator, some use the link RenderElement. In your case it looks like the link_generator is used, but that could be changed by custom theme/module.

TL:DR; you need to overwrite the link_generator to change this behavior.

Drupal 8 uses the link generator for this. You can take a look at

Drupal\Core\Utility\LinkGenerator::generate if you want to know the code behind it all.

The key part is this:

elseif ($url->isRouted() && $url->getRouteName() === '<nolink>') {
  $generated_link = new GeneratedNoLink();
  unset($attributes['href']);
}

If you take a look at GeneratedNoLink you will see

/**
 * This class holds a <span> generated from the <nolink> route.
 */
class GeneratedNoLink extends GeneratedLink {

  /**
   * {@inheritdoc}
   */
  const TAG = 'span';

}

So you need to implement your own no link class and not unset the href and everything should be fine. Doing so you more or less need to copy most of the logic in Drupal\Core\Utility\LinkGenerator::generate to determine when no link should be used.

##Note

Links/urls can be generated in various ways, some use link_generator, some use url_generator, some use the link RenderElement. In your case it looks like the link_generator is used, but that could be changed by custom theme/module.

TL:DR; you need to overwrite the link_generator to change this behavior.

Drupal 8 uses the link generator for this. You can take a look at

Drupal\Core\Utility\LinkGenerator::generate if you want to know the code behind it all.

The key part is this:

elseif ($url->isRouted() && $url->getRouteName() === '<nolink>') {
  $generated_link = new GeneratedNoLink();
  unset($attributes['href']);
}

If you take a look at GeneratedNoLink you will see

/**
 * This class holds a <span> generated from the <nolink> route.
 */
class GeneratedNoLink extends GeneratedLink {

  /**
   * {@inheritdoc}
   */
  const TAG = 'span';

}

So you need to implement your own no link class and not unset the href and everything should be fine. Doing so you more or less need to copy most of the logic in Drupal\Core\Utility\LinkGenerator::generate to determine when no link should be used.

Note

Links/urls can be generated in various ways, some use link_generator, some use url_generator, some use the link RenderElement. In your case it looks like the link_generator is used, but that could be changed by custom theme/module.

added 252 characters in body
Source Link
googletorp
  • 35.4k
  • 10
  • 69
  • 109

TL:DR; you need to overwrite the link_generator to change this behavior.

Drupal 8 uses the link generator for this. You can take a look at

Drupal\Core\Utility\LinkGenerator::generate if you want to know the code behind it all.

The key part is this:

elseif ($url->isRouted() && $url->getRouteName() === '<nolink>') {
  $generated_link = new GeneratedNoLink();
  unset($attributes['href']);
}

If you take a look at GeneratedNoLink you will see

/**
 * This class holds a <span> generated from the <nolink> route.
 */
class GeneratedNoLink extends GeneratedLink {

  /**
   * {@inheritdoc}
   */
  const TAG = 'span';

}

So you need to implement your own no link class and not unset the href and everything should be fine. Doing so you more or less need to copy most of the logic in Drupal\Core\Utility\LinkGenerator::generate to determine when no link should be used.

##Note

Links/urls can be generated in various ways, some use link_generator, some use url_generator, some use the link RenderElement. In your case it looks like the link_generator is used, but that could be changed by custom theme/module.

TL:DR; you need to overwrite the link_generator to change this behavior.

Drupal 8 uses the link generator for this. You can take a look at

Drupal\Core\Utility\LinkGenerator::generate if you want to know the code behind it all.

The key part is this:

elseif ($url->isRouted() && $url->getRouteName() === '<nolink>') {
  $generated_link = new GeneratedNoLink();
  unset($attributes['href']);
}

If you take a look at GeneratedNoLink you will see

/**
 * This class holds a <span> generated from the <nolink> route.
 */
class GeneratedNoLink extends GeneratedLink {

  /**
   * {@inheritdoc}
   */
  const TAG = 'span';

}

So you need to implement your own no link class and not unset the href and everything should be fine. Doing so you more or less need to copy most of the logic in Drupal\Core\Utility\LinkGenerator::generate to determine when no link should be used.

TL:DR; you need to overwrite the link_generator to change this behavior.

Drupal 8 uses the link generator for this. You can take a look at

Drupal\Core\Utility\LinkGenerator::generate if you want to know the code behind it all.

The key part is this:

elseif ($url->isRouted() && $url->getRouteName() === '<nolink>') {
  $generated_link = new GeneratedNoLink();
  unset($attributes['href']);
}

If you take a look at GeneratedNoLink you will see

/**
 * This class holds a <span> generated from the <nolink> route.
 */
class GeneratedNoLink extends GeneratedLink {

  /**
   * {@inheritdoc}
   */
  const TAG = 'span';

}

So you need to implement your own no link class and not unset the href and everything should be fine. Doing so you more or less need to copy most of the logic in Drupal\Core\Utility\LinkGenerator::generate to determine when no link should be used.

##Note

Links/urls can be generated in various ways, some use link_generator, some use url_generator, some use the link RenderElement. In your case it looks like the link_generator is used, but that could be changed by custom theme/module.

Source Link
googletorp
  • 35.4k
  • 10
  • 69
  • 109

TL:DR; you need to overwrite the link_generator to change this behavior.

Drupal 8 uses the link generator for this. You can take a look at

Drupal\Core\Utility\LinkGenerator::generate if you want to know the code behind it all.

The key part is this:

elseif ($url->isRouted() && $url->getRouteName() === '<nolink>') {
  $generated_link = new GeneratedNoLink();
  unset($attributes['href']);
}

If you take a look at GeneratedNoLink you will see

/**
 * This class holds a <span> generated from the <nolink> route.
 */
class GeneratedNoLink extends GeneratedLink {

  /**
   * {@inheritdoc}
   */
  const TAG = 'span';

}

So you need to implement your own no link class and not unset the href and everything should be fine. Doing so you more or less need to copy most of the logic in Drupal\Core\Utility\LinkGenerator::generate to determine when no link should be used.