Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Hot answers tagged

4

Assuming you're using Layout Builder on a Node, and you're using "overrides" to allow each content to have it's own unique layout, the data you're looking for is in the node__layout_builder__layout table. You can look there and see that it stores a reference to the "ID" of the entity, and the UUID of the content. So, in the case of a block, because you may ...


4

I can't help with the PHP filter and I don't think it is safe to use it in D8 by looking at the project's page. There are better solutions. You could for example add a Views Reference Field to the block type or use Twig Tweak in a template. You can also try to embed the View in the WYSIWYG text area, which is a bit more work to set up, but then should give ...


3

Although I've checked for other modules using hook_node_access, I forgot to check for hook_entity_access as well. It turned out that the "content moderation" module is denying access. Thanks @4k4 for making me revisit this! Just for the record, if you need to see which other modules are using a certain hook, you can use something like this: function ...


3

In your "task" module you must have a task_theme function where you've defined your templates. In there you'll need to update with your new paths too. e.g. This 'template' => "field--expire-date.html.twig" becomes: 'template' => "fields/field--expire-date.html.twig"


3

Use the Twig path() function and build a node route with the target id of the reference field: paragraph.html.twig {% if paragraph.field_example.target_id %} <a href="{{ path('entity.node.canonical', {'node': paragraph.field_example.target_id}) }}">{{ 'View node page'|t }}</a> {% endif %} See https://www.drupal.org/docs/8/theming/twig/...


3

here it is, tried it with a custom content block and a views block i executed the code in php/devel from devel_php module $storage = \Drupal::entityTypeManager()->getStorage('entity_view_display'); foreach ($storage->loadMultiple() as $display) { foreach ($display->getSections() as $section) { foreach ($section->getComponents() as $...


2

Every content type migration creates its own mapping table. I got a clue from how the taxonomy terms are migrated. The trick was to tell Drupal where to look for the nid. I replaced: process: nid: - plugin: get source: nid vid: - plugin: get source: vid with... process: nid: - plugin: migration_lookup ...


2

It looks like you're you doing an exposed filter and contextual filter for the type. As setArguments is for contextual filters and setExposedInput for exposed filters. If you've only got the exposed filter for type you should be able to remove setArguments and the 2nd argument on buildRenderable (which you dont need if you're doing setArguments) I've got ...


2

Your custom_upload migration is trying to create nodes; the custom_upload migration is taking a d6_upload source plugin: source: plugin: d6_upload ...and mapping it to a node:entity destination plugin: destination: plugin: 'entity:node' Since the d6_upload source doesn't have a title field to map to the node:entity field in the process definition of ...


2

The '$' isn't used in twig to designate a variable. This code should work: <a href="{{ path(route_name, {'node': route_parameters}) }}"> Link to the object with {{ route_name }} and {{ route_parameters }} </a>


2

You can try this instead {% if element['#items'][key].value == 'active' %}


2

You could use the Rewrite results option on that field and choose Strip HTML tags. This will "remove" the image from display. If you have some other HTML inside the Body that you want to keep you can enter them into the Preserve certain tags field, for example <em> <span> <p>.


2

Yes, inject the entity_type.manager service and load it that way: $url = $this->entityTypeManager ->getStorage('image_style') ->load('machine_name') ->buildUrl($path);


2

I had a project that needed some specific markup for different fields, using field.html.twig only at least saved managing multiple files. field.html.twig: {% set themeGroupOne = [ 'first_field', 'second_field', ] %} {% set themeGroupTwo = [ 'third_field', 'fourth_field', ] %} {# field markup option #} {% if field_name in ...


2

The code that is provided by the page that you linked to is wrong. While this hook exists in D7 and while it is possible that during early D8 core development, in alpha or beta, it existed at one point. In D8 there is no such thing as hook_prepare. As per the list of all D8 core hooks, it looks to me that hook got replaced with a newcomer hook called ...


2

This may do the trick in a hook_entity_presave(), or get you close: $old_dog = clone $dog; update_the_dog($dog); // Use == to allow for out of order keys. $same = $dog->toArray() == $old_dog->toArray(); This is kinda of cheating, and you may want to filter the arrays for just the fields and not the properties. It also isn't multilingual-safe. To ...


2

First of all, it is bad practice to use the PHP Filter that comes with core in D7 and the contributed module for D8. PHP Filter was removed from D8 core to prevent new Drupal devs from falling in this bad practice trap. Unfortunately, some evil genius decided to make a contrib module for D8. Have a read at What are the downsides of using PHP Filter code in ...


1

In your custom module add a folder src/Plugin/WebformHandler and create a file Subscription.php. Add the following code: <?php namespace Drupal\<mycustommodule>\Plugin\WebformHandler; use Drupal\Core\Form\FormStateInterface; use Drupal\webform\Plugin\WebformHandlerBase; use Drupal\webform\webformSubmissionInterface; /** * Form submission handler....


1

It should be possible with some code like this: function MY_MODULE_form_entity_browser_MY_FORM_form_alter(&$form, FormStateInterface $form_state, $form_id) { $form['#pre_render'][] = 'MY_MODULE_pre_render'; } function MY_MODULE_pre_render($element) { kint($element); //Find the tab you want to remove. if (...) { unset($element['...']); }...


1

The admin theme negotiator is tagged with a priority of -40: user.services.yml theme.negotiator.admin_theme: class: Drupal\user\Theme\AdminNegotiator arguments: ['@current_user', '@config.factory', '@entity_type.manager', '@router.admin_context'] tags: - { name: theme_negotiator, priority: -40 } So you have to use at least -39, since ...


1

Now it's in the routing.yml file at the root of your module : Here an example : example.routing.yml example.page_form: path: '/example' defaults: _form: '\Drupal\example\Form\ExampleForm' _title: 'Example' requirements: _access: 'TRUE' You can restrict by role too for example : requirements: _role: 'administrator+editor' Or by ...


1

If the content that you refer to is a node then you can use the twig path function as follows: <a href="{{ path('entity.node.canonical', {'node': content.id}) }}">{{ 'Example text'|t }}</a>


1

So you added this MY_EMAIL_FIELD to the form with form_alter. Add the following as well: $form['actions']['submit']['#submit'][] = 'MYMODULE_node_form_send_email'; Add another function to your file: function MYMODULE_node_form_send_email($form, FormStateInterface $form_state) { $email = $form_state->getValue('MY_EMAIL_FIELD'); // send email here } ...


1

A field added in the form_alter hook is not created on the entity. Therefore you cannot retrieve the value in either hook_entity_presave or hook_entity_insert. What you want however you can do by creating an additional submit handler for the form. function _MODULE_NAME_custom_submit_handler($form, FormStateInterface $form_state) { $email = $form_state-&...


1

You can add an extra validation step to those forms that checks and changes the value accordingly like so. function polaris_drupal_taxonomy_form_alter(&$form, FormStateInterface &$form_state, $form_id) { switch ($form_id) { case 'taxonomy_term_category_form': case 'taxonomy_term_article_type_form': case 'taxonomy_term_main_purpose_form'...


1

The private files point to the hostname where the backend server is, instead of pointing to the frontend server. Private files are not directly served to the user. Public files are served directly to the user. With a public file, when a file is requested, PHP is never executed, and therefore Drupal is never executed. By virtue of the files being public, ...


1

Find out which modules set session data by dumping these variables for anonymous requests: var_dump(\Drupal::request()->getSession()->all()); var_dump($_SESSION); You can ignore the symfony metadata starting with _symfony or _sf2. Then search the code base for session set() commands setting this data. You can then either change this code or remove ...


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