Latest Drupal related questions

Score: 3
Drazen avatar
Which is better way of injecting service to controller with __construct or $instance = parent::create($container)
ru flag

I'm always using this way of injecting service to controller:

<?php    
namespace Drupal\TestModule\Controller;
    
    use Drupal\Core\Controller\ControllerBase;
    use Symfony\Component\DependencyInjection\ContainerInterface;
    
    class TestModuleController extends ControllerBase {
    
      protected $testModule;
    
        public function __construct(TestModule $testModule) {
       ...
Score: 0
Burly Uranus avatar
Is it possible to avoid the use of a module in this problem?
lb flag

I want a website with 4 different pages:

Home, About Us, Services and Contact.

Every page should be rendered by a twig template, sharing the menu and the footer. If I created a theme and have created every template for each page inside of the theme folder, how do I proceed? Should I create a module to define the routes and the controller or is there any other way to do it?

Score: 0
WebmasterPF avatar
Render custom region into node twig template
jp flag

My code used for D8 doesn't work anymore for D9. Custom region twig template for region into node twig template

I get thise error and WSOD:

Error : Call to undefined function entity_load_multiple_by_properties() dans themex_add_regions_to_node() (/home/xx/www/pfdev/multid9/recommended-project/web/themes/custom/themex/themex.theme ligne 145)

I notice that the condition on the region doesn't work too bu ...

Score: 0
David Buddrige avatar
How do you add a PDF attachment to a page?
cn flag

Complete Drupal Newbie here. I have created a basic Drupal 9 site so as to teach myself Drupal. I have added some Basic pages, and put them onto the menu. I can edit the text in each page just fine, however there are two things that I can't figure out how to do.

I want to add downloadable PDF attachments to some of the pages.

I also want to add pictures to my page. I'm not sure how either of thes ...

Score: 0
beta-developper avatar
How can I set validation rules on my entity fields and get errors if the data isn't valid
ye flag

I have this entity which got the link field

This link is mandatory, has to be more than 3 chars and less than 255 Also it has to be a valid URL

class Myentity extends ContentEntityBase implements BaseEntityInterface {

  use EntityChangedTrait;

  public static function baseFieldDefinitions( EntityTypeInterface $entity_type )
  {
    $fields = parent::baseFieldDefinitions($entity_type);

    $fields['li ...
Score: 0
How can I access or expose the Commerce data in $order->data[] to the Rules module?
us flag

Following this old checkout_pane_example.module tutorial, I created a custom Drupal 7 Commerce checkout pane. It's simply a text field to collect special order instructions from the customer.

function checkout_pane_example_pane_checkout_form($form, &$form_state, $checkout_pane, $order) {

  $pane_form['nickname'] = array(
    '#type' => 'textfield', 
    '#title' => t('Your nickname'), 
  ...
Score: 0
Upgrade notification urge me to "upgrade" a module to the currently using version
au flag

The below image is in Chinese so you might not understand. But in this screen, Drupal urge me to install PHP (PHP filter) version 8.x-1.1 while showing the currently installed version already is 8.x-1.1.

This is a bit annoying. I've already rebuilt cache a few times but the issue persist. How do I fix this?

Drupal update manager screen

Score: 0
Sam Bara avatar
How can I override Sitemap module's CSS file?
ua flag

I am trying to override the sitemap.theme.css file in the sitemap module through my library file. I have read through the documentation, and use the this example:-

libraries-override:
  # Replace sitemap's CSS file with one from my theme
  sitemap/theme:
    css:
      theme:
        css/sitemap.theme.css: css/my-sitemap-theme.css

but anything I tried doesn't work.

What would be the correct markup to ove ...

Score: 0
Alex Sh avatar
How can I remove or rename tabs from the local tasks block?
de flag

local tasks

I'm using Drupal 9.2.6 with Group module and I want to remove some tabs from local tasks block and rename some of them.

I've created the module and placed above code with hook_menu_local_actions_alter and hook_menu_local_tasks_alter:

function mymodulename_menu_local_actions_alter(&$local_actions) {
   $local_actions['view.group_members.page_1']['title'] = t('Users');
}


function pacifica_menu_lo ...
Score: 1
How do I install my own, custom module dependant on Composer?
au flag

I've looked all over, but there seems to be no advice on this online.

I've recently updated a Drupal 8 site to Drupal 9. I wasn't using composer before, and so I've used composerize-drupal to make the site composer compatible.

I have my own custom module on the site, and I had to uninstall it to get the composerize-drupal and then the upgrade to work.

I'm now trying to reinstall it, but there is a comp ...

Score: 1
KrzysiekK avatar
How do I control config names?
bn flag

When creating a config entity, we get an example_entity.schema.yml file:

example_module.example_entity.*:
  type: config_entity
  label: 'Example config'
  mapping:
    id:
      type: string
      label: 'ID'
    label:
      type: label
      label: 'Label'
    uuid:
      type: string

Creating entities of this type will result in config names, where the asterisk is replaced with the "id" property o ...

Score: 0
how do i sum (and count ) a field across all nodes
cn flag

I have a decimal field on a content type. I want to sum the values of this field across all nodes of that content type and display them with the total count on a page.

I tried to do this with views using aggregation settings.

enter image description here

in this case i set them for the one field and left everything blank. I thought that would give me a sum of the fields but

what i get is a page with a bunch of values not a sum ...

Score: 0
Frontpage title outputs a node's title and ADDS quotation marks
in flag

If a given node (page, article, etc) is visited, their site title (generated by {{ head_title|safe_join(' | ') }} is displayed correctly:

My Page Title | Sample Website

If the same node is then configured to be the frontpage and is visited as such /, the title of the node gets pretty quotation marks added to it:

“My Page Title” | Sample Website

I've NO idea where these are coming from. I have be ...

Score: 0
sam0720 avatar
how to implement 'most viewed/popular' content displayed in the sort filter
in flag

I tried with radioactivity but its not working as expected because we are using layout builder for our content types.

Score: 0
How to do views bulk operations on all matches, not just a page
jp flag

I have a lot of nodes to delete on a Drupal 9 site. I thought I could use the Content view, select the node type, click select all and Delete.

However it seems that select all only selects the visible nodes, i.e. page 1. I have many pages of results!

Is there a way to select all matched rows?

Score: 1
David Buddrige avatar
How do I update a Lightsail server?
cn flag

I have decided I want to learn Drupal. To that end, I fired up an AWS Lightsail server with a Drupal site, to play around with. Having taken AWS's default Drupal 9 install and logged in, it is displaying this message in the config screens:

There is a security update available for your version of Drupal. To ensure the security of your server, you should update immediately! See the available updates page  ...

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.