How do I implement the login, register and "Forgotten password" forms?

1 month 3 weeks ago

I'm trying to implement the three Drupal 8 user forms : login, register account and forgotten password forms.

I'm creating custom pages in my module for each one of them because I want to display content around those forms, change titles, hook the forms.

I'm having a hard time to do it, especially to get those forms in order to send them to the template and render them.

romain ni

Changing group visibility needs group content to be resaved when group content visibility field is set to "Use group defaults"

1 month 3 weeks ago

Drupal Commons 7.x-3.2
Organic Groups 7.x-2.1

Content type: Mygroup
Field: Group visibility - value: Public

Content type: Mypost
Field: Group - default value: Mygroup
Field: Group content visibility - default value: Use group defaults

Now when I create a group and a post based off on these content types everything is fine. As in everything is visible for all users.

Now when I change the Group visibility to Private I would except the post to not be visible anymore (because of the Use group defaults setting.

Unfortuanetely that's not working until I resave the post content. Then it will respect it's parent's settings.

This bug is mentioned in this video (around 6 min)

Does anyone know how to solve this problem?

devunder

Adding a webform in a webform confirmation

1 month 3 weeks ago

I've been given a requirement to allow for a webform to be inserted into another webform's confirmation page.

At first I tried this with a token I could insert into the confirmation message, the form appears fine, but of course, the new webform is inside of the "parent" webform, which strips out the form tag.

So now I have overriden a few of the webform and webform submission entities handlers, so I can write my own custom getCustomForm function, I can get the new form appearing, but the submit behaviours are weird.

I've tried many things including:

return Webform::load( $webform->getThirdPartySetting('my_module', 'webform') )->getSubmissionForm();

and

$form['confirmation'] = [ '#type' => 'webform', '#webform' => $webform->getThirdPartySetting('wwf_fields', 'webform'), '#source_entity' => $webform, '#message' => [ '#type' => 'inline_template', '#template' => $webform->getSetting('confirmation_message') ] ];

Is there some combination of code I'm missing, or am I trying to bend the system a little too much?

Thanks!

user69676

Updating core to 8.9.6 fails

1 month 3 weeks ago

I'v installed Drupal 8 by composer. Everything worked fine, but when I tried to update core from 8.9.1 to 8.9.5 in ended up in 8.9.4.

Today I tried to update from 8.9.4. to 8.9.6 by changing composer.json to demand v 8.9.6 at least.

The result was following error message:

Your requirements could not be resolved to an installable set of packages. Problem 1

  • Installation request for symfony/http-kernel (locked at v3.4.41) -> satisfiable by symfony/http-kernel[v3.4.41]. > - drupal/core-recommended 8.9.6 requires symfony/http-kernel v3.4.44 -> satisfiable by symfony/http-kernel[v3.4.44]. > - drupal/core-recommended 8.9.x-dev requires symfony/http-kernel v3.4.44 -> satisfiable by symfony/http-kernel[v3.4.44]. > - Conclusion: don't install symfony/http-kernel v3.4.44 > - Installation request for drupal/core-recommended ^8.9.6 -> satisfiable by drupal/core-recommended[8.9.6, 8.9.x-dev].

I'm stuck, since I don't know what locks symphony/http-kernel to v3.4.41.

I'm still pretty new with composer and would be glad if anybody could help me. Thanks a lot.

EDIT 1

{ "name": "drupal/legacy-project", "description": "Project template for Drupal 8 projects with composer following drupal/drupal layout", "type": "project", "license": "GPL-2.0-or-later", "homepage": "https://www.drupal.org/project/drupal", "support": { "docs": "https://www.drupal.org/docs/user_guide/en/index.html", "chat": "https://www.drupal.org/node/314178" }, "repositories": [ { "type": "composer", "url": "https://packages.drupal.org/8" } ], "require": { "civicrm/civicrm-asset-plugin": "~1.0.0", "civicrm/civicrm-core": "~5.28", "civicrm/civicrm-drupal-8": "~5.28", "civicrm/civicrm-packages": "~5.28", "composer/installers": "^1.2", "drupal/admin_toolbar": "^2.2", "drupal/antibot": "^1.4", "drupal/at_tools": "^3.2", "drupal/barrio": "1.x-dev", "drupal/captcha": "^1.0", "drupal/clever_theme_switcher": "^3.0", "drupal/colorbox": "^1.4", "drupal/commerce": "^2.17", "drupal/commerce_shipping": "^2.0@RC", "drupal/core-composer-scaffold": "^8.9.6", "drupal/core-project-message": "^8.9.6", "drupal/core-recommended": "^8.9.6", "drupal/core-vendor-hardening": "^8.", "drupal/ctools": "^3.4", "drupal/editor_advanced_link": "^1.6", "drupal/editor_file": "^1.4", "drupal/entity_browser": "^2.4", "drupal/hotkeys_for_save": "^1.0", "drupal/imce": "^2.3", "drupal/layout_builder_kit": "^1.0@beta", "drupal/layout_builder_modal": "^1.0", "drupal/linkit": "^4.3", "drupal/media_library_theme_reset": "^1.0@beta", "drupal/menu_block": "^1.5", "drupal/menu_item_role_access": "^2.0", "drupal/mobile_device_detection": "^3.2", "drupal/module_filter": "^3.1", "drupal/nagios": "^1.9", "drupal/pathauto": "^1.6", "drupal/permissions_by_term": "^2.18", "drupal/pixture_reloaded": "^3.0", "drupal/printable": "^1.1", "drupal/quick_node_clone": "^1.12", "drupal/redirect": "^1.5", "drupal/superfish": "^1.3", "drupal/swiftmailer": "^2.0@beta", "drupal/token": "^1.6", "drupal/upgrade_status": "^2.0", "drupal/views_conditional": "^1.0", "drupal/views_slideshow": "^4.7", "drupal/webform": "^5.9", "drupal/webform_civicrm": "^5.0@beta", "drupal/xmlsitemap": "^1.0@RC", "wikimedia/composer-merge-plugin": "^1.4" }, "conflict": { "drupal/drupal": "*" }, "minimum-stability": "dev", "prefer-stable": true, "config": { "sort-packages": true }, "extra": { "drupal-scaffold": { "locations": { "web-root": "./" } }, "installer-paths": { "core": [ "type:drupal-core" ], "libraries/{$name}": [ "type:drupal-library" ], "modules/contrib/{$name}": [ "type:drupal-module" ], "profiles/contrib/{$name}": [ "type:drupal-profile" ], "themes/contrib/{$name}": [ "type:drupal-theme" ], "drush/Commands/contrib/{$name}": [ "type:drupal-drush" ], "modules/custom/{$name}": [ "type:drupal-custom-module" ], "themes/custom/{$name}": [ "type:drupal-custom-theme" ] }, "merge-plugin": { "include": [ "modules/contrib/webform/composer.libraries.json" ] }, "drupal-core-project-message": { "include-keys": [ "homepage", "support" ], "post-create-project-cmd-message": [ "<bg=blue;fg=white> </>", "<bg=blue;fg=white> Congratulations, you’ve installed the Drupal codebase </>", "<bg=blue;fg=white> from the drupal/legacy-project template! </>", "<bg=blue;fg=white> </>", "", "<bg=yellow;fg=black>Next steps</>:", " * Install the site: https://www.drupal.org/docs/8/install", " * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html", " * Get support: https://www.drupal.org/support", " * Get involved with the Drupal community:", " https://www.drupal.org/getting-involved", " * Remove the plugin that prints this message:", " composer remove drupal/core-project-message" ] } }

}

My update command was

composer u drupal/core* --with-dependencies
paul77

Strict case in content URL alias

1 month 3 weeks ago

(Pathauto: Leave case the same as source token values)

When I create a node with "Nullam vehicula pharetra" as title, the Pathauto module will create /content/Nullam-vehicula-pharetra as URL alias. But we can browse the same content with a different URL case, such as /content/NULLam-vehicula-pharetra.

How do I make Drupal strict on the URL alias case?

Wikipedia is good example about what I need. Two different case request return different contents:

jibotak

Reorganize Language Switcher based on Country/Region

1 month 3 weeks 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 month 3 weeks 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 month 3 weeks 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 month 3 weeks 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 month 3 weeks 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 month 3 weeks 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 month 3 weeks 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 month 3 weeks 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

Render Custom Menu Block from Menu Tree Array of Links Programmatically

1 month 3 weeks ago

Here's what I have: A custom menu (side nav) that mimics the main/secondary menu tree which shows the entire subtree of the root menu item (Dine, Play, Stay) you're under.

This sidenav can be shortened with a checkbox field in the content type. If checked, the sidenav shows the checked page as the root and all children, recursively, but omits any parents of the checked page. I've successfully created that menu and this all works on the checked pages.

This yields:

This is done by creating both menus, then adding a "hide" css class to one of them in the template_preprocess_page() function, depending on the checkbox of the current node.

MY ISSUE: The final thing I need it to do is when you are on a CHILD page of a parent with the shortened nav checked, I need it to still show that shortened nav. So on the example above, when on the Visitor FAQ page, it needs to show the shortened menu from Visitor Tips (with the current page bolded or whatever). So it needs to grab the field from the parent node, and if it is true, grab the shortened submenu array, which I've done, but I haven't been able to render the menu tree array into html correctly.

Here's the current code for grabbing the submenu (from the full menu), and it saves the menu array in $alternateSecondaryMenu. I also tried saving in $vars['secondary_nav'], which is the key Drupal uses for the rendered menu array, but I think the menu has already rendered by the time it calls preprocess_page(). I just can't figure out how to render that menu tree. (The menu is 4 levels deep, level 0 being the root menu item, so this only happens on level 1 or level 2.)

In template.php:

function THEME_preprocess_page(&$vars) { // Follow active-trail and check if short/long menu is toggled // *********************************************************** if(!empty($vars['secondary_nav'])) { // Level 1 foreach($vars['secondary_nav'] as &$topmenuitem) { // for each top level item if(!empty($topmenuitem['#title'])) { if(in_array('active-trail', $topmenuitem['#attributes']['class'])) { // check if in active-trail (parent) // load the node of the parent menu item $firstnid = str_replace('node/','',$topmenuitem['#href']); $firstnode = node_load($firstnid); // check for shortened menu checkbox if (array_key_exists('field_show_menu_as_parent',$firstnode) && $firstnode->field_show_menu_as_parent && $firstnode->field_show_menu_as_parent['und'][0]['value']) { dsm("1. YES, shortened menu."); // Saving this submenu in these variables $vars['secondary_nav'] = $topmenuitem; // this is the drupal-made array that shows the menu in question $alternateSecondaryMenu = $topmenuitem; // just saving to some other variable, too. } else { dsm("1. NO shortened Menu for you!"); } // Level 2 (same as level one) foreach($topmenuitem['#below'] as &$secondmenuitem) { if(!empty($secondmenuitem['#title'])) { if(in_array('active-trail', $secondmenuitem['#attributes']['class'])) { $secondnid = str_replace('node/','',$secondmenuitem['#href']); $secondnode = node_load($secondnid); if (array_key_exists('field_show_menu_as_parent',$secondnode) && $secondnode->field_show_menu_as_parent && $secondnode->field_show_menu_as_parent['und'][0]['value']) { dsm("2. YES, shortened menu."); $vars['secondary_nav'] = $secondmenuitem; $alternateSecondaryMenu = $secondmenuitem; } else { dsm("2. NO shortened menu for you!"); } } } } } } } } dsm(drupal_render($alternateSecondaryMenu)); // Only renders an <li> of the current node, not the <ul> or the children <li>, even though it has the whole menu tree. dsm($vars['secondary_nav']); // doesn't render anything because this preprocess_page() is called after the elements of the page have already rendered, right? }

I am using Panelizer to display and Menu Block to create the menu (only modules that ones that might be relevant).

Do I need to call the theme_menu_tree() and theme_menu_link() functions on this array again to render it, somehow? I wasn't able to get render() or drupal_render() to work. Also tried doing this with menu_preprocessing/tree functions but was having difficulty getting the checkbox value in the nodes. Any ideas or help would be GREATLY appreciated.

Thanks!

ProGrammar

Theme video-embed-iframe.html.twig by content type

1 month 3 weeks ago

I am using Drupal 8 and trying to theme video-embed-iframe.html.twig by content type. with the current naming suggestions this is not possible.

I am using Media with video embed field containing in a field called video

This is what I did so far. in the fields template named above in the templates folder of my theme

{% if logged_in %} <iframe{{ attributes }}{% if url is not empty %} src="{{ url }}{% if query is not empty %}?{{ query | url_encode }}{% endif %}"{% endif %}></iframe> {% else %} <div id="promotion"> <div id="promotion-image"> <div id ="promotion-bg"> <div id ="promotion-text"> <H1>Eine brilliante Überschrift</H1> </div> </div> </div> <span id="promotion-attribution"> <a href="http://somesite.com">Credit author of the background image</a></span> </div> {% endif %}

I have no clue how to access the field by content type to separate the code deepening if you have a content type eg page and article Any Ideas?

Is there a way to populate a global var like logged in containing the mashine name of the content type without needing a custom module. I other words is there a way to populate a var like

contenttype=anycotenttypehere in the mytheme.theme file by writing a function? to be able to display the video depending on with contetnt type has been used and if the user is logged in or not

Josh

Inline Editing Weight Field on admin view

1 month 3 weeks ago

I am working on a Drupal 10 site and and I have a built an admin view that has 2 fields. Node title and Weight. I would like to be able to on that view edit the weight inline on each node and save it. It looks like the modules that could do this in previous versions of Drupal are no longer supported in Drupal 10.

Does anyone know of a way to do this?

ThankYouNeco
Checked
11 hours 25 minutes ago
most recent 30 from drupal.stackexchange.com
Subscribe to Drupal StackExchange feed