2

I have developed a custom template for a node where I wanted to essentially show the node in a blank white page. I created a file called node--results.tpl.php and page--node--results.tpl.php that removed just about everything except a few divs. In my module, I have function called results_view_preprocess_node that adds the custom javascripts and css files I needed and removed.

function results_view_preprocess_node(&$variables) {

  if ($variables['view_mode'] == 'full') {
    $node = &$variables['node'];
    if ($node->type == 'results') {
      //remove all other CSS files
      drupal_static_reset('drupal_add_css');

      $path = drupal_get_path('module','results_view');
      drupal_add_css($path . '/css/styles.css');
      drupal_add_css('sites/all/libraries/jquery/jquery-ui-1.10.4.custom/css/smoothness/jquery-ui-1.10.4.custom.min.css');
      drupal_add_js('/sites/all/libraries/jquery/jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js');

      $id = $variables['nid'];
      drupal_add_js(
        'meetdir="/files/results/' . $id .'";',
        array(
          'type' => 'inline',
          'scope' => 'header',
          'weight' => 5,
          'group' => JS_LIBRARY,
        )
      );

      drupal_add_js(
        array(
          'results_view' => array(
            'path' => drupal_get_path('module','results_view'),
          ),
        ),
        'setting'
       );
      drupal_add_js(
        $path . '/js/advancedResults.js',
        array(
         'type' => 'file',
         'scope' => 'header',
         'group' => JS_LIBRARY,
        )
      );
      drupal_add_js(
        $path . '/js/filter.js',
        array(
          'type' => 'file',
          'scope' => 'header',
          'group' => JS_LIBRARY,
        )
      );

      //drupal_set_message('<pre>' . print_r($variables,true) . '</pre>','warning');
    }

  }
}

I've noticed that when I load a node of this type, I get a large number of warnings and have narrowed it down to drupal_static_reset('drupal_add_css');. When I comment this line out, I don't get the warnings, but then I don't get a clean page.

Notice: Undefined index: group in drupal_sort_css_js() (line 3129 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: group in drupal_sort_css_js() (line 3129 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: group in drupal_sort_css_js() (line 3132 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: every_page in drupal_sort_css_js() (line 3139 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: every_page in drupal_sort_css_js() (line 3142 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: weight in drupal_sort_css_js() (line 3146 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: weight in drupal_sort_css_js() (line 3149 of /mysites/html/development/drupal/includes/common.inc).
Warning: uasort(): Array was modified by the user comparison function in drupal_get_css() (line 3063 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: type in drupal_get_css() (line 3080 of /mysites/html/development/drupal/includes/common.inc).
Warning: ksort() expects parameter 1 to be array, null given in drupal_group_css() (line 3206 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: type in drupal_group_css() (line 3218 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined variable: group_keys in drupal_group_css() (line 3238 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: type in drupal_aggregate_css() (line 3279 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: type in drupal_pre_render_styles() (line 3399 of /mysites/html/development/drupal/includes/common.inc).

As far as I have been able to tell, this is the technique you're supposed to use to create a separate template for a node, but obviously, I'm missing something. What do I need to do to fix this?

EDIT Looking at the rendered HTML, both CSS files I add using drupal_add_css are linked like this:

<style type="text/css" media="all">
   @import url("http://www.oregonswimming.org/sites/all/modules/results_view/css/styles.css?ngdwh6");
   @import url("http://www.example.com/sites/all/libraries/jquery/jquery-ui-1.10.4.custom/css/smoothness/jquery-ui-1.10.4.custom.min.css?ngdwh6");
   @import url("http://www.example.com/modules/shortcut/shortcut.css?ngdwh6");
   @import url("http://www.example.com/modules/toolbar/toolbar.css?ngdwh6");
 </style>
  • drupal_add_css() does add those array indexes, when they are not present. The problem is not the code you are showing. – kiamlaluno Apr 19 '14 at 6:23
  • jQuery Update module provides jQuery UI up to version 1.10.2. Is there something specific you need in 1.10.4 ? or is it the custom UI theme ? – jowan sebastian Dec 10 '14 at 21:50
  • That's just the latest version I have. The jQuery version shouldn't have anything to do with the PHP errors. – Robbert Dec 10 '14 at 22:00
  • Can you try making all the drupal_add_css absolute, or set 'external' after them: drupal_add_css(LOCATION,'external'); – Daniel Waters Dec 11 '14 at 11:08
0

Well, if group, page, weight etc are missing or undefined, try this :

$file = drupal_get_path('module','results_view') . '/css/styles.css';
drupal_add_css($file, array(
    'type' => 'file',
    'group' => CSS_DEFAULT,
    'every_page' => TRUE,
    'weight' => 0),
    );

Maybe following a drupal_static_reset('drupal_add_css'); calls to drupal_add_css need these attributes. Perhaps the functions defaults get reset as well.

  • drupal_add_css() initializes those array indexes already, as long as the first argument is not NULL: if (isset($data)) { }. – kiamlaluno Dec 13 '14 at 18:09
  • I presumed so, looking at the docs. but wondered if it worked for the OP ? if it does (or even if it doesn't) it looks like something else is causing the problem. – jowan sebastian Dec 13 '14 at 19:23
  • Your suggestion was promising, but didn't work. – Robbert Dec 14 '14 at 0:05
  • @Robbert Clearly, it is something else causing the problem, probably a module. Possibly there is one that doesn't call drupal_add_css(). – kiamlaluno Dec 14 '14 at 4:58
  • I'm using drupal_static_reset to remove all drupal css files. That's what I read was the technique to accomplish this. The problem goes away when I comment out that line but then I have styles from other css files I don't want on this node page. It seems to me this is a bug in common.inc not checking if the array key exists before doing its thing. – Robbert Dec 14 '14 at 6:15
0

I ended up removing drupal_static_reset('drupal_add_css'); from my code and overriding all the drupal css styles in my own CSS file. It's a pain but the only way I can find to get rid of all the errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.