Latest Drupal related questions

Score: 0
Provide menu link when creating node programmatically and append it to parent menu link
in flag

I am creating a Node programatically:

Node::create([
  'title' => "Some name",
  'type' => "people",
  'body' => $params['body'],
  'field_people_degree' => $params['field_people_degree'],
  'field_people_email' => $params['field_people_email'],
  'field_field_image' => ['target_id' => $this->createImageFile($params['field_field_image'], $params['field_pub_tool_id'])->id()],
  ' ...
Score: 0
Timberman avatar
Link user to a LDAP user
cn flag

I have the LDAP authentication module installed, and have a user that is not able to sign in using LDAP.

In the database I can see that there is no DN string for this user.

I have got the DN string for this user.

Is it possible for me to add this string somewhere in the database, for him to be able to login to drupal again?

Thanks!

Score: 0
Rainer Feike avatar
Create solr_core for search_api_solr 4.x with docker solr 8
in flag

I used to create my solr instance for drupal like this:

docker run -v $PWD/solrconf:/asdentcore  -e SOLR_JAVA_MEM="-Xms2G -Xmx2G" --restart unless-stopped  -p 8984:8983 -t --name asdentDevSolr -d solr:8.11
docker exec -it --user=solr asdentDevSolr  bin/solr create_core -c asdentcore -d /asdentcore

Where ./solrconf contains the files from modules/contrib/search_api_solr/solr-conf-templates/7.x.

With the n ...

Score: 1
Baud avatar
How to validate a paragraph field?
sa flag

I have a paragraph type with 2 fields: year and quarter

I have a content type with a paragraph field (field_year_and_quarter) targeting ONLY this paragraph type

I am trying to create a constraint to disallow the encoding of a duplicate (same year/quarter)

I have tried:

1-A constraint at the node level which is looping into field_year_and_quarter with $node->get('field_year_and_quarter')->reference ...

Score: 0
Arif avatar
How to get remote post handler returned response at module file?
us flag

I want to get remote post handler returned response inside hook_webform_handler_invoke_post_save_alter.

Please help me.

function hook_webform_handler_invoke_post_save_alter(\Drupal\webform\Plugin\WebformHandlerInterface $handler, array &$args) {
  $webform = $handler->getWebform();
  $webform_submission = $handler->getWebformSubmission();
  $webform_id = $webform->id();
  $handler_id = $h ...
Score: 1
How do I get the selected image style from a referenced media field?
cn flag

I created a custom block with an entity reference to a media field (field_background_image).
In the display settings I have chosen 'Thumbnail' as format and selected a custom image style 'background'.

In my _preprocess_block(&$variables) function I would like to get the selected format (thumbnail) and especially the selected image style ('background').
How can I load both these information from the $v ...

Score: 0
Dorian Winterfeld avatar
How can I stop Webform Spam?
ae flag

We are getting spam from a simple Contact Us webform. We are running Drupal 7, using the Captcha and Honeypot modules. The Captcha challenge is set to image and the Honeypot time limit is set to 4 seconds and in enabled for all webforms. But we recently started to get spammed at the rate of 4 or 5 posts per minute, all from different gmail or ru addresses. For the time being we unpublished the offen ...

Score: 1
Jaypan avatar
Is it possible to add an entity to the current route parameters?
de flag

Using \Drupal::routeMatch()->getParameter(), it's possible to fetch objects that come from the parameters of the URL.

I'm wondering if it is possible to add values to the routeMatch. For example, if using the Groups module, nodes may be part of a group, however the group is not part of the path. Is there a way to load the group from the node, and add the group to the parameters that can be retrieved  ...

Score: 1
Vince Saseniuk avatar
Adding a class to an image using preprocess function
ck flag

I am having trouble adding a class to an image using a preprocessor function in Drupal 9. Specifically, I only want certain images to have that class added. The image is being added using paragraphs.

I've tried a few variations of the following and cannot seem to get class added. I've also tried using ['#item'] but it causes an error.

function confluence_preprocess_field__paragraph__field_card_imag ...
Score: 0
Drupal 8 Webform multistep - send data to custom controller
cn flag

I'm trying to implement a multistep form with Webform. I have my custom controller that takes data from POST request and then rendering a page with result from the from.

But I don't get how to link the two. Webform Remote Post Handler doesn't seem to be the solution.

Score: 0
Adding theme JS library in custom module
pt flag

My theme documention.libraries.yml file is defined as follows :

global-styling:
  version: VERSION
  css:
    base:
      styles/dist/styles.css: {}
tocbot:
  js:
    libraries/tocbot/tocbot.js: {}
    js/tocInit.js: {}
  css:
    layout:
      libraries/tocbot/tocbot.css: {}
layout_tweaksLib:
  js:
    js/layout_tweaks.js: {}

My custom module implements a custom template which also requires the theme fu ...

Score: 0
Amine avatar
Vertical tabs custom form Drupal7
us flag

I have a question to discuss about Vertical tabs on Drupal7 when we use it on custom module to make a form.

Can we use a vertical tabs on a another vertical tabs?

I know how we do to make a one vertical tabs but with one on another i think maybe one day we need it.

Score: 0
Gunnar Vestergaard avatar
The quick-start script in Drupal fails
de flag

I am trying to install Drupal v 9.2.9 on my web server. I was informed by core/INSTALL.txt that I could run the script

php core/scripts/drupal quick-start

It stops the installation prematurely with an error message:

In RouteProvider.php line 206:
Route "user.reset" does not exist.

How do I solve this? I have not set up a database yet. The web server has MySQL and PostgreSQL installed.

Score: 0
bigboy avatar
Update node and all translations programmatically
gu flag

I need to add tags as taxonomy terms to already created nodes in 7 languages.

If I do this:

$node = Node::load($nid);
$node->set('field_tags', getTerms($terms));
$node->save();

Just default node in English is updated, however, all terms are created in all languages.

getTerms() - is my own function, which is getting term ids and creating them if they don't exist.

I need to update all node transla ...

Score: 0
Run php code on text field in variation possible?
cn flag

Is it possible - anyone know how - to run php code on a commerce 2 variations created field to check the data in that field maybe using Ajax to make the field typingsensitive in the checkout?? I read through https://www.drupal.org/project/commerce/issues/3103537 but but the code there. The field would be used to verify an imei or Vin number before the purchase can be made. ( I have code to count k ...

Score: 0
Export data with one thousand values in contextual filter
fr flag

I have a view (views data export) that I need to pass approximately 1000 values for a the contextual filter. I need to get the view results for certain 1000 node ids.

Via the GUI it allows me only a few values as parameters. How could I have a CSV with the fields I have added to the view of the nodes given as a contextual filter all these values?

I have tried to export the view, edit it and manually ...

Score: 0
Baud avatar
How to get the revision of a paragraph
sa flag

I have a code which is running in hook_node_update. This code grab the revision of the saved node and compare the values of the fields between current node and its revision to generate some kind of historic log (what is deleted/updated/added).

This is working very well except for the paragraph field... When my code is trying to get the revision of a paragraph (recursively), I got each time the same para ...

Score: 3
Baud avatar
How to not split select list by content type
sa flag

This is about the regular select widget that you can choose in the Manage form display page.

If this widget is linked to an entity_reference field allowing several bundles to be selected; then you end up with an #options populated as follow:

_none -> "None"
Bundle label 1 ->
  id1 -> "label of ID 1"
  id3 -> "label of ID 3"
  id4 -> "label of ID 4"
Bundle label 1 ->
  id5 -> "la ...
Score: 6
How can I remove default image from image fields?
ru flag

I need to create an image field with a default value, which must also be nullable on single content entities. Contrary to text fields or entity reference fields, I was unable to remove this default value on single content entities.

E.g. I can create a text field with default value "Lorem ipsum". On node creation, the field is prefilled with that text, but I can also delete that text and the field ...

Score: 2
Baud avatar
How to alter the view behind a select widget in a regular node edit form
sa flag

I have an entity_reference field in a content type: field_node_ref

In the field definition, it can reference all the nodes of a given type.

The widget used for this field is a select widget

Depending the context, in the node edit form, I would like to use different views to populate the #options of the select widget.

Ex:

Context A --> View A will be used

Context B --> View B will be used

The cont ...

Score: 0
Display a pager on the top and bottom of view pages but only on the bottom of view blocks
pe flag

For a project running on Drupal 9.2.9, I want pagers on the top and bottom of view pages. I have it working on pages by an edit to a custom views-view.html.twig in the theme (using the full pager option in the Views display). Unfortunately, this resulted in double pagers on blocks using minipager also.

I think I need a little conditional logic in the views-view.html.twig template to check for if …  ...

Score: 0
view and context variables does not get passed on VBO custom execute action
in flag

I have created a custom VBO action and below is my code for the customaction.php. The action is getting created perfectly fine, however the $view and $context variables are not getting passed through. They are all getting null. Below is the custom action code:

    namespace Drupal\mymod\Plugin\Action;
    
    use Drupal\views_bulk_operations\Action\ViewsBulkOperationsActionBase;
    
    /**
      ...
Score: 0
How can I make certain fields of my block implementation translatable?
vn flag

I've created a simple module, which extends BlockBase to provide a custom block.

This block class has a few fields (e.g., "Header"), which I would like to be translatable.

How can I accomplish this? The Drupal docs have a section titled "Make your block translatable", but it hasn't actually been written yet.

I've found some posts which suggest that my module needs a .schema.yml file – but I'm n ...

Score: 0
jfc avatar
Is there a way to duplicate existing fields instead of manually creating new ones?
us flag
jfc

I am using Drupal 9 and I have a template which will require 40 text fields and 20 image fields.

They are meant to display 20 individual products, so they are all similar. The display would be something like this -

Product Title 1 Product Thumbnail 1 Product Subtitle 1

Product Title 2 Product Thumbnail 2 Product Subtitle 2

And so on for 20 products.

To add this field manually will take a very long  ...

Score: 1
Adding an "Accept Terms" checkbox on User Registration form
in flag

I need to add an "Accept terms and conditions" checkbox onto a user registration form. What is the best way to do this?

Also, it seems odd to me that there is no easy way to use radio buttons nor checkboxes on the User Registration form at admin/config/people/accounts/fields. Select lists are awkward, especially for multi-select lists on a mobile device.

Is there a way to output the list fields as ...

Score: 0
Amine avatar
custom module form radios fields & ajax problem
us flag

I have a custom form, that iI develop on a custom module to get some fields from a content type with an entity reference.

All is good, I can get all information, and I can save the chosen value on a field of content type.

My problem is: why is it that the first input radio doesn't save and show me the max, but I have 0 on the field like a value.

My code to create the field of form:

'#type' =&gt ...
Score: 0
How to make the private image accessible with image style?
kr flag

I have a private image with this URL.

http://mystite.com/system/files/images/IMG_0371_24.jpg/IMG_0371_24.jpg

An image style is created for the above image on location

http://mysite.com/system/files/styles/square/private/images/IMG_0371_24.jpg/IMG_0371_24.jpg

The problem is when I display the original image, it works fine. But when I display the image with style, the image is not displaying and in th ...

Score: 0
Plugin not found
in flag

I am overwriting the CommentBulkForm class in my module.

namespace Drupal\mymod\Plugin\views\field;

use Drupal\comment\Plugin\views\field\CommentBulkForm;

/**
 * Defines a custom comment operations bulk form element.
 *
 * @ViewsField("custom_comment_bulk_form")
 */
class CustomCommentBulkForm extends CommentBulkForm {

  /**
   * {@inheritdoc}
   */
  protected function emptySelectedMessage() { ...
Score: 1
frank.schram avatar
Filter GeoJSON feed on a value in the path
ca flag

I have GeoJSON feed, created with a view in Drupal 7, that I want to filter on a path value in the url of the loaded page (/path/%). The feed is loaded as an Openlayers map on a page. The feed seem to work with its own feed-url and is not aware of the site url. Contextual filters in the view don't work either. I can use hook_views_query_alter or hook_views_pre_view. But I don't know how to bring the val ...

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.