0

I'm trying to make a block display on a specific page and inside a node type; I got this code from drupal.org, but I keep getting this error.

Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /home/content/45/6861545/html/includes/entity.inc).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of /home/content/45/6861545/html/includes/entity.inc).

This is the code I used.

$match = FALSE;
$types = array('middle_content' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
  $nid = arg(1);
  $node = node_load(array('nid' => $nid));
  $type = $node->type;
  if (isset($types[$type])) {
    $match = TRUE;
  }
}

if (substr($_SERVER["REQUEST_URI"], 0, 10) == '/test'){
  $match = TRUE;
}

if (substr($_SERVER["REQUEST_URI"], 0) == "/node/add/middle_content") {
  $match = TRUE;
}

return $match;
3

To actually fix that error, see my answer to a stackoverflow question.

However, in that case, your code can be simplified a lot using menu_get_object():

$types = array('middle_content' => 1);
if ($node = menu_get_object()) {
  if (isset($types[$node->type])) {
    return TRUE;
  }
}

And anyway, you should avoid PHP in blocks etc (See What are the downsides of using PHP Filter code in blocks, nodes, views-args, etc?), check out Context. It allows you to configure your blocks (among other things) for conditions exactly like this without having to write code. It is also much faster.

0

The actual error is occurring because node_load() either takes an integer or a numeric array of nids, not an associative array. $node = node_load($nid); is perfectly valid.

That said, Berdir's answer is a better solution.

  • 1
    That's what my linked answer is saying exactly. I initially only had that and then edited the other parts in :) – Berdir Apr 23 '11 at 10:47
  • Well there you go. Upvote for you :) – tim.plunkett Apr 23 '11 at 14:50
  • Thanks, slightly updated my answer to give some context to that link. – Berdir Apr 23 '11 at 15:29

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.