Latest Drupal related questions

Score: 1
Ricardo Castañeda avatar
Schema insert row only if primary key doesn't exist
at flag

I'm doing an exercise where I have a table called visit_counter with fields uid (primary key that stores the user id) and user_visit_count (sum of user's page visits). The purpose of the table is to store the user id and to count the times the user visits the page that loads the controller.

My problem is that my if condition is not working well. I'm trying to insert the row with the uid (primary key,  ...

Score: 0
Glenn avatar
How to alter webform programmatically using hook_ENTITY_TYPE_prepare_form()
ph flag

Using Webform 6.2.0-beta5 on D10.0.9.

I have created a custom webform with a module; this is working perfectly.

Now I need to make several changes to the webform; some values will be calculated within my custom module, used as the default value for fields, and then the fields will be hidden.

With this code I can see the $webform details:

function mymodule_webform_submission_prepare_form(WebformSub ...
Score: 1
Tourist avatar
Display only the first child of a book
cn flag

I have a book "continent". Child are like this : Continent > Country > State >cities > Street

There are several countries, several states, several cities.

When I visit a State, a City or streets, I want to have a block to display the Country (the first child of the book).

What I tried to do in Views: Relationship : Book parent Contextual filters : Node ID with the relationship Book parent F ...

Score: 1
Advanced queue module: How to stop processing queue in cron, when some conditions apply in job event/job preprocessing?
fr flag

I have a custom module handling jobs from the Advanced Queue module. To limit the number of jobs allowed to be processed in one cron run, I have some configuration variables in my custom module. With an event listener my function gets called correctly, when the queue is processed.

How can I fetch the current running process of the queue and stop it?

public static function getSubscribedEvents() {
  $eve ...
Score: 1
Best way getting video url for paragraph on a node with a field video (media core)
bd flag

When I have a paragraph on a node with a field video (media core), is there another good practice to get the URL of the video?

I have this in the twig-file field--paragraph--field-video.html.twig:

file_url(item.content['#media'].field_media_video_file.entity.uri.value)

Or is there a better way in a field--paragraph--* file?

Score: -2
lolhonk avatar
Argument #1 ($callback) must be a valid callback, class Drupal\node\Entity\Node does not have a method "getCurrentUserId"
in flag

I upgraded from Drupal 8.9.20 to Drupal 9.59. All modules seem compatible (upgrade manager). The site is up and running, but if I try to add new content via node/add/article, this error appears.

TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, class Drupal\node\Entity\Node does not have a method "getCurrentUserId" in call_user_func() (line 400 of /html/core/lib/Drupal/Core/ ...

Score: 0
Why is my javascript settings variable empty in Chrome/Edge, but it works in Firefox?
br flag

My javascript file starts like this...

var my_global_var;

(function ($, Drupal, drupalSettings) {
  'use strict';

  Drupal.behaviors.myBehavior= {
    'attach': function attach(context, settings) {

      console.log(settings); // settings is empty in Chrome and Edge, but it works in Firefox.

...
    
})

(jQuery, Drupal, drupalSettings);

I add the settings in my block's build method...

  /**
 ...
Score: 1
Chanel avatar
Unable to reinstall Admin Toolbar in modules directory
mx flag

All my modules are in the web/modules/ directory except for Admin Toolbar which is in web/modules/contrib/. (Why? Long story, legacy site.) Admin Toolbar refuses to update now because of the inconsistency.

I temporarily changed the composer modules directory to web/modules/contrib/ and uninstalled the toolbar flushing the cache all along the way. I then removed the admin_toolbar directory and the ...

Score: 0
witti avatar
Showing parts of ajax-enabled forms in Dialog and using submit buttons in Dialog to change the form?
gr flag

I'd like to achieve the following (d10):

In a form a list of custom drupal plugins will be displayed. Each of those plugins has a settings form array depending on its type that will be merged into the form as part of the list of plugins.

Users can add plugins by clicking an ajax-enabled add-button that shows a dialog popup with buttons for each plugin. This is similar to what paragraphs does when se ...

Score: 1
Владимир Помелов avatar
Theming webform element label template for entity checkboxes field

In the webform, I use the Entity checkboxes component, which allows me to display the options I need using Views, depending on the node to which the webform is linked. But I lack flexibility in terms of setting up the output theme of these fields. In debugging mode, I saw that the markup I needed was inserted in the template "form_element_label.html.twig". How do I override this template for a webform wit ...

Score: 1
Dynamdilshan avatar
How to create a QueueWorker and run it without cron
in flag

Can someone please help me with an example on how to create a QueueWorker class, add items, and run it inside hook_ENTITY_TYPE_presave() or anywhere in a module file?

Basically, what I want is adding an item to the queue and run it soon after a node save, without waiting until the next cron runs.

Score: 0
Eric Sorum avatar
My site is not reading the custom page--user--login.html.twig files I created
gi flag

I am creating custom user (login) pages for my Drupal 9 sites. I have ensured that the files follow the Twig naming conventions and are in the correct folder:

app/web/sites/site-name/themes/our-uikit-theme/templates/user/page--user--login.html.twig

But the site is still reading the Twig file from the core theme directory. This is the path of the login page that the Twig debugging shows in the browse ...

Score: -2
eando avatar
Deleting a File from Website
eg flag

I host my municipality's website (lionsbay.ca) through Drupal. On this website, residents can find council minutes and agendas. Upon request of a resident, she would like her information removed from a past agenda file that was posted in 2021, however, I cannot seem to delete the file through the website. I've tried tracing the file path but I cannot seem to find the direct source of the file's location ...

Score: 3
File can not be copied during migration of media entity
in flag

I'm migrating pictures into Drupal (9) media entities (image). System is using AWS S3 for local storage. I have 2 migrations:

First migrates external images into drupal's files. It copies files from S3 bucket where export is to S3 bucket used as drupal local storage and registers the files.

Second is parsing same data source but creating image media entities from those previously migrated image file ...

Score: 1
sonfd avatar
Search API Solr: How to highlight search term in indexed HTML?
in flag

How can I configure Solr to index a search result view mode, and render that indexed content with the search terms highlighted without highlighting text in attributes?

We are indexing a "Search Result" view mode for every node and then using views to render that indexed content on a search results page. This view mode is very simple (see markup below). The problem is that if a search term appears  ...

Score: 0
Priya Degwekar avatar
Is it possible to not show extra box by default when Allowed number of values is Unlimited in Text (formatted, long, with summary)?
gb flag

I have created a long text formatted field with unlimited allowed number of values. But it is giving one extra box as default.

box

Every time user edits the content the empty box will show. That is so annoying. Second box should be appear only when I click on Add another item

Case1: (first edit) enter image description here

Case2: (second edit) enter image description here

It is creating issue after second edit. Anyone have any idea that How can I make this  ...

Score: 0
How to remove an uploaded file with JSON:API?
cn flag

I have an image field on the User entity that saves to the private filesystem. The field is limited to one image.

I can POST an image file to the field using JSON:API in accordance with this change record.

However, I cannot figure out how to delete a posted file. I don't want to upload a new file to replace it; I want to remove the file that was uploaded from the user. How can I do that?

Score: 0
Kernel test throws errors: field not found, and Base table or view not found:
fi flag

Here's the class I want to test:

class Thing {
  
    public function foo() {
      return \Drupal::entityQuery('node')->condition('body', 'blah')->execute();
    }
  
  }

And the test:

class footest extends \Drupal\KernelTests\KernelTestBase {

  public static $modules = ['node', 'user', 'field'];

 public function testFoo() {
   $thing = new Thing();
   \PHPUnit\Framework\assertEquals($th ...
Score: 0
Custom form, add admin editable instructions from settings area to form
za flag

I have a custom form that is working great. I'd like to add a field "instructions" right under the title, above the first form field. This "instructions" field is editable in the module settings area. I have tried to get this data like:

$config = $this->config('myform.settings');
$instructions = $config->getValue('instructions');

however, it throws an error:

Call to undefined method Drupal\Core\ ...

Score: 0
Patoshi パトシ avatar
Creating content on via REST API using POST: proper formatting of json?
kr flag

I'm trying to do a POST to create content on my site, but I get an Access Denied for creating field: changed even though I am an administrator role. When I remove the "changed" field in the JSON I get the Website encountered an unexpected error error. I assume my JSON format is incorrect. I got it from doing a GET on one of the published nodes, and just removed the nid and uuid values in the JSON.

 ...

Score: 0
Kevin avatar
Using StreamedResponse for AJAX?
in flag

I am looking for a way with a Form API form in Drupal to have an #ajax event on a form field. When submitted, this calls a remote API.

How can I stream the response out to the screen without the request being terminated before completing the stream read?

I thought maybe I could do this in the #ajax callback:

  /**
   * {@inheritdoc}
   */
  public function getResponse(array &$form, FormStateInterface ...
Score: 2
liquidcms avatar
How to create a group of sub tokens off an entity type?
us flag

I am trying to create sub tokens in a group off of existing Users token (sometimes referred to as "chaining"). So there are 2 parts to this. Creating the subgroup off the existing User tokens group and creating tokens within that group. I really only need the hook_token_info() part of this; not the actual token code.

I am trying to create a set of tokens of the form: [user:state:{token_id}]. Exam ...

Score: 0
Override a field in a taxonomy terms view
us flag

I have a taxonomy terms view, filtered by a vocabulary. I would like to add the dashes before the term name like in the Parent terms field on the edit term page. The code in TermForm.php does that when creating $options using str_repeat based on the item's depth.

This is the code from TermForm.php:

$tree = $taxonomy_storage->loadTree($vocabulary->id());
$options = ['<' . $this->t('root' ...
Score: 0
Anders avatar
Is it ok to share a comment field with multiple content types?
bo flag

Imagine I want to convert individual forum threads (topic + comments) into a content type 'Blog post' to preserve them for the long term.

In order to make this work, the comment field of 'Blog post' needs to be identical to that of 'Forum topic' (this is a limitation of the conversion module currently in beta). Thus I simply re-used the comment type comment_forum also for 'Blog post', which works fine.

Score: 0
Alex avatar
Replace Tokens from Webform Submission in DOCX
ua flag

This is my first question here at Drupal Answers and I try to be as precise as possible.

I'm using Drupal 9 and the current version of the webform module. What I am trying to do is replacing tokens (placeholders) in a DOCX file with values submitted with a webform.

To get this work I wrote a custom Webform Handler. This handler provides a file upload where I submit the DOCX that contains the placeho ...

Score: 0
Config split is imported only every second time of jenkins job run
ng flag

I have some weird behavior with drush cim when running from a jenkins job. It seems like a config split is only imported every second time or so when the job is run. The update skript containing the drush cim does work fine on local ddev sites and with other splits on other environements.

Jenkins does the following:

export stage=dev
sites=$(find "$project_dir"/web/sites/ -name "*.domain.de" -type l -p ...
Score: 0
My product variation is not shown on the entity form
kn flag

I have many products coming from a migration. This is working for most of the products, but for some of them, the /commerce/modules/product/src/Plugin/Field/FieldWidget/SingleVariationWidget.php widget is empty.

First, I thought that the product didn't have any variation. Turns out, it does.

After some digging, I've found that the formElement function inside SingleVariationWidget isn't retrieving only th ...

Score: 0
Disable pre-populated fields in webform
in flag

I have form created with Webform module, some fields are enabled for pre-population, so in some cases I use URL parameters to pre-populate them.

The thing is that I need to forbid users to change pre-populated fields (ether to disable them, or to hide them).

I checked field conditions in Webform configuration, but there's no option for this.

How it's possible to resolve this?

Score: 3
Enable a module with sample config that depends on a theme
in flag

I have a submodule that provides some prepared configuration via config/install. The goal is to have devs enable that module to get a preconfigured set of content types complete with preconfigured fields, form displays, view displays, language settings, pathauto patterns, etc. The reason why this is all in a module and not a profile is because it's opt-in, i.e. devs may or may not want this preconfig ...

Score: 0
maynardsmith avatar
How to dynamically set Test mode for a Webform_CiviCRM Contribution using Stripe Payment Processor
jp flag

This is in Drupal 9.5, CiviCRM 5.60, Webform 6.1, Webform_CiviCRM 6.2.

I have a webform which is allowing a Contact to make a CiviCRM Contribution - for example a simple Donation. If I manually set the Contribution into Test mode, then I can perform the payment process with a test card number, without actual money being involved. I would like to be able to programmatically set Test mode during  ...

The Stunning Power of Questions

Much of an executive’s workday is spent asking others for information—requesting status updates from a team leader, for example, or questioning a counterpart in a tense negotiation. Yet unlike professionals such as litigators, journalists, and doctors, who are taught how to ask questions as an essential part of their training, few executives think of questioning as a skill that can be honed—or consider how their own answers to questions could make conversations more productive.

That’s a missed opportunity. Questioning is a uniquely powerful tool for unlocking value in organizations: It spurs learning and the exchange of ideas, it fuels innovation and performance improvement, it builds rapport and trust among team members. And it can mitigate business risk by uncovering unforeseen pitfalls and hazards.

For some people, questioning comes easily. Their natural inquisitiveness, emotional intelligence, and ability to read people put the ideal question on the tip of their tongue. But most of us don’t ask enough questions, nor do we pose our inquiries in an optimal way.

The good news is that by asking questions, we naturally improve our emotional intelligence, which in turn makes us better questioners—a virtuous cycle. In this article, we draw on insights from behavioral science research to explore how the way we frame questions and choose to answer our counterparts can influence the outcome of conversations. We offer guidance for choosing the best type, tone, sequence, and framing of questions and for deciding what and how much information to share to reap the most benefit from our interactions, not just for ourselves but for our organizations.