Hot answers tagged

5

The standard way to inject services in other services is passing dependencies directly through the constructor: mymodule.services.yml: services: mymodule.foo_service: class: Drupal\mymodule\FooService arguments: ['@current_user'] While you can define a factory method in *.services.yml, see https://symfony.com/doc/current/service_container/...


4

Could be a caching issue within the browser, Drupal or both. For the browser set cache headers in the response, see https://drupal.stackexchange.com/a/278703/47547. For Drupal caching add a cache context user.roles: $response->getCacheableMetadata()->addCacheContexts(['user.roles']); Furthermore it is recommended to execute a redirect event ...


3

Entity query respects access by default. Add the ->accessCheck(FALSE) method to prevent access checking. Be careful, removing access checks may expose restricted data. It may be better to configure view permissions or whatever access system you're using to allow anonymous users to access content instead of removing the check.


2

A custom content block has no unique machine name, only a bundle type, an UUID and an ID. Only custom content blocks placed in a region have a machine name, but this is NOT the machine name of the block, it is the machine name of the block placement (configuration)


2

I use the patch method mentioned on https://www.drupal.org/docs/develop/using-composer/using-drupals-composer-scaffold#toc_4 e.g: "name": "my/project", ... "scripts": { "post-drupal-scaffold-cmd": [ "cd docroot && patch -p1 <../patches/htaccess-ssl.patch" ] } Then if the core file changes it will either merge correctly or the patch ...


2

Looks like Views Infinite Scroll is a good option for you: Views infinite scroll allows you to load and display pages of any view inline, using AJAX (this has been called infinite scrolling, load more, autopaging, endless pages and more). The pager can be triggered with the press of a button or automatically as the user scrolls to the bottom of the view'...


2

How todo it custom in code such as in a hook_form_alter $form['something'] = [ "#title" => t('@title', ['@title' => 'My Title'), "#type" => "details", "#group" => "advanced", "#weight" => 50, ]; // Add fields to the group. $form['something']['text'] = [ "#title" => t('@title', ['@title' => 'test'), "#type" => "textfield",...


2

The Easy way in Views UI add field_link 2 times. in 1) Exclude from display, Select url only, and Show url as plain text. which will give you the url only. in 2) Exclude from display, and REWRITE RESULTS -> Strip HTML tags which will give you the title only. Then in a custom field you can use twig URL: {{ field_link }} Url Title: {{ field_link_1 }} ...


2

Based on the comments above from leymannx, I've manually uploaded Pathauto 1.6 to my site via FTP. Returning to /update.php, I got the option to update the database and that worked and my site is back up again. Note: The first time I tried this, I renamed the old Pathauto module folder to "pathauto_old", and uploaded the new version to a newly created ...


2

You can pass down your region's ID as parameters to your route. For example: <a class="use-ajax" data-dialog-options="{&quot;width&quot;:550, &quot;dialogClass&quot;: &quot;my-region-class&quot; }" data-dialog-type="modal" href="/route/to/custom/form/this-region">...</a> As explained here you can add arguments from the ...


2

The latest version of Field Group module supports putting fields into the sidebar (at least for nodes). Field Group version >= 3.0-rc2, containing issue 2652642


2

To use state for checkboxes element, you should target the specific element by JQuery selector, all elements they have the name="field_select_shipping" with value attribute different so try to target the input with both attributes try with the following to show adresse_home only if home and colissimo checkbox checked: $form['input']['adresse_home'] = [ ...


1

A list of services are also available on drupal.org https://api.drupal.org/api/drupal/services/8.9.x


1

What you are looking for is called theme suggestions you can implement your own or alter existing ones. In this case since the theme hook is provided by another module (core) you need to alter the provided suggestions and add your own. Check this post with useful examples. Also core's always have excelent examples (Bartik theme example). /** * Implements ...


1

For now I solved this by creating a seperate global role which stays in the default shared config. I added the editor role to the conditional (graylist) section (configured per subsite) using config_split. So that way I am able to have seperate permissions for that role. That global role can be automatically assigned to a subsite user during a new subsite ...


1

create exposed form filters template following this naming standard: views-exposed-form--{view-name}--{display-name}.html.twig to get the view-name you can get from Backoffice (Structure > Views > search for your view > then get machine name and repalce the underscore with dash - see image bellow) so we get this template: views-exposed-form--media-...


1

It depends a little on how your Paragraph is structured. Is it a single paragraph type with multiple generic fields in it or a paragraph with multiple other paragraph types inside of it? If it's the latter, you have to create two twig files (For the parent and the child) but you can control output for each row and the contents of each row. Alternatively, ...


1

Custom blocks do not have machine name since they are content entities. What you can do is to check the bundle of the block in your field formatter. public function viewElements(FieldItemListInterface $items, $langcode) { if ($items->isEmpty()) { return NULL; } $entity = $items->first()->getEntity(); if ($entity->...


1

AFAIK core's does not support (and could take a while to do so) keyed based translation (like Symfony or other do). Theres an idea queued but seems to fall on deaf ears.


1

After a bit of struggle and research, here is the approach taken - custom_module.install file - /** * Enable translation for workbench_reviewer field. * Implements hook_update_n. */ function hook_update_xxxx() { $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager(); $field_storage_definition_node = $...


1

The text of the submit button depends only on the translation settings of the status field. If the field "Publishing status" is not translatable for the content type, the button says "Save (all translations)". You can change the language settings for content types, taxonomy vocabularies, user profiles here: /admin/config/regional/content-language


1

As with most things you are learning. The answer is often simpler than first thought. To resolve my issue I was able to use hook_form_alter and implement my own submission handler. From here I was able to disable the redirect to prevent the page reloading. Once redirect was disabled then my block plugin was able to get access to the form and use the ...


1

You can render a views block within another views page. E.g. you want to show 10 nodes in total, and 1 of them in full mode: Duplicate the existing view display as a new display of type "block". (Do not duplicate the entire view, only the sub-display by using "Duplicate as block"). In the original page display, in the Pager section, limit the number of ...


1

A file that comes in from a browser's Web API as a Blob is probably base64-encoded. PHP will not decode files in the POST or GET parameters. It is up to the PHP application to decode the file before saving. if (!empty($payload['blobFile'])) { $name = str_replace(' ', '_', $payload['fileName']); $file = file_save_data(base64_decode($payload['blobFile']), ...


1

Take a look to \Drupal\views\Plugin\views\field\FieldPluginBase::renderText /** * {@inheritdoc} */ public function render(ResultRow $values) { $tokens = $this->getRenderTokens($this->options['text']); return [ '#theme' => 'custom_button', '#target' => $this->options['target'], '#class' => $this->options['class'], '#...


1

Drupal 8 doesn't cache Ajax forms anymore, so you can't get properties of the form object set in the initial form build. see Bypass form caching by default for forms using #ajax. Forms are only cached as rendered form. Put the entity id in a hidden form element to load the entity before saving. Add the entity cache tag to the form if you use default values ...


1

I have found how to resolve this specifically if using the Tailwind framework, which I am. You can use the @apply function of the framework to add classes based on common Drupal class names, or ones you specify in your custom html.twig files. Documentation here: https://tailwindcss.com/docs/functions-and-directives/#apply I am using the Tailwind Starter ...


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