New answers tagged

0

You may have encountered a core bug where a page cache is not respecting the max-age, or in other words, max-age is not bubbling up to the page cache. There's a workaround on the issue summary but the workaround has a few problems of its own so make sure you consider the implications carefully. The bug issue is postponed until 3 of the linked issues are ...


0

Building on @adrianp, this is how you would do it for the form pages (edit/add). my_module.services.yml services: theme.negotiator.my_module: class: Drupal\my_module\Theme\MyModuleThemeNegotiator arguments: ['@config.factory'] tags: - { name: theme_negotiator, priority: 1000 } in my_module/Routing/MyModuleThemeNegotiator.php ...


1

The problem was that the twig cache path was not set for the project. See https://blog.jetbrains.com/phpstorm/2019/05/twig-and-blade-templates-debugging-2/


0

I would suggest you to firstly check if the data is stored in num_donateur variable successfully using $tempstore->get('num_donateur') If not stored then try to save it using \Drupal::service('tempstore.private'), As i have just googled it and seen user.private_tempstore is deprecated [ https://www.drupal.org/project/entity/issues/2951683 ] If data is ...


0

You should be able to set variables within hook_theme(). From the docs page: Variables: Only used for #theme in render array: an array of variables, where the array keys are the names of the variables, and the array values are the default values if they are not given in the render array. Template implementations receive each array key as a ...


0

Not sure it is still relevant after more than 2 years of inactivity, but I just wanted to point out that your approach isn't working most likely because the title is not a string but a Markup object which can't be modified. You need to create a new one and then assign it to the title variable. Your function should be something like this: function ...


1

In Drupal 8 you can do it by using Markup: use \Drupal\Core\StringTranslation\TranslatableMarkup; ... $message = new TranslatableMarkup('<b>@message!</b>', array('@message' => 'A bold error')); $form_state->setError($message); OR $mainMessage = "<em> the@email.com</em> is already in use. Have you forgotten your password?...


0

With the help of Clive's comment, I managed to identify the active theme suggestion. Code below. function mymodule_preprocess_field(&$variables, $hook) { $theme_suggestions = mymodule_get_theme_suggestions($hook, $variables); $active_suggestion = mymodule_get_active_theme_suggestion($theme_suggestions); } function mymodule_get_theme_suggestions(...


0

Bit late to the party here but here's how I just did it using Drupal 7. I have a paragraph type called Related Content (related_content) with 2 fields: An entity reference field and a Select (text) field called field_related_content_view_mode I have set the default display mode of the referenced entities / field_related content in the field display of the ...


0

I finally found the solution on the Drupal forum. I put it here, maybe it will help in the future a novice who will be in my case. What was missing was simply a list of essential javascripts for anonymous users. It seems that at one time it wasn't necessary, but now we have to add them otherwise they wouldn't be loaded for anonymous users. So what I needed ...


0

Using the following code to target the file name image source, I could hide one of the two images in the Views showing the current Node which had Image fields in. In this case, one .SVG filename exported from Inkscape was called "sales_discount_alt_mobile_2019" with 'mobile' the alt field from the Desktop graphic image. So in my Desktop @media CSS rule I ...


1

The field item list belongs to a field, so you need to render the list in a field template. Here's a basic example of a field template that renders each item keyed by its position in the list: {# field--yourfieldname.html.twig #} <ul> {% for item in items %} <li data-index="{{ loop.index }}"> {{ item.content }} </li> {% ...


0

For those ones experiencing the same case in Drupal 8, this is the equivalent solution: $user_input = $form_state->getUserInput(); unset($user_input['my_tableselect']); $form_state->setUserInput($user_input);


-1

try this in twig: {% set url = url('<current>')['#markup'] %} {% set urllast = url|split('/')|last %} {{ urllast }} // 3


0

In Drupal 7, there is a class like page-node-NID (with NID replaced by the node ID of the node being viewed) added to the tag so we can easily add CSS styles to specific nodes for example: body.page-node-NID{ background-color: red; } Drupal 8 is missing this core D7 functionality, but now there is a module for that, its called Body node ID class


0

Drupal 8 is missing this core D7 functionality, but now there is a module for that, its called Body node ID class


0

These kind of errors often happen when you have not attached the proper library to your form. So one thing to check is if you have $form['#attached']['library'][] = 'core/drupal.dialog.ajax'; in your form's buildForm().


1

You can create a custom block: https://www.drupal.org/docs/8/creating-custom-modules/creating-custom-blocks/create-a-custom-block In the build() method, you can return the form: public function build() { return \Drupal::formBuilder()->getForm('Drupal\system\Form\ThemeSettingsForm'); }


0

May you can use hooks: /** * Implements hook_preprocess_HOOK() for menu.html.twig. */ function mytheme_preprocess_menu(&$variables) { if ($variables['menu_name'] == 'main') { if (!isset($variables['attributes']['class'])) { $variables['attributes']['class'] = []; } $variables['attributes']['class'] = array_merge($variables['...


0

If you are in views and want to print node created datetime value in twig you need to: 1. If your views HAS outputted Field (Authored On): then {{ fields.created.content }} 2. If NOT: then {{ row._entity.created.value }}


0

There is a module for that™️: Use Display Field Copy From the module page: Display Field Copy provides the ability to make a display copy of a field with Display Suite. The copy of the field can use a different formatter (with different config) than the single field that is currently available in core. For instance, if a site has a single ...


0

When using the field module, I found this was better: in page--yourcontenttype.tpl.php: <?php $this_field_image = field_view_field('node',$node,'field_image'); print render($this_field_image);?> ?> using field_view_field() provides additional advantages whereby one can set an array of display settings: <?php $hide_labels = array('label'=...


0

The hook hook_mail_alter() should work in this case. Have you double checked if your module is activated and you have cleared your cache after adding the hook? Also i am not sure if your template will work, because normally all templates are working with dashes instead of underscores.


1

The following is called a tertiary operator. First, it renders the field page.emergency. Then it checks if the value is equal to ALL CLEAR' If it is, then show_emer_alert is set to N, otherwise it is set to Y. {% set show_emer_alert = 'ALL CLEAR' in page.emergency|render ? 'N' : 'Y' %} Tertiary operators act as follows. Imagine the following: $sex = ...


2

You find the block_content entity in the template variable elements to get the ID: block.html.twig: {{ elements.content['#block_content'].id() }}


0

My teammate figured this out: {{ content['dynamic_token_field:block_content-link_card_edit_block'] }}


0

Define a JS library with a dependency on the core/drupal.active-link library: mytheme/mytheme.libraries.yml remove-active-links: version: 1.x js: js/remove-active-links.js: { } dependencies: - core/jquery - core/drupal - core/drupal.active-link Then your JS code knows which link has an is-active class and you can add HTML or remove ...


0

This patch (https://www.drupal.org/files/issues/2019-02-26/order_receipt_payment_gateway_and_instructions.patch) from this thread (https://www.drupal.org/project/commerce/issues/2884497#comment-12988057) fixed my issue. It required patching commerce_order.module and commerce_payment.module, as well as adding the display code to the order email receipt twig.


0

For core/themes/classy/templates/navigation/menu.html.twig: {# /** * @file * Theme override to display a menu. * * Available variables: * - menu_name: The machine name of the menu. * - items: A nested list of menu items. Each menu item contains: * - attributes: HTML attributes for the menu item. * - below: The menu item child items. * - title:...


0

I guess Filebrowser module is what you looking for : This module provides an interface for administrators to expose directories on the file system to users through a file listing as in a FTP application. You will create one node (node type dir_listing) for each each Directory Listing (DL). Node settings are used to control access and other features of the ...


0

I'd do it like this. Example below is used for node templates: use \Drupal\views\Views; function MYTHEME_preprocess_node(&$variables) { // make the result count available as a variable for a certain content type if($node->getType() == 'news') { $view = Views::getView('related_news'); $view->setDisplay('default'); // contextual ...


0

You can do this directly in the form. Add this to the radios element: '#attributes' => [ 'attribute_name' = 'attribute_value' ],


1

I used twig_tweak module to load and render a block on any where in Drupal. Read more on the module docs: https://www.drupal.org/docs/8/modules/twig-tweak/rendering-blocks-with-twig-tweak


Top 50 recent answers are included