Latest Drupal related questions

Score: 0
Rayan Frem avatar
Why is this hook implementation not working?
cn flag

I am new to custom modules and hooks and i am trying to connect to a sharepoint site i created to upload pictures of a content i have into sharepoint instead of drupal's file system. My issue is not actually with all this, the initial function sharepoint_file_upload_form_alter isn't working. I added the die(); function to test if the function is being called but i was able to add content normally. I mad ...

Score: 0
kankari avinash avatar
Uncaught TypeError: Cannot read properties of undefined (reading 'messages') (forms AJAX POST)
td flag

Here I have created a custom module, which has one form in it...An ajax response is called when an Email is entered in form field and it will callback an HTML response.

I have tested this code on my localhost and my own test website I havent seen this error but when i installed my module in main website i could this error...

Here is the error from console.

enter image description here

Thank you in advance

Score: 0
Libbna Mathew avatar
Is there any way to show the data fields from content and google analytics reports in view page?
in flag

I want to create a view page where I can show/add the fields of content (title, author, content type, etc) and also the fields of google analytics reports api (event name, total views, users, etc.) I tried with view's permission and and also added a module views multiple permission to give multiple permission but it didn't work.

I have already configured google analytics reports module, I just wa ...

Score: 1
Anders avatar
How to pass node argument to a local task form?
bo flag

Suppose I have a route for a local task like this:

MODULE_NAME.node_options:
  path: '/node/{node}/options'
  defaults:
    _form: '\Drupal\MODULE_NAME\Form\NodeOptionsForm'
    _title: 'Options'
  requirements:
    _entity_access: 'node.update'
    node: \d+
  options:
    parameters:
      node:
        type: 'entity:node'

NodeOptionsForm shall present 2-3 radio buttons to the user to select a se ...

Score: 0
Alex avatar
How do I programmatically attach a file to a webform submission
ua flag

I'd like to attach a custom file to an email of a webform submission. That means, I want to add the file as email attachment without an existing webform field (document file) or similar.

My idea was to create a custom field programmatically in the method

public function preSave(WebformSubmissionInterface $webform_submission) {...}

that will be used as attachment. However, this doesn't work at all.

Score: 1
Data is not saved on the entity when the source and destination field names are the same but have different types
cn flag

I'm migrating from Drupal 7 to Drupal 9.

On the source Drupal 7 user entity there is a Text (list) field with various values. These need to be migrated to a taxonomy_term reference field on the Drupal 9 site, where the referenced terms have names corresponding to the values provided in the D7 source.

I'm using entity_lookup to link the Text (list) values to entities on the D9 site, and this works fine,  ...

Score: 1
Anders avatar
Local task for content node doesn't show up and raises 'Access denied'
bo flag

After spending two days trying to figure this out, it's probably better to ask for help.

I need to add a custom tab next to View Edit Delete Revisions Translate for content nodes (a local task, if I understand the terminology correctly). This tab is supposed to open a form where the user can select from a choice of tasks to perform on the current node (e.g. generating a summary of the text with A.I.). ...

Score: 1
user76445 avatar
How can I use EntityForm ::save() in a custom module?
ru flag

How can i call public function ContactFormEditForm::save. My goal is refer to return value, do something like email, custom logged message, etc.

Refer to api."Return value int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed."

Un myCustom.module file how to do: if contact Form == specific Form, and if the form submitted. $value = $form->save():

how do custom module know when u ...

Score: 2
tonytheferg avatar
How can I properly create separate storage for a base field?
cn flag

What is the correct and supported way to create a separate table storage for a base field on a custom entity? I tried the answer here, using setCustomStorage(TRUE), but it didn't work, and I don't think that I need to actually create custom storage, I just wanted a separate table in the database for the field.

I was able to get a separate storage table with BundleFieldDefinition::create('address') ...

Score: 1
Allow access to Webform form URL only through Ajax
in flag

I'm using Webform to create some forms, those forms must be showed in modal through Ajax, and all of this is working good.

The issue is that I need URL to the form in order to load the form in modal, but I need to deny access to the form URL and allow it only through Ajax.

So, if user try to get /forms/my-form to get 403, and if I get the same URL in Webform Ajax Modal to allow it.

Any idea how to a ...

