You are here

function crumbs_InvokeAction_findForPath::invoke in Crumbs, the Breadcrumbs suite 6.2

This should run once for each plugin object. It should be called by the PluginEngine, during invokeUntilFound().

Overrides crumbs_InvokeActionInterface_find::invoke

File

./crumbs.plugin_engine.inc, line 343

Class

crumbs_InvokeAction_findForPath

Code

function invoke($plugin, $plugin_key, $weight_keeper) {
  $smallest_weight = $weight_keeper
    ->getSmallestWeight();
  if (isset($this->_candidate_weight) && $this->_candidate_weight <= $smallest_weight) {

    // any further candidate would have a higher weight, thus lower priority,
    // than what we already have found. Thus, we can stop searching.
    return TRUE;
  }
  foreach ($this->_methods as $method) {
    if (method_exists($plugin, $method)) {
      $result = $this
        ->_invoke($plugin, $method);
      break;
    }
  }
  if (method_exists($plugin, 'defineMany') || method_exists($plugin, 'define')) {

    // we expect an array result.
    if (is_array($result) && !empty($result)) {
      foreach ($result as $key => $value) {
        $weight = $weight_keeper
          ->findWeight($key);
        $this
          ->_setValue($plugin_key . '.' . $key, $value, $weight);
      }
    }
    else {
      $this->_log[$plugin_key . '.*'] = array(
        NULL,
        NULL,
      );
    }
  }
  else {

    // we expect a simple value as a result
    if (isset($result)) {
      $weight = $weight_keeper
        ->findWeight();
      $this
        ->_setValue($plugin_key, $result, $weight);
    }
    else {
      $this->_log[$plugin_key] = array(
        NULL,
        NULL,
      );
    }
  }
}