Problem when I don't translate a node [closed]

22 hours 52 minutes ago

If a node is not translated, the language selection block still redirects to the missing language. Furthermore, at the URL of the "not translated node" this is still rendered. How?

  • Set Language module
  • Set content with translation
  • Add new node
  • Don't translate the node
  • Go to the node and replace the language code in the node url with an active one (ex. to
  • The page will still return the node

Unable to create temporary file while installing site

1 day ago

When trying to install Drupal 9 I get this error

This problem comes up when I try to install drupal in Spanish

Warning: curl_setopt_array (): Unable to create temporary file. in GuzzleHttp \ Handler \ CurlFactory-> create ()

and although I already create the tmp folder I still get the error

Beto Guitars

Limit the number of uploads per image field depending of role

1 day ago

I need a hook (or something similar) where I can set the number of image uploads depending of the role of the user.

In the settings of the field there is no way to set the maximum number of values users can enter, just one value for all roles. For example, for role #1 I want the users can upload just 3 images, for role #2 just 5 images.

I tried several ways but none worked. I tried using #element_validate but the validation never worked.

Is there some way to do that? I forgot to mention is for Drupal 7.

Jose Daniel

Pass data to hook_entity_insert

1 day ago

How can I pass data to hook_entity_insert() given that the arguments it takes are fixed?

I'm writing to the database during entity save, and need to be able to pass some data in this hook.


How do I check by default a checkbox from a checkboxes control after an AJAX call

1 day 1 hour ago

I have the next form which behavior is:

  • When you select an option from select control, different checkbox are load on checkboxes control.

  • When you check/uncheck checkbox a message is showed on the botton with info about select value and checkbox clicked.

Everything works fine, but is impossible check by default a checkbox from checkboxes control after ajax function.

Any idea?

namespace Drupal\drupal_miseries\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element\Checkboxes; class CheckboxesAjax extends FormBase { protected $values = [ 'select' => [ '1' => 'Value1', '2' => 'Value2', ], // Options when select 1 is selected 'checkboxes_v1' => [ '1' => 'checkbox1', '2' => 'checkbox2', ], // Options when select 2 is selected 'checkboxes_v2' => [ '3' => 'checkbox3', '4' => 'checkbox4', ], // Default values for checkboxes 'checkboxes_df' => [ // Default value when checkboxes_v1 is showed '1' => ['1' => '1', '2' => '0'], // Default value when checkboxes_v2 is showed '2' => ['3' => '0', '4' => '1'], ], ]; public function getFormId() { return 'drupal_miseries_checkboxesajax'; } public function selectAjaxCallback(array &$form, FormStateInterface $form_state) { return $form['container']; } public function checkboxesAjaxCallback(array &$form, FormStateInterface $form_state) { $checkbox = $form_state->getTriggeringElement(); $select = $form_state->getValue('select'); $form['status']['mensaje'] = [ '#markup' => '

Select: '.$select.' '.$checkbox['#title'].' clicked.'.'

', ]; return $form['status']; } public function buildForm(array $form, FormStateInterface $form_state) { $form['select'] = [ '#type' => 'select', '#title' => $this->t('Select form control'), '#options' => $this->values['select'], '#default_value' => key($this->values['select']), '#ajax' => [ 'callback' => [$this, 'selectAjaxCallback'], 'wrapper' => 'checkboxes_wrapper', ], ]; $form['container'] = [ '#type' => 'container', '#attributes' => ['id' => 'checkboxes_wrapper'], ]; $form['container']['checkboxes'] = [ '#type' => 'checkboxes', '#title' => $this->t('Checkboxes form control from select @select', [ '@select' => empty($form_state->getValues()) ? $this->values['select'][key($this->values['select'])] : $form_state->getValue('select') ]), '#options' => empty($form_state->getValues()) ? $this->values['checkboxes_v1'] : $this->values['checkboxes_v'.$form_state->getValue('select')], '#default_value' => empty($form_state->getValues()) ? $this->values['checkboxes_df']['1'] : $this->values['checkboxes_df'][$form_state->getValue('select')], '#ajax' => [ 'callback' => [$this, 'checkboxesAjaxCallback'], 'wrapper' => 'status', ], ]; $form['status'] = [ '#type' => 'container', '#attributes' => ['id' => 'status'], ]; return $form; } public function submitForm(array &$form, FormStateInterface $form_state) { } }
Javier Martín

How to retrieve #tree values inside a multiple containers?

1 day 2 hours ago

I am using Drupal 8 and I am creating multiple forms that are made of a #tree hierarchy.

I am retrieving the value of the "first name" from the #tree using the below code and it doesn't get the value.

$firstName = $form_state->getValue('userBoxArea')[$counter]['userBox']['nameBox']['firstName'];

The code of my #tree form is:

$form['userBoxArea' ] = [ '#type' => 'container', '#tree' => TRUE, ]; for($counter = 0; $counter < $rowCount; $counter++){ $form['userBoxArea'][$counter] = [ 'userBox' => [ '#type' => 'container', 'nameBox' => [ '#type' => 'container', 'firstName' => [ '#type' => 'textfield', '#title' => 'Enter your first name', ], ], ], ]; }

The rowCount pertains to the row in my database. The process is to acquire firstName from the user and those variables will be saved inside the database.

I have researched articles from Drupal if there is a limitation of the #tree containers and found nothing about it.

Any suggestions if I am missing something. How do you retrieve the value of "firstName"?

Thanks in advance.


Using Media, views, and colorbox to create a image gallery

1 day 2 hours ago

Currently I am running in D7 with the following modules:

  • Media 7.x-2.0
  • Views 7.x-3.7
  • Colorbox 7.x-2.4

I am trying to create an image gallery using these modules with the following steps. Please note problems I am running into will be in bold.

  1. Go to admin/structure/views
  2. Click Add new view
  3. Select File for show, and image for type
  4. Unchecked Create a page, and check Create a block
  5. Select Grid of File for Display Format
  6. Click Continue and Edit

This is where things go off the rails for me, what I would like to do is have ALL images that are tagged display in a custom image style I already created (200x200) in a 4 column grid, and when you click on them they open up into a normal sized image colorbox.

Now I have seen this done when you create a image content type, but that way is clunky compared to using the media module, and I have to believe that there is an easy way to do this with these modules, and I am simply missing it.

I have read about Media Gallery module, but there seem to be a lot of errors with it and I am not thrilled with the idea of it.

Any help on how to get what I am trying to do done would be greatly appreciated as this is becoming a bother.


How can one user assign certain portions of permissions to other users, while the rest of the permissions are invisible to him

1 day 3 hours ago

I'm using Drupal 9. I want to create an account for the website, which has the permission to create roles and accounts, but I hope that the permission list he can see when assigning role permissions is the one I allow. and the permissions I do not allow will not appear in the list. How can I implement this function, please help me, thanks!


How do I collect field values of a submitted webform?

1 day 5 hours ago

I'm trying to integrate a Mailchimp mailing list into Drupal. The Mailchimp list requires:

  • First Name
  • Last Name
  • E-Mail

The client already has a list in this format so ideally I need to collect this data in Drupal.

I want to have a newsletter block that collects the email address and forwards a user to another page that has the full newsletter sign up with first name last name and the email but pre filled out.

I know I'm going to need Rules and Webform. But how can I collect the value of the webform field and use it again as a token later?

Note: I am using this within the Drupal setup, but the list requires three fields of data (first/lastname/email). I want to have a block that initially collects the email and forwards them to the full newsletter signup page. I have the webform and rules working to direct the user from the page with the block to the signup page, but I need to find out how to create a custom token from the field.

James Kirkby

Grouped Exposed filters radio buttons : one in two no value ticked. How to programatically force default button be ticked?

1 day 6 hours ago

Some exposed filters (radio buttons) aren't systematically ticked when a view is displayed, causing an "An illegal choice has been detected. Please contact admin..." error message and No result found.

Moreover, refreshing the same view, or surfing between similar views with another contextual filter value (taxonomy term ID) : one in two the button is ticked, the other not !

Ticking any radio button once the view is loaded gives correct results.

Errors reported :

  • Warning : Illegal offset type in isset or empty dans convert_exposed_input() (line 1165 of views/handlers/
  • Illegal choice 0 in field_statut_depart_value element.

EDIT : I did put below as many details as I could find to illustrate the problem, but after searching and searching, basically the question is : since I can't find why such behaviour, nor why this is always the same value which is loaded by default, whichever setup I try : How can I alter the form and ensure the default button is ticked on page loading.

This filter filters a field which values can be "Open, Almost confirmed, Confirmed, Full, Closed", and I need to group the filter values :

  • 1=> Any value excepting Closed, selected by default
  • 2=> Almost confirmed or Confirmed

I played around with Grouped filters and BEF, and achieved the correct radio buttons display with at least 2 different setups. This is the last setup I tried.

I tried then to alter the form :

function MODULE_form_alter(&$form, &$form_state, $form_id) { if($form['#id']=='views-exposed-form-my-form'){ $form['field_status_depart_value']['#default_value'] = 1; $form['field_status_depart_value']['#required'] = TRUE; //dpm($form); } }

I could hide the error message with $form['field_status_depart_value']['#validated'] = TRUE; . It seems to be solving also the view returning empty result one in two... but now the result are filtered with one or another filter value, while the customer does not know it !

I tried without success to change the UI setup in many manners : with or without ajax, with or without BEF overwriting, optional or not, remember or not.. Same if I set to default select list, the exposed filter value toggles from one to the other at each page refresh.

After night & day fighting with that, I would feel really better to get some help, my most wished Christmas present ! Thanks a lot !

EDIT : this is the relevant parts of code export.

$handler->display->display_options['exposed_form']['options']['bef'] = array( 'field_status_depart_value' => array( 'bef_format' => 'bef', 'more_options' => array( 'bef_select_all_none' => 0, 'bef_collapsible' => 0, 'is_secondary' => 0, 'any_label' => '', 'bef_filter_description' => '', 'tokens' => array( 'available' => array( 0 => 'global_types', ), ), 'rewrite' => array( 'filter_rewrite_values' => '', ), ), ), //... /* Critère de filtrage: Commerce Product : Statut (field_status_depart) */ //RELEVANT LINES $handler->display->display_options['filters']['field_status_depart_value']['value'] = array( 1 => '1', 2 => '2', ); $handler->display->display_options['filters']['field_status_depart_value']['expose']['multiple'] = TRUE; $handler->display->display_options['filters']['field_status_depart_value']['is_grouped'] = TRUE; $handler->display->display_options['filters']['field_status_depart_value']['group_info']['remember'] = 1; $handler->display->display_options['filters']['field_status_depart_value']['group_info']['default_group'] = '1'; $handler->display->display_options['filters']['field_status_depart_value']['group_info']['group_items'] = array( 1 => array( 'title' => 'Opened', 'operator' => 'or', 'value' => array( 0 => '0', 1 => '1', 2 => '2', 3 => '3', ), ), 2 => array( 'title' => Confirmed or almost confirmed', 'operator' => 'or', 'value' => array( 1 => '1', 2 => '2', ), ), );

How do I connect to Adsense Account?

1 day 7 hours ago

I have to add a script section to the head section on the website. I am modifying the html.html.twig file like this:

<!DOCTYPE html> <html {{ html_attributes }}> <head> <script async src="//"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-6243578269823283", enable_page_level_ads: true }); </script> <head-placeholder token="{{ placeholder_token|raw }}"> <title>{{ head_title|safe_join(' | ') }}</title> <css-placeholder token="{{ placeholder_token|raw }}"> <js-placeholder token="{{ placeholder_token|raw }}">-- </head> <body{{ attributes.addClass(body_classes) }}> <a href="#main-content" class="visually-hidden focusable skip-link"> {{ 'Skip to main content'|t }} </a> {{ page_top }} {{ page }} {{ page_bottom }} <js-bottom-placeholder token="{{ placeholder_token|raw }}"> </body> </html>`

This seems to not work. Google responded and said I still have to connect my site to Adsense for verification. How do I do this? I have the Adsense module installed but I can't use it until I have an account. This script is for verification so that I can have an account with my website.


All instances of block are not getting removed

1 day 8 hours ago

This question is a continuation of this Block in Drupal 8, The second problem I am facing is that suppose I select block made for comment section and place it under Sidebar second section and afterwards deselect comment from configuration setting then after clearing cache the label for comment from block section is removed but block placed under Sidebar section still remains with default message for broken blocks "This block is broken or missing. You may be missing content or you might need to enable the original module.".What changes should I make so that this message is removed ? Thanks.


creating nodes with many to many relationship type with some fields?

1 day 9 hours ago

This is in line with How to structure a "many-to-many" relationship between nodes.

To keep things in line with the example from the linked thread, what if i was a book warehouse and i had a list of all my books but i want to allow each seller to name his own price and show that book in the seller's store view with only the price that he set?

How would I allow him to edit the info of his entry without having access to anyone else's entry? I am trying to avoid associating nodes from different content types like creating a node type seller's price and reference a book inside of it.

I thought about a combination of field collection, content access, and TAC to try to make each seller capable of entering and editing their own price field collection. While I thought that field collection would create a new collection for every user, this doesn't seem to work: All sellers end up editing the same collection.

Do you have any idea?


Injecting a NEW instance of a service into another service class

1 day 10 hours ago

I have a service (for sending error alerts) which is used by multiple other services.

The alert service is injected into those classes via the relevant services.yml files and through their constructors.

However, both classes share the same instance of the service (something I actually didn't realise until now). If I set a property from one class, it's available for the other class to use later.

In some cases this will be great, but in my use case I want each class to start with a fresh instantation of the alert service class.

Is there a way, through services.yml, the constructors, or any other means, to achieve this?


Add another item by multivalued fields directly from node (or entity) view page

1 day 10 hours ago

I have a file field which can have unlimited number of values. I am using File Entity module. As default, if users want to add more files, they must edit the node.

I'm looking for a solution to give the user the possibility to add another file directly from the node page where the files are displayed/listed. Just like the edit/delete functions from file entity, which the user can edit or delete an existing file directly from the node display using the contextual links hovering the file.

Is there any setting, API function or any hook that I can implement to provide this feature? Any advice will be very helpful.


I don't want editable fields (Edit or Editable Fields as suggested as an answer. They may provide this functionality, but their main purpose is making fields editable, which is much more than I need and I already have the editing and deleting features through the File Entity module, and I only need this functionality for file fields.

I hope I was clear enough, otherwise I could expand my question and provide some screenshots.

Елин Й.

Entity query for distinct field

1 day 11 hours ago

I have an entity line_item with the following fields:

  • id
  • uid (entity reference)
  • product (entity reference)
  • ...

I would like to get all distinct products (product ids) for a specific user.

I tried with entity query:

$query = $this->entity_query->get('line_item'); $query->condition('', $username); $entity_ids = $query->execute();

Unfortunately this results in all line_items from the given user, with multiple times the same product. But what I am interested in is just getting all different products for the given user.


How can I see all the places an asset or entity is referenced?

1 day 12 hours ago

In Drupal 8, I have a requirement from a client that they be able to find a reference of a given asset (file, node, entity, etc) throughout a Drupal site. The ultimate goal is to know that if they want to delete this asset, it's not going to create 404 errors throughout the places on the site where this is referenced in other content.

I'm thinking about a Views page where the name or ID or some type of identifier would be a contextual filter and then would show a list of all nodes or blocks where that relationship exists.

Any thoughts on how to approach solving an issue like this?


Import multiple images with sub_process and image_import

1 day 13 hours ago

I have some nodes with multiple images I want to import. How can I combine sub_process plugin with image_import?

"field_image":[ {"src":"","alt":"Image 1","title":"Image one."}, {"src":"","alt":"Image 2","title":"Image two"} ]

What can I do to loop throw the array of images and import them later.

Here is example of my YML migration process configuration

process: nid: nid title: title field_image: plugin: sub_process source: field_image process: plugin: image_import source: src destination: constants/file_destination title: title alt: alt

Add menu links to custom generated menu

1 day 13 hours ago

I am working on a custom Drupal 8 module which generates a menu. Refer Create a new Menu in Drupal 8 programmatically for details.

I have the menu now, but when I try to add custom menu links to it, following add a menu link, somehow it's not getting added to that custom menu.

Another weird thing is that the links are getting added to the wrong menu, i.e. they show under User Account Management menu.

The only reason I can think of is, when I install the module, Drupal tries to create the menu link first, before it has created custom menu. As the custom menu is not there yet, it tries to add the menu links to another menu. Is that right?

Here is my code, if that helps:

// // This creates the new menu on module install langcode: en status: true dependencies: { } id: aeauth label: 'AE Authentication Links' description: 'Links related to AE Authentication' locked: true // // This adds menu links to menus ae.admin_settings: route_name: ae.adminForm title: 'AE Configuration' description: 'Configure AE for your website' parent: system.admin_config_system ae.register: title: 'Register' description: 'Register using AE Connect' parent: aeauth route_name: ae.regroute ae.login: title: 'Login' description: 'Login using AE Connect' parent: aeauth route_name: ae.loginroute
Akshay Khot
22 hours 43 minutes ago
most recent 30 from
Subscribe to Drupal StackExchange feed