Hot answers tagged

5

A Drupal URI starts with a stream wrapper like "public://" that indicates to Drupal how to handle that resource. Typically, the "public" stream wrapper is defined as "treat this resource as a local file within sites/default/files." Your module assets are not located within sites/default/files, so they cannot use the "public&...


3

My first guess would be an incorrect targeting of the submit button when the user is logged in (be aware that Drupal adds a lot of elements to the DOM when being logged in). I'd highly recommend you to use the right method and build your form with the form API, though. Your block build code would look like this: public function build() { $form = \...


3

Try letting Drupal generate the module path: $modulePath = \Drupal::service('module_handler')->getModule('MYMODULE')->getPath(); $imagePath = $modulePath . "/images/my-image.jpg";


3

You don't necessarily need to turn off aggregation if you want to remove all javascript. You could for example remove the placeholder in the html template, then the (already aggregated) javascript won't be replaced in the html page: function mymodule_preprocess_html(&$variables) { if (MODULE_get_headers()) { unset($variables['#attached']['...


3

The Watchdog to File module is handy for this use case. You can initialize it in a test setup, like so: <?php namespace Drupal\Tests\my_module\Functional; use Drupal\Tests\BrowserTestBase; /** * My browser tests. */ class MyBrowserTest extends BrowserTestBase { /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $...


2

Good use of git branching can definitely help with this. The key thing is that each individual branch has a stable configuration basis: nothing external to the branch should change the configuration state within the branch, so that later when it's time to export configuration in the branch and merge it into production, only the changes relevant to the branch ...


2

In Drupal 8 you may define your own logger implementation to do whatever you want with log messages. The default logger provided by core Drupal saves these messages in the Drupal database and makes them available in the UI at /admin/reports/dblog. This default logger is implemented in the core dblog module by the logger class \Drupal\dblog\Logger\DbLog, and ...


1

It's important to note that Drupal 9.2 broke the simple way of doing it: $response = new RedirectResponse($path); $response->send(); You have to use the full code from the drupal_goto() changelog, namely: $response = new RedirectResponse($url->toString()); $request = \Drupal::request(); // Save the session so things like messages get saved. $request-&...


1

The Diff module can only compare fields for which a @FieldDiffBuilder class is implemented for that field and that class offers options for comparing that field. For example, for a comment field, the Diff module implements the CommentFieldBuilder class, for which the options are given by CommentFieldBuilder::buildConfigurationForm(). $form['compare_key'] = ...


1

Easiest solution is to use the Metatag module, indeed. For a full code solution, I'd recommend you to have a look at core/themes/classy/templates/layout/html.html.twig file (which is the default html template used by Drupal if your theme does not override it) for clues concerning template variables. The variable you want to alter is head_title which, as ...


1

You need to use the THEMENAME.theme file to store this in.


1

With the select2 widget the #default_value' is an array so try with $form['field_name']['widget']['#default_value'] = [12]; It will work!


1

The code shown on comment #2 in Get the token bearer with the JWT module after log in rest method is the code for an event subscriber class. What that comment doesn't show is the definition of the event subscriber service. As described in Subscribe to and dispatch events / Drupal 8 Events, the .services.yml file should contain lines similar to the following ...


1

This is very easy to do in D8 Rules. The advantage you get from using Rules is that you don't have to write code and it doesn't take a custom module or developer to change the action if your needs change in the future. In this way Rules is like Views - you can either program this functionality or you can make it available to the UI for easy building and ...


1

To Avoid spam keywords on Webforms with field. just check this out, https://www.drupal.org/project/webform_spam_words Administrators can provide the ability to add spam keywords, Error message, Webform field name.


1

The answer 4k4 gave was the right one: Language switching is based on language detection methods and what you've described are simply two different methods you have enabled. Normally you only need the path based method. If you have multiple methods enabled you have to be prepared that they are used depending on the context the page is built in.


1

Not that complicated and you don't need Views. Most of the functionality is right there, built-in, you only need to add your own bits. Filtering In addition to EntityListBuilder, create a form of the filter to be exposed. Just create a usual form extending FormBase, building whatever UI you need (eg. a dropdown with items to select from, with Filter and ...


1

I would use a Queue. You can check https://api.drupal.org/api/drupal/core!core.api.php/group/queue/8.9.x for more information. The point is each item will be processed one at a time, by timed chunks (30 seconds in my example). So the queue will process as many items it could in a 30 seconds span (or less, or more, you can adapt this in the annotation), then ...


1

For Drupal 8 you can do. /** * Implements hook_page_attachments(). */ function mymodule_page_attachments(array &$page) { $page['#attached']['drupalSettings']['myname'] = 'himanshu'; } (function ($, Drupal, drupalSettings) { /** * @namespace */ Drupal.behaviors.mymoduleAccessData = { attach: function (context) { var data = ...


1

Under 'Download options' you can limit the CSV to a submission id.


1

The difference could be that managed_file is using Ajax which is caching the form object. If you want to have this property cached you would need to declare it as protected property: class CustomForm extends ConfigFormBase { protected $config; Normally $this->config() is the method FormBase::config as the main entry point to the config API, not a ...


1

An additional workaround to this is you can add a tag to the entity query and then alter it in a separate hook_query_TAG_alter hook. It's an extra step but it gets the job done and gives you direct access to the SQL query for you to modify. So you can generate the entity query like you normally would, and any extra SQL that it does not support you can modify ...


1

I found a solution to this problem. Apparently if you have active "Clean wrapper for (x region)" on your theme, it will use that damn nowrap template no matter what. Disabling that goes back to use your default theme templates. You can find it over: /admin/appearance/settings/themeName Screenshot to follow:


1

I've found it preferable to pass the entity object instead of manually setting the IDs yourself: $node->field_qs_and_as[] = $paragraph; $node->save(); Only make one call to $node->save() of course, after you've added/edited all the paragraph entities you want. The primary reason for this is that when I set the reference array values instead, at ...


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