Score: 0
Lambic avatar
Adding a select box to a tableselect
ph flag

I'm trying to use the technique outlined in this blog post:

https://www.hexblot.com/blog/drupal-tableselect-fields

to add a select box to a tableselect, but there are a couple of issues:

  • The default value is not being respected (I've tried using #value and #default_value)
  • The roles element is empty on submit

Any idea what I'm missing? Here's my code:

foreach ($query as $row) {
  $member = user_loa ...
Score: 0
H M avatar
Temporary file issue when creating a file from an external script
mw flag
H M

I would like to create a file and write some data to it using a PHP CLI script. The script will bootstrap Drupal and then use either the file_system or file.repository services to perform the task.

For sanity check, I tested the methods using Drush:

drush eval 'use Drupal\Core\File\FileSystemInterface; $fileRepository = \Drupal::service("file.repository"); $fileRepository->writeData("hello", "public: ...

Score: 1
equivalent of hook_field_widget_form_alter() for field formatters?
by flag

There's a hook hook_field_widget_form_alter() for altering a field widget, but I can't see anything equivalent for altering a field formatter's output.

Score: 1
MyaBee802 avatar
Why does this Twig code not perform math operations as expected?
tn flag

I have a registration form set up for athletes; I'm a volunteer coach. The form contains 5 slots to register up to 5 children at a time. There's also a donation field. Everything works fine unless the donation value goes over 999. I tried to use number_format in every way possible to grab the donation value and format it properly, but it still keeps adding a 1 when the number is higher than 1000. ...

Score: 0
Robert Janssen avatar
target separate fields of my taxonomy term in my view using twig
lk flag

I have a view displaying taxonomy terms as fields by making use of a responsive grid. I have a twig file based on views-view-grid-responsive.html.twig.

in this twig file there is a loop {% for item in items %} and than in there {{- item.content -}} which is basically displaying the whole taxonomy term. in my case simply the name and an image.

I am trying to find a way to target each field/value s ...

Score: 1
mbomb007 avatar
User-specific caching, but not necessarily the current user
nl flag

Background

I'm creating a render array that is built for a specific user, from data related to that user. The resulting render array is dependent on the user ID that is passed in, and it will be rendered in a block.

The resulting block will be built and shown to the user whose data it is. However, it could also be shown to privileged users via another page, where they select a user from an Entity  ...

Score: 0
Anders avatar
How to add a confirmation form to an advanced configurable action?
bo flag

So far I successfully implemented an advanced action (in a custom module) by extending ConfigurableActionBase and implementing ContainerFactoryPluginInterface. As expected, it appears listed in /admin/config/system/actions, where new actions can be created and configured. These actions show up in the bulk action drop down menu in /admin/content. Selecting one or more content items and performing the act ...

Score: 0
user3038672 avatar
Responsive Background Image offers theme code for paragraphs, but I need it in taxonomy
cn flag

Responsive Background Image module offers theme code for paragraphs, but I need it in taxonomy. Taxonomy is a little different in that it is an array inside of an array. How do I change this code to work with Taxonomy instead of Paragraphs?

use Drupal\responsive_background_image\ResponsiveBackgroundImage;

/**
 * Implements hook_preprocess_TEMPLATE().
 *
 * Preprocess paragraph.html.twig.
 */
funct ...
Score: 1
Enum class not found when trying to use it in settings.php
cn flag

I defined an enum in a custom module:

namespace Drupal\my_module\Enum;

enum BuildType: string {
  case Apple = 'apple_build';
  case Orange = 'orange_build';
}

And I want to use it in settings.php to change the config directory of the site:

settings.php:

$build_type = BuildType::from(getenv('build_type'));

$settings['config_sync_directory'] = dirname(DRUPAL_ROOT) . '/config/base_' . $build_type->v ...
Score: 0
quantumized avatar
How can I set a node's nested (address field) value in a custom submit handler?
ng flag

I need to clear any data from an address field's values (administrative area, etc.)

In my custom submit hanlder for node form, I know I can use something like below for a standard field:

<?php
  $form_state->setValue('field_alternate_phone', [['value' => 'NEW VALUE']]);
?>

But I cannot figure out how to change the value of a nested address field where the values are something like:

enter image description here

I ...

Score: -3
Rayan Frem avatar
How to open an iframe with a different base URL for "Page Not Found" errors in Drupal?
cn flag

I am working on a Drupal website and I need to implement a functionality where an iframe is opened with a different base URL whenever a "Page Not Found" error occurs. The goal is to display the content from a different website within the iframe.

I have tried implementing a custom module using the hook_preprocess_HOOK() and hook_page_attachments() hooks, but I'm encountering issues with the code n ...

Score: 2
BlondeSwan avatar
Creating your own Node Entity Normalizer
br flag

I am trying to create my own Node Entity Normalizer in Drupal 10 to get rid of the unnecessary JSON structure that comes out of the box. For example, instead of my API's returning

{
  "nid": [
    {
      "value": 7
    }
  ]
}

I want to make it return

{
  "nid": 7
}

So I've tried the following options in my custom module:

  1. Typed Data Interface

example_normalizer.services.yml

services:
  example_no ...
Score: 1
Alimba avatar
can a module introduce paragraph types and templates?
in flag

I'm building a very complicated paragraph layout with multiple levels of interconnecting paragraph types. At the moment, configuration and template files are all over the place.

So, I was wondering if there is a way to do the same using a module so, it will have all packaged up in one place.

Is there a way that a module to introduce a paragraph type?

Only things I've found so far was a module creating  ...

Score: 1
Ben avatar
Custom access for a web-based custom type
pg flag
Ben

For my Drupal site, I made a custom type named MyCoolCustomType. I'd like to grant access to view this custom type only to certain condition on user role and properties of the custom content itself (for example, the ModerationState of the content).

I'm quite confused about how to process.

Thanks to a class that extends RouteSubscriberBase, I'm trying to modify the route entity.node.canonical to c ...

Score: 1
spiderfingers avatar
Excluding some taxonomy terms from a view when grouped by taxonomy
gd flag

For node type 'people' I have tags A, B, C etc. Some people have multiple tags.

On my view I'm grouping them by taxonomy term and selecting A,B,C,D etc under 'Select terms from vocabulary People type' but I don't want to include E tag as a group on this page.

Nobody who is only E tag shows up, which is correct, and people who have E as one of their tags are there in their respective A,B,C tag groups, w ...

Score: 0
Md Eqbal Ahmad avatar
Different values in an custom entity field for each domain?
gh flag

I have implemented the Domain module and added a boolean custom field to a taxonomy entity that is accessible in all three domains: domain1.example.com, domain2.example.com, and domain3.example.com. However, I am facing an issue where updating the field value in one domain affects all the other domains. I want to have the ability to save different values for this field in each individual domain. Is  ...

Score: -5
Eluchel avatar
Is there a place to find a list of good premium/paid drupal modules?
so flag

I have a client that has "deep pockets" and so higher ups are pushing for us to use premium modules so that "the user experience is better for the client". I haven't ever used a premium/paid drupal module and haven't been able to find a place where I can see a list of them to see if any would be beneficial (specifically higher ups are looking for premium calendar and hero banner modules).

Any one ...

Score: 1
antongordon25 avatar
How to add the title with a sequence number to inline entity form?
ng flag

I have an edit form of a custom entity that is passed to the controller:
$form = $this->entityFormBuilder()->getForm($entity_quote, 'edit');

This custom entity has the reference field to another custom entity quote_design. Widget for this field - Inline entity form - Complex.

I added this code to display the word Design above each inline entity form:

/**
 * Implements hook_inline_entity_form_enti ...
Score: 0
Brittany avatar
How can I prevent a custom node page template is used when editing a node?
ph flag

I'm theming some specific Drupal 9 pages with custom templates (e.g. page--node--17.html.twig).

That said, the theme carries over when I go to https://example.com/node/17/edit.

I only want the template to appear on the front end, not when I go in to edit a node (I want that to remain the same basic page.html.twig that it usually is).

How can I fix this?

Score: 0
quantumized avatar
How can we move Webform's progress bar from above the form to below it?
ng flag

I can't find a way to move the progress bar to below the form. I've looked all through the UI options and also examined the Twig templates that are used to render the progress bar but there does not seem to be a way to move it. Is it being inserted through a process hook? Can't figure this one out.

enter image description here

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.