Hi all!

With this module i got erros
Warning: array_keys() expects parameter 1 to be array, null given в функции similarterms_list() (строка 197 в файле Z:\home\easyflash.ru\www\sites\all\modules\similarterms\similarterms.module).

How fixed this in similar by terms 7.x-1.0-beta3?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

areynolds’s picture

From a brief glance, it looks like similarterms doesn't support using pathauto aliases. Check out the code around line 167:

  if (arg(0) == 'node' && is_numeric(arg(1)) && !$nid) {
    $nid = arg(1);
  }

$nid will be null if this doesn't evaluate, leading to the error that we're both experiencing.

areynolds’s picture

Status: Active » Closed (works as designed)

The short hack below that will enable aliases to be used; if there's more demand or if V2 is going to take a while for D7, I can write a patch which puts this option into the admin interface. Insert this code around line 167 (we're appending the elseif statement to the if statement which I mention in my above post).

if (arg(0) == 'node' && is_numeric(arg(1)) && !$nid) {
    $nid = arg(1);
  }elseif(module_enabled('pathauto')){
      //Get the system path from the alias
      $alias = $_GET['q'];
      $path = drupal_get_normal_path($alias);
      $path_array = explode('/', $path);
      if($path_array[0] == 'node' && is_numeric($path_array[1]) && !$nid){
        $nid = $path_array[1];
      }
   }

Something like this should work, although you might want to add in some extra validation for your specific use case to make sure that you aren't running the path retrieval for every page, even if it isn't a node. That's the way I'm going to do it for my site, so let me know if you want an example or something.

areynolds’s picture

For right now, I'm just marking this as "closed, works as designed". I took a quick look around the issue queue and didn't see anyone else complaining about this. This issue will ultimately be solved by the 2.0 branch coming to D7, which has views integration (this is already the case on D6).

If you think you're experiencing the error for another reason than path aliasing, please reopen the issue

areynolds’s picture

Status: Closed (works as designed) » Active

Ok, should have done some more debugging until I spoke up :)

arg(1) should get the nid from the original system path, whether or not you're using an alias. This means I was totally wrong and the problem lies somewhere else.

Also note that my permutation of the issue has rendered the module inoperable.

areynolds’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev
FileSize
945 bytes

Note the code starting on line 517, dev branch:

foreach ($node_fields as $item) {
        if (($vid == NULL) || ($item['taxonomy_term']->vid == $vid)) {
            $terms[$node->vid]['tid'][$item['tid']] = $item['taxonomy_term'];
        }

$item['taxonomy_term'] doesn't exist; there's just $item['tid']. We can't link up terms with vocabulary ids this way, so if a $vid is given in similarterms_taxonomy_node_get_terms(), we have to load more data. This is one way to make it work:

foreach ($node_fields as $item) {
        if ($vid == NULL){
          $terms[$node->vid]['tid'][$item['tid']] = $item['tid'];
        }else{
          $term = taxonomy_term_load($item['tid']);
          if($term->vid == $vid){
            $terms[$node->vid]['tid'][$item['tid']] = $term->tid;
          }
        }
      }

Of course, this could probably be more performant by matching the $field vocabulary (we can get the vocabulary machine name from $field) with the $vid. My only question is how best to get the vocab machine name from the $vid:

  • Load the vocabulary object using taxonomy_vocabulary_load
  • Load the vocabulary machine name with db_query

Ideas?

I've attached a patch against the current dev version to get things running, let me know how that works out and if you have any suggestions.

areynolds’s picture

Assigned: AndreyMukha » areynolds
Status: Active » Needs review
areynolds’s picture

Status: Needs review » Closed (duplicate)

This issue is a duplicate of 1277256 and 1260750; I'm marking it as a duplicate, progress is probably best followed in 1277256.

areynolds’s picture

Issue summary: View changes

fixed mistake