1

i am using this hook in my custom module but getting a fatal error

Fatal error: Cannot use object of type stdClass as array in C:\wamp\www\bid\includes\common.inc on line 5901

Anyone can help???

Below is my code, I have two conditions in it. In the second condition I want to search with taxonomy index because I have added a filter contains taxonomy parent term.

/**
 * Implements hook_search_execute
 * Override core node_search_execute here with custom implementation
 * Basically a clone of node_search_execute, but with limit variable available
 * See mymodule_module_implements_alter
 */
   function mymodule_search_execute($keys = NULL, $conditions = NULL) {
 // Add new limit conf variable
   $limit = variable_get('search_result_limit', 10);
 // Build matching conditions
  $prnt = (isset($_REQUEST['prnt'])) ? $_REQUEST['prnt'] : 'none';
  $site = (isset($_REQUEST['chld'])) ? $_REQUEST['chld'] : 'none'; 

  $query = db_select('search_index', 'i', array('target' => 'slave'))->extend('SearchQuery')->extend('PagerDefault');
    if (($prnt != 'none' && $site!= 'none') || ($prnt = 'none' && $site!= 'none')) {

        $query->leftjoin('node', 'n', 'n.nid = i.sid');
        $query->leftjoin('field_data_field_category', 'fdfc', ' fdfc.entity_id = i.sid ');
        $query->leftjoin('taxonomy_term_data', 'txd', 'txd.tid = fdfc.field_category_tid');
        $query->condition('txd.name', $site, '='); 
    }

    if ($prnt != 'none' && $site = 'none') {

        $query= db_select('taxonomy_index', 'ti');
        $query->leftjoin('node', 'n', 'n.nid = ti.nid');
        $query->leftjoin('taxonomy_term_data', 'txd', 'txd.tid = ti.tid');
        $query->leftjoin('taxonomy_term_hierarchy', 'tth', 'tth.tid=txd.tid');
        $query->condition('tth.parent', '$prnt', '='); 

    }


   $query->join('node', 'n', 'n.nid = i.sid');
   $query
         ->condition('n.status', 1)
         ->addTag('node_access')
         ->searchExpression($keys, 'node');

   // Insert special keywords.
   $query->setOption('type', 'n.type');
   $query->setOption('language', 'n.language');
   if ($query->setOption('term', 'ti.tid')) {
   $query->join('taxonomy_index', 'ti', 'n.nid = ti.nid');
 }
  // Only continue if the first pass query matches.
 if (!$query->executeFirstPass()) {
  return array();
  }

 // Add the ranking expressions.
  _node_rankings($query);

// Load results, use limit variable
  $find = $query
   ->limit($limit)
   ->execute();
 $results = array();
 foreach ($find as $item) {
  // Render the node.
  $node = node_load($item->sid);
  $build = node_view($node, 'search_result');
  unset($build['#theme']);
  $node->rendered = drupal_render($build);

  // Fetch comments for snippet.
  $node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node);

  $extra = module_invoke_all('node_search_result', $node);

   $uri = entity_uri('node', $node);
   $results[] = array(
  'link' => url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE))), 
  'type' => check_plain(node_type_get_name($node)), 
  'title' => $node->title, 
  'user' => theme('username', array('account' => $node)), 
  'date' => $node->changed, 
  'node' => $node, 
  'extra' => $extra, 
  'score' => $item->calculated_score, 
  'snippet' => search_excerpt($keys, $node->rendered), 
  'language' => entity_language('node', $node),
 );
}
  return $results;
}
0

1 Answer 1

0

I don't question that the suggested answer (from NishantP) might answer the question. But the "Goto ... & open taxonomy.module ..." looks like hacking this module. If you just do that, then be prepared for the issue potentially coming back in the next module upgrade (because such upgrade might wipe out your edit).

As an alternative, how about filing an issue for this module (if such issue doesn't exist already), and attach a patch to it corresponding to the suggested edit (hack). It might (and probably will) get accepted to be committed to the module in the next reease of it). From then on no more issue with future upgrades of that module. And if it doesn't get accepted, you can still use that same patch to re-apply in further module upgrades (assuming you don't have to re-roll them then).

Edit: looks like NishantP's answer is no longer there (deleted?). Not sure (yet) if that implies that I should now also delete "my" answer. Since I'm sure there was something in it like that "Goto ... & open taxonomy.module ...", I'll leave my answer here for now, just in case anybody else ever has similar hacking-suggestions ...

2
  • It's very unlikely that this is a bug in the taxonomy module. The problem is almost certainly being caused by a different module that's making use of taxonomy
    – Clive
    May 14, 2015 at 13:03
  • Happy to see that "my" answer was not downvoted (yet ...). It even already received a comment to somehow support my answer (though not worth an upvote so far, oh well). About Clive's comment: could it be the custom module that is causing it? Maybe you can/want to provide more details (via another answer) to explain what you mean and what makes you think so? May 14, 2015 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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