Hi

Is it possible to get a check on the links parsed by hook_link_alter? I'm getting some errors with other modules using $links in non-standard ways.

Thanks

From:

<?php

/**
 * Implementation of hook_link_alter().
 */
function securepages_link_alter(&$node, &$links) {
  if (!variable_get('securepages_enable', 0)) {
    return;
  }
  foreach ($links as $module => $link) {
    if ($link['href']) {
?>

To:

<?php

/**
 * Implementation of hook_link_alter().
 */
function securepages_link_alter(&$node, &$links) {
  if (!variable_get('securepages_enable', 0)) {
    return;
  }
  foreach ($links as $module => $link) {
    if (is_array($link) && !empty($link['href'])) {
?>

Comments

alexmarkley’s picture

This is actually manifesting as a bug for me:

PHP Fatal error: Cannot use object of type stdClass as array in /home/web/malexmedia/malexmedia/modules/contrib/securepages/securepages.module on line 187, referer: https://malexmedia.net/node/add/forum/9

I haven't really had time to chase down the exact combination of factors that's causing this. For now, I've rolled my site back to a previous 6.x-1.x-dev version.

alan d.’s picture

Just a minor correction to my code above, there should have been an is_array check

gordon’s picture

Status: Active » Closed (won't fix)

This is actually a problem with another module which is returning an array of objects instead of an array of link arrays. If you look at http://api.drupal.org/api/function/hook_link/6 you will see that it is an array and not an object that should be returned.