if (isset($variables['#theme']) || isset($variables['#theme_wrappers'])) {
    $element = $variables;
    $variables = array();
    if (isset($info['variables'])) {
      foreach (array_keys($info['variables']) as $name) {
        if (isset($element["#$name"])) {
          $variables[$name] = $element["#$name"];
        }
      }
    }
    else {
      $variables[$info['render element']] = $element;
    }
  }

What I wonder is why we add this line,why not just

$variables = $element;

Can some one help us make it clear. Thank you very much.

Comments

Kuldip Gohil’s picture

Hi, its simple $variables will be passed by reference in your theme function so it will be multidimensional array and it holds values which assigned on other functions.

so when you will do $variables = $element; it will override value of $variables with $element.

To realize this, you can print $variables in start of your function.

Hope this will make sense and clear your doubt.

Thanks,
Kuldip Gohil

qqboy’s picture