Latest Drupal related questions

Score: 1
Disable the "Add Link" button in entity.menu.edit_form for certain roles
ng flag

I'd like to hide the "Add Link" button in menu.edit_form for certain roles. Running dpm($form) for this form I can't find that button in there. In core there is menu_ui.links.action.yml with this snippet:

  entity.menu.add_link_form:
  route_name: entity.menu.add_link_form
  title: 'Add link'
  class: \Drupal\menu_ui\Plugin\Menu\LocalAction\MenuLinkAdd
  appears_on:
  - entity.menu.edit_form

I don't g ...

Score: 1
Bass-Ninja avatar
How to refresh/rebuild block without reloading the page?
ru flag

I have a custom block which displays the number of events added to favorites(Flag module). I am using the TWIG template to display those results. I want to refresh the block contents right after the user flags/unflags a node. Currently I can only get the updated value if I reload the page.

The build() looks like this:

class FavoritesBlock extends BlockBase
{

  /**
   * {@inheritdoc}
   */
  public fu ...
Score: 1
How to hide a facet item if it does not narrow the results?
kr flag

I have a facet of taxonomy terms with the links widget. There are 3 taxonomy terms displaying with the number of results in the bracket.

Term 1 (3)
Term 2 (2)
Term 3 (10)

When I select Term 1, the search page displays 3 results, which is fine. But count on Term 2 and Term 3 are still 2 and 10 respectively, which is wrong. It should be decreased. Like for example, In those 3 results, there is only one i ...

Score: 0
pglatz avatar
Execute a behavior only once per page load
in flag

Moving from Dupal 7 to 9, I'm having a problem with javascript behaviors being called multiple times. In the browser console, when I load a page, I'm seeing:

process test for [object HTMLDocument] pet_guides.js:27:15
process test for [object HTMLUListElement] pet_guides.js:27:15
process test for https://whiskerdocs-local-d9.pglatz.com/portal/config/user-interface/shortcut/manage/default/customize p ...
Score: 1
How do I re-order a node's body and link fields in my Bartik subtheme?
in flag

I have a simple subtheme of the standard Bartik theme in Drupal 9.3.0. By default, when a node is rendered, its links, eg. "read more", "log in", come before the body.

For example,

<div class="node__content clearfix">
  <div class="node__links">
    <ul class="links inline">
      <li class="node-readmore"><a href="/node/11" rel="tag" >Read more</a></li>
       ...
Score: 0
Display comments only for users with "administer comments" permission
id flag

In hook_node_view_alter, I'm trying to restrict the display of comments to users who have the "administer comments" permission.

So far I have this but it is not working.

if (isset($build['comment'])) {
  if (!\Drupal::currentUser()->hasPermission('administer comments')) {
    $build['comment']['#access'] = FALSE;
  }
}
Score: 0
Dorian Winterfeld avatar
Why is the Aggregator module not creating a block
ae flag

I am using the Aggregator module that is part of Drupal 9 core. I am following the docs on drupal.org: https://www.drupal.org/docs/8/core/modules/aggregator/overview

After I create a feed and update it, I understand that a custom block should automagically be created. But I cannot find any new blocks under /admin/structure/block. Am I missing something?

Score: 0
sanbaldo avatar
How can I print a single field?
cn flag

I've got a taxonomy page (https://www.dovericaricare.it/becharge) that I'm trying to customize using a twig template.

I don't understand what syntax I should use to print fields like the logo ({{ fields.field_logo }} doesn't work and there is nowhere in the dump a field with a full path url for the image) or the value of field_fornitore

Here's the dump of the content of the page (you can see it on  ...

Score: 0
Views filtering by two values from same field and comparing with another time field
us flag

I have a customer which works with buses and passenger transportation.Now he would like that all routes would be visible on a site and guests could filter routes by source and destination points.
Routes examples:

Route A-E
StopA 08:10
StopB 08:20
StopC 08:30
StopD 08:40
StopE 08:50

Route E-A
StopE 09:00
StopD 09:10
StopC 09:20
StopB 09:30
StopA 09:40

Now client wants Search fields Source and Dest ...

Score: 0
May  avatar
Is it possible to render a region in a menu template?
zw flag

In my Drupal 8 theme I have a template called __menu.html.twig which gets called in my page.html.twig

I am trying to render a region within the __menu.html.twig where I can place blocks.

I have rendered the region within my theme.info. How can I declare the region in __menu.html.twig?

Score: 0
How do I move a node's tags to be near its author information in my Bartik subtheme
in flag

I want to style a node's author data and tags slightly differently to the Bartik theme in Drupal 9.3. That is, rather than:

Submitted by user1 on Mon, 1/1/70
Tags
  foo
  bar

I'd like to have:

Submitted by user1 at Mon, 1/1/70 on foo | bar

So far, I have created a subtheme tweak with the following definition in tweak.info.yml:

name: Tweak
type: theme
description: This is a sub-theme of Bartik
core_ ...
Score: 0
How can I print view/edit/comment links?
tr flag

I have a view that uses the "View content," "edit content," and "view comments" fields. I can't figure out how to print these in a custom twig template.

I've tried:

{{ fields.comments_link.content }}
{{ fields.comments_link }}
{{ comments_link }}

Similar attempts to print the view and edit links didn't work either. Other fields print fine. Can someone point me in the right direction, or do I just need to ...

Score: 0
quantumized avatar
How to remove the fieldsets that are pup around "list (text)" fields that have their display set to "Check Boxes / Radio Button"?
ng flag

We have a Drupal 9 website and are using "list (text)" fields whose displays are set to "Check Boxes/ Radio Button". This causes the output to be wrapped in a field set which we need to remove.

I have tried some trial and error (guessing) at altering the field in hook_form_alter() but the fieldset remains.

enter image description here The field variable is below:

Array
(
    [#type] => container
    [#parents] => Array
   ...
Score: 0
Use Migrate Tools to import into multiple value link field from JSON array
cn flag

I am trying to import data into a multi-value link field from a JSON source using Migrate Tools. I think I should be able to do this without writing a custom plugin, but so far nothing is working. My JSON looks like this:

[
 {
  "first_name": "Joe"
  "last_name": "Smith"
  "departments": [
     {
       "department_name": "Mail room"
       "department_url": "https://myoffice.com/mailroom"
     },
 ...
Score: 0
Debugging functional tests with phpunit just hang unless I toggle "stop/start listenting for php debug connections"
cn flag

Trying to get tests up and running by following https://www.previousnext.com.au/blog/running-and-debugging-phpunit-tests-phpstorm-ddev-and-xdebug. Seems to work, except having an issue with functional tests. If I disable xdebug, the test runs in like 5 secs. If I enable xdebug and try to "debug the test", it just hangs forever.

If I wait like 30s then toggle "stop/start listening for PHP Debug Connecti ...

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();

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.