Render Custom Menu Block from Menu Tree Array of Links Programmatically

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.

enter image description here

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.

enter image description here

This yields:

enter image description here

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!

Trying to display or render values from links field within paragraph field base on its current language

I’m currently using Drupal 8 Paragraph and I’m trying to figure out how I can display or output the url and title of a link field from within a Paragraph base on the current language via preprocess. Here is a snippet of the code I’m working on.

function iom_preprocess_paragraph(&$  variables) {      $  language = \Drupal::languageManager()->getCurrentLanguage();     $  variables['lang_code'] = $  language->getId(); } 

function _preprocess_primary_links_paragraph($  paragraph, &$  variables) {     // Current page node     $  currentNode = \Drupal::request()->attributes->get('node');     $  activeLanguage = \Drupal::languageManager()->getCurrentLanguage()->getId();     $  links = [];      foreach ($  paragraph->field_link as $  link) {         $  entity = _loadEntityByUri($  link->uri);          $  title = $  link->title;          // If there is an entity and the title is not set of the link         // use the entity title instead         if ($  entity && !$  title) {             $  title = $  entity->title->value;         }          $  links[] = _generatePrimaryLinkElement($  currentNode, $  entity, $  title, $  link->getUrl()->toString());     }      $  variables['label'] = $  paragraph->field_label->value;     $  variables['links'] = $  links; } 

<div class="sidebar-menu-group primary-link">     <span class="label">{{ label }}</span>     <ul class="menu -sidebar">           {% for link in links %}              <li {{link.attributes}}>                 <a {{link.link.attributes}}>{{link.title}}</a>             </li>         {% endfor %}     </ul> </div> 

How can I get emojis to render properly on a Samsung Galaxy S8+?

My wife has a Samsung Galaxy S8+ with Oreo. Often when I send her a text containing an emoji, or she sends me one, the other person receives it as a box like this: ☒

I have a Nokia 6.1. But my suspicion is that her phone, not mine, is the problem, because I saw the same thing when I had a Windows phone.

What do I need to do to her phone to get it to send emojis properly?

Carte Server web page render issue

Recently we have upgraded our Pentaho Data Integration Installation from 7.1 to 8.2 We have also carte server installed on same machine which points to latest version of data integration.

Carte server can be accessed as http://localhost:8081

After upgrade when we access Carte server using http://machinename:8081, web page doesn’t render the content properly in the browser.

Any suggestions regarding it?

Thank Dhru

Changing ‘#view_mode’ in content type’s render array

I have a content type in Drupal 8 project that has image, name, info and body field as a default display, and image,name and information as a teaser display. I am able to display this content type with teaser view at the page, but right under that i would like to get the default display along with body field so i can create a bootstrap modal with that.

I am using hook_node_view in the module level to change the #view_mode of that render array to ‘full’ instead of ‘teaser’.

function team_bio_node_view(array &$  build, \Drupal\Core\Entity\EntityInterface $  entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $  display, $  view_mode) {  if($  entity->bundle() == 'about_us'){  if($  view_mode == 'full'){   if($  display->getComponent('field_team_bio')){     $  build['full_view'] =  $  build['field_team_bio'];      $  build['full_view'][] = array(        'full_view' =>array(          '0'=>array(             '#view_mode'=>'full'          ),          '#weight'=>'103'        )     );     kint($  build);    }  } } } 

i can display the content type right under teaser views, but i can’t change the view_mode to full. This is what i see when i kint($ build):

enter image description here

Current contents have name like ‘0’,’1′,’2′,’3′,’4′, and they have the view mode that are ‘teaser’ but i dont how to pass ‘view_mode’ to ‘full’in render array, I am not sure if there is specific name for that or not. Trying this:

     $  build['full_view'][] = array(        'full_view' =>array(          '0'=>array(             '#view_mode'=>'full'          ) 

didnt change the view_mode neither. So my question: What is the best way to change these view modes to full for the contents? Should I search these numeric keys in the array and pass them to another array then change view_mode like that? Or is there an easier way to approach the problem?

httpd24 by scl doesn’t render php

I have installed httpd24 with php72 by scl in a CentOS 6.10 x86-64 environment. But Apache doesn’t render php files and display them as text.

Installed php using,

yum install php72-php php72-php-iconv php72-php-mbstring php72-php-curl php72-php-openssl php72-php-tokenizer php72-php-xmlrpc php72-php-soap php72-php-ctype php72-php-zip php72-php-gd php72-php-simplexml php72-php-spl php72-php-pcre php72-php-dom php72-php-xml php72-php-xml php72-php-intl php72-php-json php72-php-mysqlnd php72-php-ldap 

When I run,

apachectl -M | grep php 

Output:

php7_module (shared)

When I run,

php -v 

Output:

PHP 7.2.14 (cli) (built: Jan 8 2019 11:55:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Not able to render images quicklatex?

[latex] [+preamble] \usepackage{amsmath} [/preamble] 

 \begin{align*}f(x)&=e^{\sqrt{cot~x}}\f(x+h)&=e^{\sqrt{cot(x+h)}}\dfrac{d}{dx}f(x)&=lim_{h\to0}~\dfrac{f(x+h)-f(x)}{h}\&=lim_{h\to0}~\dfrac{e^\sqrt{cot(x+h)}-e^\sqrt{cot~x}}{h}\&=lim_{h\to0}~e^\sqrt{cot~x}~.\dfrac{e^{\sqrt{cot(x+h)}-\sqrt{cot~x}}-1}{h}\&=lim_{h\to0}~e^\sqrt{cot~x}~.\Bigg(\dfrac{e^{\sqrt{cot(x+h)}-\sqrt{cot~x}}-1}{\sqrt{cot(x+h)}-\sqrt{cot~x}}\Bigg)\times\dfrac{\sqrt{cot(x+h)}-\sqrt{cot~x}}{h}\hspace{1cm}\Bigg[Since,~lim_{x\to0}~\dfrac{e^x-1}{x}=1\Bigg]\&=lim_{h\to0}~e^\sqrt{cot~x}~.\dfrac{\sqrt{cot(x+h)}-\sqrt{cot~x}}{h}\&=lim_{h\to0}~e^\sqrt{cot~x}~.\dfrac{\sqrt{cot(x+h)}-\sqrt{cot~x}}{h}\times\dfrac{\sqrt{cot(x+h)}+\sqrt{cot~x}}{\sqrt{cot(x+h)}+\sqrt{cot~x}}\hspace{1cm}[Rationalising~the~numerator]\&=lim_{h\to0}~e^\sqrt{cot~x}~.\dfrac{{cot(x+h)}-{cot~x}}{h\times({\sqrt{cot(x+h)}}+\sqrt{cot~x})}\&=lim_{h\to0}~e^\sqrt{cot~x}~.\dfrac{\dfrac{cot~(x+h)~cot~x+1}{cot~(x+h-x)}}{h\times({\sqrt{cot(x+h)}}+\sqrt{cot~x})}\hspace{1cm}\Bigg[cot~(A-B)=\dfrac{cot~A~cot~B+1}{cot~A-cot~B}\Bigg]\&=lim_{h\to0}~e^\sqrt{cot~x}~.\dfrac{\dfrac{cot~(x+h)~cot~x+1}{cot~h}}{h\times({\sqrt{cot(x+h)}}+\sqrt{cot~x})}\&=lim_{h\to0}~e^\sqrt{cot~x}~.\dfrac{{cot~(x+h)~cot~x+1}}{{cot~h}\times{h}\times({\sqrt{cot(x+h)}}+\sqrt{cot~x})}\&=lim_{h\to0}~e^\sqrt{cot~x}~.\dfrac{{cot~(x+h)~cot~x+1}}{\dfrac{h}{tan~h}\times({\sqrt{cot(x+h)}}+\sqrt{cot~x})}\&=lim_{h\to0}~e^\sqrt{cot~x}~.\dfrac{{cot~(x+h)~cot~x+1}}{\dfrac{h}{\dfrac{tan~h}{h}\times{h}}\times({\sqrt{cot(x+h)}}+\sqrt{cot~x})}\hspace{1cm}\Bigg[Since,~lim_{h\to0}~\dfrac{tan~h}{h}=1\Bigg]\&=\dfrac{e^{\sqrt{cot}}\times(cot~x^2+1)}{2\sqrt{cot~x}}\hspace{1cm}\Bigg[Since,~(1+cot^2~x=cosec^2~x)\Bigg]\&=\dfrac{e^{\sqrt{cot}}cosec^2~x}{2\sqrt{cot~x}}\end{align*} 

[/latex]

do not know why quicklatex not able to render images ?

How do I render values of input elements into a div correctly?

I’m trying to grab an input value with javascript and render it into a div element. What do I do to make it work?

I’m using querySeclector to grab the input value. When I hardcode it like this:

document.getElementById("result").innerHTML = "Hello World"; 

It works but doesn’t when I replace “Hello World” with the variable that stores the input value and when I do a console.log, I get nothing back even though there are no errors.

HTML

<body>     <div id="container">         <div id="values">             <input id="firstinput" type="text" placeholder="Enter 2 positive figures">             <button id="submit">Submit</button>         </div>         <div id="result"></div>     </div>  <script src="script.js"></script> </body> 

JAVASCRIPT

let submitButton = document.querySelector("#submit"), showResult = document.getElementById("result").innerHTML, weightsForLeftAndRightSides = document.querySelector("#firstinput").value;  submitButton.addEventListener("click", weightBalancer);  function weightBalancer() {     showResult = weightsForLeftAndRightSides;     console.log(weightsForLeftAndRightSides); } 

How to preprocess group title render in views?

I tried to preprocess a title of the group in the result of the rendering of the view.

Example:

Actual: Group 1 title Item 1 Item 2 Item 3 Group 2 title Item 4 Item 5 Item 6

Expected: <span class="test">Group 1 title<span> Item 1 Item 2 Item 3 <span class="test">Group 2 title</span> Item 4 Item 5 Item 6

Here the similar question on the drupal.org https://www.drupal.org/project/drupal/issues/2950737.