Latest Drupal related questions

Score: 0
How do you remove a user role via a hook update?
id flag

I would like to remove a user role via a hook update in Drupal 9.

I believe I would need to do something like the below but unclear what other code might be needed.

$user->removeRole('administrator');
$user->save();
Score: 0
yuuuu avatar
Add a second RulesAction to a custom module
ao flag

I created a custom module containing one Rules Action that works perfectly. I tried adding a second by creating a second php file in the MODULE/src/Plugin/RulesAction folder, with the names and class etc all changed from the original action.

I've tried refreshing the cache, and uninstalling/installing the module but the new action is not showing up. Is there another step I need to take, other than just  ...

Score: 0
Евгений Батулин avatar
How to get id from context filter in views?

Please tell me how can I get the node id from the url in views? Is it possible to pull it out of the context filter so that after passing it to the form via the prepopulate module? I am creating a website for accounting books in the library. I have three types of materials: reader, book and issue. There are 4 fields in the issue: a link to the reader, a link to the book and two dates - issue and return. ...

Score: 0
Bass-Ninja avatar
Send message to users with certain field enabled with Message Module
ru flag

I would like to send/display a message in a block view on user profile when some content type node is created, but only if that user has a certain custom field enabled on their profile.

I have created the message template and used hook_node_insert() to send a message but the problem is it sends this message to all users if I(as an admin user) have the custom field enabled or doesn't if I have it  ...

Score: 1
What is the POST end point for taxonomy?
cn flag

I have a test script to create (POST) a term for a Tags vocabulary using cUrl. That simple script is working fine on Drupal 8.9.20, but it returns a 404 error on Drupal 9.3.0.

{"message":"No route found for 'POST \/entity\/taxonomy\/term\/taxonomy_term'"}

What is the POST end point for taxonomy terms?

I tried with different endpoints, but I get the same error message. In Drupal 8, they work.

Score: 0
Souvik Das avatar
Send email to author when content is published through scheduler
rs flag

I have used Scheduler module with content moderation integration to publish a content automatically. It is perfectly working using the module. Now I want to add a functionality that once the content is published via cron, an email will be sent to the author of that particular content.

I have used hook_scheduler_publish_action to perform this action, but unfortunately I am facing some different scen ...

Score: 2
Unique constraint on several entity fields fails when >1 jsonapi POST requests happen right after another
cn flag

In a fully decoupled drupal 9 project I have a custom entity type and added a unique constraint for several fields just as described here. This works well and adding a second entity with the same field values is not possible. However, I'm using JSONAPI POST requests to create the entities. I noticed that when issuing multiple POST requests with the exact same field values right after another, the vali ...

Score: 0
Drazen avatar
How to get current region or current block of node in hook_theme_suggestions_node()
ru flag

I need to get the current region or the current block where a node is rendered, in hook_theme_suggestions_node().

function mymodule_theme_suggestions_node(array $variables) {
  $node_region = "I don't know how to get it";
  $node_block = "I don't know how to get it";
  $suggestions[] = 'node__' . $node_region . '__' . $node_block;    
}

I need only one value between $node_region and $node_block. How can  ...

Score: 1
quantumized avatar
Is it possible to allow anonymous users to view a temporary managed file via hook_file_download()?
ng flag

I am creating a live image preview system for customizable products that needs to send a user's temporary file to a remote server.

I have a token-based system to protect the file but the problem seems to be that the file is temporary. I've created a hook_file_download() to return the headers as required to allow access when approved but the file access is still being denied somewhere.

It does not se ...

Score: 0
Amine avatar
Templating the user edit page
us flag

i'm using the theme startupgrowth lite and i want to theme my user edit page , only when the user is a 'testeur' and he's editing the 'candidate user profile'.

i know that when i want to modify the form i must do this step:

1- add function to template.php to override the template page:

 function startupgrowth_lite_theme($existing, $type, $theme, $path) {
$items['user_profile_form'] = array(
    // Forms  ...
Score: 0
mt.i.1 avatar
Apply image style on asset image
us flag

I have a static image in my theme folder. Is it possible to apply an image_style to it ?

When I apply the image_style, I have this url that's generated :

/sites/default/files/styles/card_product/public//themes/custom/mytheme/resources/images/widget/myimg.jpg?itok=eIWpocqr

That's how I call it

{% set img = base_path ~ "/" ~ active_theme_path() ~ "/resources/images/widget/myimg.jpg" %}
<img class="" sr ...
Score: 1
how to convert date into timestamp using timezone
ls flag

I am using strtotime to convert date into time stamp but its does not work correctly. I know its relatively to time zone. My drupal store time zone is denver. I am not sure why its not showing correct date. there is around one day difference. so The last date I used 31 but I get last date of 30th not 31

Here are my query to make date into time and fetch record

date_default_timezone_set(drupal_get_user ...
Score: 0
steven avatar
How do I get the path for an image referenced in an entity field?
gb flag

I'm using <img src="{{ node.field_listing_location.0.entity.field_listing_location_image.entity.uri.0.value }}"> to get the path of an image referenced from a taxonomy field. What I get is a URL that starts with public://, not a full path nor a URL I can use with <img>.

How can I get a path or a URL I can use?

Score: -1
sea26.2 avatar
How to alter list of available countries provided commerce/guys
om flag

I need to alter the list of countries that are displayed in a webform. That uses a widget that is powered by the Address module which is powered by the commerceguys/addressing library.

According to the docs for Drupal/Commerce, that can be done with an event subscriber.

You can alter the list of available countries for a select list by subscribing to the AddressEvents::AVAILABLE_COUNTRIES

In fac ...

Score: 0
Greg Sims avatar
Tarball 9.3.0 to Composer 9.3.0
us flag

We have a large production website running 8.9.20 with a Tarball directory format. We would like to make the jump to 9.3.0 and convert the site from Tarball to Composer directory format. I performed the following:

  • Cloned the production website to "staging" (copy production directory and database)
  • drush up drupal-9.3.0

This "staging" Tarball 9.3.0 website has a clean "status" report and could be  ...

Score: 0
Better exposed filter for block view doesn't appear
pl flag

I created a new content type and a display page to show a listing of all my new content type pages. I'm trying to create a better exposed filter block on my page for the sidebar, but when I try to add the block view to my page, I don't see it listed.

I have another content type which uses exactly the same filters and I mirrored the same settings, but it still doesn't show up. I added this filter  ...

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.