drupal 8

Add javascript

Submitted by root on Fri, 03/04/2022 - 07:50
Code
(function ($) { Drupal.behaviors.funtzioIzen = { attach: function (context, settings) { /* if(!$('#balio-modal-button').length) { $('#edit-group-balioak legend').append('<button id="balio-modal-button">Balioak erakutsi</button>'); }*/ } }; })(jQuery);

Get translated taxonomy

Submitted by root on Thu, 11/05/2020 - 16:31
Code
<?php $terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('vid', 0, NULL, TRUE); $current_langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); foreach ($terms as &$term) { if ($term->hasTranslation($current_langcode)) { $term = $term->getTranslation($current_langcode); } } ?>

Drupal links

Submitted by root on Mon, 09/21/2020 - 06:52
Code
<?php // Link use Drupal\Core\Link; $link = Link::createFromRoute('This is a link', 'entity.node.canonical', ['node' => 1]); // Url use Drupal\Core\Link; use Drupal\Core\Url; $link = Link::fromTextAndUrl('This is a link', Url::fromRoute('entity.node.canonical', ['node' => 1])); $link = Link::fromTextAndUrl('This is a link', Url::fromUri('base:robots.txt')); // External links $link = Link::fromTextAndUrl('This is a link', Url::fromUri('http://www.google.com')); // links with only the fragment (without url) $link = Link::fromTextAndUrl('This is a link', Url::fromUri('internal:#fragment')); // Using the data provided by a user $link = Link::fromTextAndUrl('This is a link', Url::fromUserInput('/node/1'); // The param passed to fromUserInput must start with /,#,? or it will throw an exception. // Linking entities. $link = Link::fromTextAndUrl('This is a link', Url::fromUri('entity:node/1')); // Entities are a special case, and there are more ways to link them: $node = Node::load(1); $link = $node->toLink(); $link->setText('This is a link'); // And even using the route: $link = Link::fromTextAndUrl('This is a link', Url::fromRoute('entity.node.canonical', ['node' => 1])); // Drupal usually expects a render array if you are going to print the link, so the Link object has a method for that: $link->toRenderable(); ?>