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

New answers tagged

0

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>.


0

Ok if all else fails here is a sneaky trick by setting a new form state object. use Drupal\Core\Form\FormState; ... $form_state = new FormState(); $form_state->set('name', $name); $form_state->set('user', $user); $render_array = \Drupal::formBuilder()->buildForm('\Drupal\mod\Form\MyForm', $form_state); ... // Example render. $response = new ...


0

this one worked: function THEMENAME_preprocess_html(&$variables) { //view name as body class $variables['view_title'] = ''; $route = \Drupal::routeMatch()->getRouteObject(); if ($route) { $view_title = $route->getDefault('_title'); $variables['attributes']['class'][] = 'view-' . $view_title; } }


0

By the way, all the hooks are listed here there doesn't appear one that fits the task tho. You can always add a custom validation to the field add form. /* * Implements hook_form_FORM_ID_alter() */ function mymodule_form_field_ui_field_storage_add_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state) { $form['#validate'][] = '...


0

Per 'No Sssweat's comment above, this was due to a small syntax error in a custom javascript file, viewable in console. Once corrected, the contextual links worked as intended.


0

This is the default template for a views-view-list.html.twig. Basically you've overwritten this template when you've created views-view-list--content-recent--block-1.html. {# /** * @file * Default theme implementation for a view template to display a list of rows. * * Available variables: * - attributes: HTML attributes for the container. * - rows: A ...


2

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 ...


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 ...


0

Checkbox fields value check in Twig templates for drupal 8: {% if node.field_checkbox['#items'].value == '1' %} <div class="only added when there are values"> {{ content.field_name }} </div> {% endif %} Thats works fine for me.


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"


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 ...


0

Although the whitespace control modifier is supposed to work for all {{ … }} prints, {% … %} statements and {# … #} comments I'd expect to make your sample work it needs to be put directly into the print like that: {% for item in items %} {{- item.content -}}{{- not loop.last ? ', ' -}} {% endfor %} Alternatively you could try to use the {% spaceless %} ...


2

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


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/...


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 ...


-4

After some research I found this is possible using Image Styles and Twig Tweak I created 2 image styles scale and crop: scale_crop_1000_1000 scale_crop_500_500 It is something like this: <img srcset="{{ node.field_image.entity.uri.value | image_style('scale_crop_1000_1000') } 1000w, {{ node.field_image.entity.uri.value | image_style('...


3

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 ...


2

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 $...


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>


0

Aggregator offer the possibility to add custom fetch/parser/process to update/override/remove actions on the global process. For example I managed to make aggregator deal with enclose url image. Their are several ways to do it with Drupal 8. I used a very simple one : Annotation. /** * Defines a default parser implementation. * * Parses RSS, Atom and ...


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 ...


0

As mentioned here, it might be because you are pointing your menu link to "" instead of <front>. There is also a module called menu by trail path, which might also solve your problem. That module sets the menu item to active if its the page you are currently on.


0

I couldn't get oknate's solution to work so I modified it. You can add it to your custom module file. /** * Implements hook_preprocess_html(). */ function MYMODULE_preprocess_html(&$variables) { // Add node ID if ($node = \Drupal::request()->attributes->get('node')) { $variables['attributes']['class'][] = 'page-node-' . $node->id(); }...


0

Today I had to struggle again with this problem and could solve it by disabling Xdebug. So to sum up this could help: increase memory_limit and max_execution_time update to latest PHP version (at least 7.1) make sure Xdebug is not enabled when saving the settings form (e.g. via browser extension or general xdebug settings on server/vm)


0

Old question, but I'm guessing you need to add the array for the item list. I was successful with: field_something/0/target_id: YOUR_VALUE_HERE I haven't found documentation on the slash in the field id, but it is an array notation. The above is equivalent to something like: $destination_values['field_something'][0]['target_id'] = YOUR_VALUE_HERE


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-&...


0

I have seen this error a couple of times. Usually it's related to the file system. Most of the times it has worked for me to change the permissions of the files directory to 777. Otherwise make sure that your private folder is accesible and exists.


0

We have ended up using the protected file module. File medias chosen to be protected are only accessible to authentified users. [https://www.drupal.org/project/protected_file][1]


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'...


0

In Drupal 8 : // Logs a notice \Drupal::logger('my_module')->notice($message); // Logs an error \Drupal::logger('my_module')->error($message); In Drupal 7 : // Logs a notice watchdog('my_module', $message, array()); // Logs an error watchdog('my_module', $message, array(), WATCHDOG_ERROR);


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 ...


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 ...


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, ...


0

You can't. The 302 response code will only redirect your AJAX request, not the browser page executing it. You'll need to your AJAX callback function implement the redirect in JS code instead.


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 ...


0

The pages that list content related to specific Taxonomy terms are created through views called Taxonomy term (usually at /admin/structure/views/view/taxonomy_term). You can control what those pages output by editing that Views. I usually disable that original View and Duplicate it to work on overrides, so I can always refer back to the original if ...


2

If you want to only override the field template. Try with with the following. Implement hook_theme like the following no needs for variables and file keys. /** * Implements hook_theme(). */ function myModule_theme($existing, $type, $theme, $path) { return [ 'field__parent_task' => [ 'template' => 'field--parent-...


1

Views Format: Fields I don't think there is a special separate field in Views UI for the Alt field. Alt text is part of the Image field data, stored with the content entity (not the file). So what you do is add another Image field to your Views, but configure it this way: Rewrite results Override the output of this field with custom text Check ...


0

In this article from Varnish explain how to remove the anonymous user sessions: https://www.varnish-software.com/wiki/content/tutorials/drupal/drupal_step_by_step.html#cookies If Varnish works fine, Drupal should not know that there are anonymous users around it.


2

You can use BaseFieldDefinition::setCardinality() for that, e.g.: $fields['fichier'] = BaseFieldDefinition::create('file') ->setLabel(t('Fichier attaché')) ->setSetting('file_directory', 'messagerie/fichier') // dossier d'upload ->setSetting('max_filesize', '10MB') // taille max du fichier ->setSetting('file_extensions', 'pdf doc txt xls ...


1

Set the cardinality to unlimited: ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)


-1

In Filter criteria you need to Add the tag (Taxonomy) fields to extract right values from views. Also remember to select expose this filter to visitors and selection type - Autocomplete. You can see attached screenshots below. I hope these will help.


0

As noted in the comments above, RedirectResponseSubscriber does alter redirects. Here's the relevant snippet: if (!($response instanceof SecuredRedirectResponse)) { try { // SecuredRedirectResponse is an abstract class that requires a // concrete implementation. Default to LocalRedirectResponse, which // considers only redirects to ...


1

Add the datasource (entity reference) as a exposed filter. Check the "allow multiple selections". Now, the user can add comma seperated tags (with autocompletion): Used search api 8.x-1.13 on drupal 8.6.16


0

For Drupal 8 I had to write custom properties to get my comments into the index. I followed this documentation https://www.drupal.org/docs/8/modules/search-api/developer-documentation/create-custom-fields-using-a-custom-processor And than queried my Entity in addFieldValues() Method. Like $object = $item->getOriginalObject()->getValue(); $...


1

Found an alternative solution, by using hook_views_pre_render and $view->attachment_after $view->attachment_after = array('#markup' => '<a href="/" title="Title" class="button">Button</a>');


0

I would enable the Facet API module first of all, which will give you the facet interaction with Search API. I would then point you towards a good, simple tutorial at https://medium.com/@swappyp20/creating-a-faceted-search-view-in-drupal-8-using-the-search-api-modules-2b2604ad37f4 Hopefully you should be able to sort it out from there.


0

Instead of /my-node have you tried this? Url::fromRoute('entity.node.canonical', ['node' => $node->id()], ['absolute' => TRUE])


Top 50 recent answers are included