Drupal StackExchange

Reorganize Language Switcher based on Country/Region

1 day 7 hours ago

I'm working on a site with 34+ languages and will likely be expanding to more. With this many countries, a simple drop-down list can be difficult for usability. I would like to customize the language switcher so that I can categorize a language by region and country. I have seen this before, have created similar on other non-Drupal sites, but haven't seen anything like it for Drupal.

Example:

  • Europe
    • Germany
      • DE
    • Switzerland
      • DE
      • FR

etc.

I'm looking for either a module, or a head start on what I might do short of writing some custom PHP for the project.

Jesse Taylor

How to alter output of markup on a specific views field

1 day 8 hours ago

Is there a way to change the output programatically on a specific field in d8 views?

I have a field called 'IMCID' which I want to output as a link, but the link is going to change based on the value of another field for that row.

For example, if IMCID of row #1 is 15, and Format of row #1 is 'Copy', then I want the output URL to be something like example.com/copy/15, however if IMCID of row #1 is 15, and Format is 'Hard Copy', then the output URL would be example.com/hardcopy/15

If possible, I would like to avoid making multiple template files for individual fields, as this functionality will be carried over onto other fields later on, and would rather not have to manage a ton of template files.

I have tried using hook_pre_render() and hook_post_render(), but the markup doesn't appear to be in this hook so I am not sure how to update the link URL.

Ex0r

Drupal 8 block css add

1 day 9 hours ago

I am using a fresh D8 install. I have created a custom block with a token which I have added to a header. The block is themes from somewhere to float left. If I, through "inspect" in the browser, add an element to float right. All my spacing works out great. I dont want to change other site feilds. Just this block and/or content to float right

How do I add CSS to get this block content to float right? Specific files would be handy or ? Your advise?

The html I have copied from the inspect looks like this

<div data-quickedit-field-id="block_content/2/body/en/layout_builder-default-0-73e5980c_7e7f_426b_9046_491d9b827238-2-01e8424e1f1f24943ed5c53651a4049d736f7ab2e67f5602d40887962c657805" class="w3-section field field--name-body field--type-text-with-summary field--label-hidden w3-bar-item field__item" style="float: right;"><h3><a href="/node/8" hreflang="en">Pro Safety</a></h3> </div>

Thanks for Im sure a simple fix

Matthew Gibbon

hybridauth redirection to an emailed link after success login

1 day 10 hours ago

Im using hybridauth to let users login from different social media websites ... I send emails manually to some users with an link to edit specific nodes (for example http://example.com/node/444/edit?parma1=val1&param2=val2). At that moment the user is automatically redirected to a page to choose a social media he want to login with. Im using hook_init for this :

function MYMODULE_init(){ if($node->type == 'type' && other conditions){ drupal_goto('link_to_hybridauth_login_page'); } }

Now I want that user to be automatically redirected to that link sent via email after success login via hybridauth ( I tried to add destination query inside drupal_goto but not working.)

how can I do this redirection ?

Thanks in advance.

Boussetta moez

Passing arguments to a node with an alias url

1 day 11 hours ago

There is a similar issue in here: Passing an argument to a node causes 404

But there is no real viable solution. I tried using the sub-pathauto module but the restiction of 8 arguments is too little, since the urls will look something like this:

www.site.com/alias/key/value-1/key/value-2/key/value-3/key/value-4

and it can go on for a while. It works when instead of alias i have node/nid.

Is it possible to have it work with any amount of dynamic arguments?

user45545

Drupal Downloads PHP files instead of executes them

1 day 14 hours ago

I'm having trouble getting Drupal 10 to properly work on my web server. It's an EC2 instance on AWS behind a loadbalancer for HTTPS, running Nginx as the proxy between the code and PHP-FPM.

HTTPS is working correctly, but the site has multiple issues where clean URLs download the PHP script instead of executing it.

My Nginx config for the site is:

server { listen 80 deferred default_server; listen [::]:80 deferred default_server ipv6only=on; server_name _; root /srv/marketing/web; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php$query_string; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { log_not_found off; access_log off; } location ~ \.php$|^/update.php { try_files $uri =404; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/run/php/php8.1-fpm.sock; include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { expires max; log_not_found off; } location ~* \.(txt|log)$ { allow 192.168.0.0/16; deny all; } location ~ \..*/.*\.php$ { return 403; } location ~ ^/sites/.*/private/ { return 403; } location ~ (^|/)\. { return 403; } location ~ ^/sites/[^/]+/files/.*\.php$ { deny all; } location ~ /\.ht { deny all; } location ~ /vendor/.*\.php$ { deny all; return 404; } }

As far as I can tell from other posts, the pass to PHP-FPM should be working. But why is it only downloading files instead?

Joseph Quinn

Call to undefined function entity_create()

1 day 14 hours ago

i try to include a node creation form by a field attach form. So i try to load the entity of a custom content type created by the back-office with is called 'friterie'. But when i call the entity_create function i get this error : Call to undefined function entity_create()

Here is my code :

function fritr_register_friterie_form($form, &$form_state) { $form = array(); // INCLUDE FRITERIE ADD FORM $form['friterie'] = array(); //module_load_include('inc', 'node', 'node.pages'); this is an old method //$form['friterie'] = node_add('friterie'); global $language; $entity = entity_create('node', array('type' => 'friterie', 'language' => $language->language)); //$form['friterie'] = field_attach_form('node', $entity, $form['friterie'], $form_state); // INCLUDE USER REGISTER FORM //$form['user'] = drupal_get_form('user_register_form'); $form['submit'] = array( '#type' => 'submit', '#value' => t('Enregistrer la friterie'), ); dsm($form); return $form; }

I don't know why i get this error, i watch on the official documentation and it says i can do it like i did :/

Kpone

Getting error from entity.eval.inc - null given in array_values() - upon login after upgrading to 7.100 and php to 8.1.2

1 day 15 hours ago

We recently spun up a new server with newer php. Tested the new server, converted dns records to now point to the new server, etc. I was about to take it out of maintenance and noticed drupal had an update. We were running 7.99. I figured not much risk, never had a problem updating drupal. Still, upgraded in test and it seemed fine, upgraded prod and took it out of maintenance. Now if you log out and log back in you get "The website encountered an error" page. Reloading the page will get you to the after login screen.

The log showed this error message: TypeError: array_values(): Argument #1 ($array) must be of type array, null given in array_values() (line 60 of /usr/share/nginx/oursite/sites/all/modules/rules/modules/entity.eval.inc)

I did the same upgrade to 7.100 on the old server and it doesn't have the problem. It's running php 7.2.24. Of course, with spinning up a new server there are lots of other things that are updated.

I hack the file and fixed it with this:

return array('entity_fetched' => is_array($return)? array_values($return): array());

original code

return array('entity_fetched' => array_values($return);

I find it hard to believe there is bug in the code. I'm guessing we're missing some entity.

Any thoughts on how to fix this properly?

user2487820