Example #1
0
 /**
  * @param string $path
  * @param array $item
  * @return array
  */
 protected function find($path, $item)
 {
     if (FALSE === ($entity = crumbs_Util::itemExtractEntity($item, $this->entityType))) {
         return;
     }
     if ('user' === $this->entityType) {
         return $this->userFind($entity);
     } else {
         return $this->entityFind($entity);
     }
 }
Example #2
0
 /**
  * Set news/(year)/(month)/(day) as the parent for a node.
  * You can use the weights config at Admin > Structure > Crumbs to specify
  * which node types this should apply to.
  *
  * @param string $path
  * @param array $item
  *   The loaded router item for $path.
  *
  * @return string[]|NULL
  *   Candidates for the parent path, or NULL.
  */
 function findParent__node_x($path, $item)
 {
     if (FALSE === ($node = crumbs_Util::itemExtractEntity($item, 'node', 1))) {
         return;
     }
     if (!empty($node->created)) {
         list($year, $month, $day) = explode('-', date('Y-m-d', $node->created));
         $path = "news/{$year}/{$month}/{$day}";
         return array($node->type => $path);
     }
 }
Example #3
0
 /**
  * @param crumbs_PluginInterface $plugin
  * @param string $plugin_key
  */
 function invoke($plugin, $plugin_key)
 {
     $this->pluginKey = $plugin_key;
     $basic_methods = array();
     $route_methods = array();
     $rf_class = new ReflectionClass($plugin);
     foreach ($rf_class->getMethods() as $rf_method) {
         $method = $rf_method->name;
         $pos = strpos($method, '__');
         if (FALSE !== $pos && 0 !== $pos) {
             $method_base = substr($method, 0, $pos);
             if (in_array($method_base, array('findParent', 'findTitle'))) {
                 $method_suffix = substr($method, $pos + 2);
                 $route = crumbs_Util::routeFromMethodSuffix($method_suffix);
                 $route_methods[$method_base][$route] = $method;
             }
         } else {
             if (in_array($method, array('findParent', 'findTitle', 'decorateBreadcrumb'))) {
                 if (!isset($this->pluginRoutes[$plugin_key])) {
                     $basic_methods[$method] = $method;
                 } else {
                     $route = $this->pluginRoutes[$plugin_key];
                     if (!isset($route_methods[$method][$route])) {
                         $route_methods[$method][$route] = $method;
                     }
                 }
             }
         }
     }
     if ($plugin instanceof crumbs_MonoPlugin) {
         $this->collectedInfo['basicMethods'][$plugin_key] = $basic_methods;
         $this->collectedInfo['routeMethods'][$plugin_key] = $route_methods;
         $result = $plugin->describe($this->injectedAPI_mono);
         if (is_string($result)) {
             $this->setTitle($result);
         }
     } elseif ($plugin instanceof crumbs_MultiPlugin) {
         $this->collectedInfo['basicMethods']["{$plugin_key}.*"] = $basic_methods;
         $this->collectedInfo['routeMethods']["{$plugin_key}.*"] = $route_methods;
         $result = $plugin->describe($this->injectedAPI_multi);
         if (is_array($result)) {
             foreach ($result as $key_suffix => $title) {
                 $this->addRule($key_suffix, $title);
             }
         }
     }
 }
Example #4
0
 /**
  * Prepared list of plugins and methods for a given find operation and route.
  * This is the version to be cached.
  *
  * @param crumbs_Container_CachedLazyPluginInfo $container
  * @param string $method
  * @param string $route
  * @return array|bool
  */
 function routePluginMethodsCached($container, $method, $route)
 {
     if (empty($route)) {
         return FALSE;
     }
     $only_basic = TRUE;
     $plugin_routes = $container->pluginRoutes;
     $method_suffix = crumbs_Util::buildMethodSuffix($route);
     if (!empty($method_suffix)) {
         $method_with_suffix = $method . '__' . $method_suffix;
     }
     $result = array();
     foreach ($container->pluginOrder['find'] as $plugin_key => $weight) {
         $plugin = $container->plugins[$plugin_key];
         if (isset($method_with_suffix) && method_exists($plugin, $method_with_suffix)) {
             $result[$plugin_key] = $method_with_suffix;
             $only_basic = FALSE;
         } elseif (method_exists($plugin, $method)) {
             if (!isset($plugin_routes[$plugin_key])) {
                 $result[$plugin_key] = $method;
             } elseif ($route === $plugin_routes[$plugin_key]) {
                 $only_basic = FALSE;
                 $result[$plugin_key] = $method;
             }
         }
     }
     return $only_basic ? FALSE : $result;
 }