Hot answers tagged

5

you can also use something like the following, it all depends of the type of object you are extracting and the field name, In my case it was a paragraph with a field named field_link and the following worked: {{ paragraph.field_link.get(0).getUrl().toString() }}


4

You will need to check if the $node variable is actually an instance of node object. if ($node instanceof \Drupal\node\NodeInterface) { // You can get nid and anything else you need from the node object. $nid = $node->id(); } See How do I get the current node ID?


3

Check the "Reverse Proxy Configuration" in settings.php: /** * Reverse Proxy Configuration: * * Reverse proxy servers are often used to enhance the performance * of heavily visited sites and may also provide other site caching, * security, or encryption benefits. In an environment where Drupal * is behind a reverse proxy, the real IP address of the ...


3

From the documentation for the Url class: In most cases, use Url::fromRoute() or Url::fromUri() rather than constructing Url objects directly in order to avoid ambiguity and make your code more self-documenting. So, generating a new Url object from a static method is preferred.


2

For a link enclosed in translatable text, Drupal core suggests to use t() and embed the HTML anchor tag directly in the translated string. In LinkGeneratorInterface::generate(), the example code for this case is the following. $text = t('Visit the <a href=":url">content types</a> page', array( ':url' => Url::fromRoute('entity.node_type....


1

It will easy if you convert link to url and use translate like this. $url = Url::fromUri('http://example.com')->toString(); t('Visit <a href=":href">link</a>', array(':href' => $url)); Example drupal core use translation with link. $requirements['online'] = array( 'title' => t('Internet'), 'value' => t('The translation ...


1

if you don't won’t to create a new token as @Clive mentioned in comment, you can use hook_pathauto_alias_alter in your custom module like the following. /** * Implements hook_pathauto_alias_alter(). */ function MY_MODULE_pathauto_alias_alter(&$alias, array &$context) { if ($context['module'] === 'node' && $context['bundle'] === '...


1

Use [current-page:query:foo] in Default Value field and set query string to node/1?foo=1,2 and it will work. Installing Tokens module will show you some values you can use in your default value field.


1

A different option: Add a class to your disabled links. Create a JS behavior that targets a.your-class and uses preventDefault() on the click event. Add to libraries file for your module and add library as needed. ... $('a.your-class').click( function (e) { e.preventDefault(); }); ...


1

I know it's horrible, but if nothing else works: {{ link|replace({'internal:':''}) }} My situation: accessing a Link field via an overridden views template: views-view-fields.html.twig I had to get the variable from: row._entity.field_machine_name.value.0.uri (I gave up trying to use the fields variable, you can seemingly get a .content property out of ...


1

In paragraph, to get the link url and link name - <a href="{{ content.FIELD_LINK_NAME[0]['#url']|render }}"> {{ content.FIELD_LINK_NAME[0]['#title']|render }} </a>


Only top voted, non community-wiki answers of a minimum length are eligible