Drupal StackExchange

Add print button in the "Review order" page

2 hours 47 minutes ago

I want to know, is there any way to add print button to "Review order" page.

by clicking this button, a pop up page is loaded with good style for print mode and user can print the cart items , taxes and all information in Review order page.

Please guide me.

Mehrdad201

Load disabled items in a menu

3 hours 47 minutes ago

I load my main menu programmatically with the following code :

$menuTree = \Drupal::menuTree(); $menuTreeParameters = $menuTree->getCurrentRouteMenuTreeParameters($name); $menuTreeParameters ->setMinDepth($minLevel) ->setMaxDepth($maxLevel); $tree = $menuTree->load($name, $menuTreeParameters); $tree = $menuTree->transform($tree, $this->getDefaultManipulators()); return render($menuTree->build($tree));

I would like to get all my menu items, included thoses which are disabled. When I inspect $tree variable, I have all my menu items.

I don't know why but after the call to the build method, I get only my enabled items.

kero_zen

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

4 hours 44 minutes 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

Exposed filter list by tags

5 hours 46 minutes ago

I have a view, which is listing nodes. I like to exposed filter it by tags (what is a taxonomy). But I like to show tags, what is relevant (has nodes) for the current view. How can I make it?

Ámon Tamás

Render Custom Menu Block from Menu Tree Array of Links Programmatically

8 hours 43 minutes 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

Why my query string generates page not found for my view?

9 hours 43 minutes ago

In Drupal 7 I'm using a view export to download information for my orders.

If i go to the default url /admin/commerce/orders then the page downloads correctly.

However, I also have some filters so I can download only the orders I need, this passes a query string to the view which causes a 404 error (page not found).

In example:

/admin/export/orders?status[0]=invoiced&event=All&school=&uid=&held=All&attach=admin_page

I can't find out why this is causing a 404 error.

I have another view with the same configuration and it works fine. It is a number of query or something?

LeeUDO

how to check only some options in a form with hook form alter

10 hours 13 minutes ago

i am using hook form alter on drupal 9 and I want some of the select options to be checked . I can change the select options, but i can't make only some of them be checked i tried setting the default value like this $form['field_learning_path_category_target_id']['#default_value'] = array(11); where 11 is the key of the options which i want selected.

which has no effect , as well as changing the attributes as below but only succeed in getting all of them checked with the code below , how do i check only the ones i want ?

$form['field_learning_path_category_target_id']['#attributes'] = [ 'id' => 11, 'checked' => true, ];

and

$form['field_learning_path_category_target_id']['#attributes'] = array('checked' => 'checked');
Diana

Failure getting nodes from terms via the rest api

10 hours 48 minutes ago

I have added a REST web service in Drupal and all content is tagged with taxonomy. I'm now trying to acquire all related nodes to the terms.

First I'm calling taxonomy_vocabulary/getTree along with the vid and I'll get all the terms for a specific vocabulary, that works just fine. The problem comes when I've gotten all the term-id's I need to go through. When I create a request it fails to find the nodes that should be connected to the term. I'll get a 404 response on each request.

This is how I call the selectNodes. I'm creating a POST request and pass along with the tid, the endpoint is called http://myhostname/api/taxonomy_term/selectNodes

Have someone else experienced this? Do I need to pass more arguments with the POST call?

EDIT: After a quick look in wireshark it also returns the error string: "String value: No nodes were found with tid 15". Does this mean that there aren't any relation between the terms and the nodes by default?

David Wiktorsson