Exemplo n.º 1
0
 /**
  * Returns the set of the custom SugarLogic Dependencies defined in the dependency metadata
  * for a module that are valid for the given action.
  * @static
  * @param string $module Primary module for this action
  * @param string $action name of the action to get dependencies for ("edit", "view", "save", ect)
  * @param string $form name of the form element used on html forms
  * @return array<Dependency>
  */
 public static function getModuleDependenciesForAction($module, $action, $form = "EditView")
 {
     $meta = self::getModuleDependencyMetadata($module);
     $deps = array();
     foreach ($meta as $key => $def) {
         $hooks = empty($def['hooks']) ? array("all") : $def['hooks'];
         if (!is_array($hooks)) {
             $hooks = array($hooks);
         }
         if (in_array('all', $hooks) || in_array($action, $hooks)) {
             self::filterActionDefinitionsForView($def, $action);
             if (empty($def['actions']) && empty($def['notActions'])) {
                 continue;
                 // Skip if no actions left after filtering
             }
             $triggerExp = empty($def['trigger']) ? self::$default_trigger : $def['trigger'];
             $triggerFields = empty($def['triggerFields']) ? Parser::getFieldsFromExpression($triggerExp) : $def['triggerFields'];
             $actions = empty($def['actions']) || !is_array($def['actions']) ? array() : $def['actions'];
             $notActions = empty($def['notActions']) || !is_array($def['notActions']) ? array() : $def['notActions'];
             $dep = new Dependency("{$module}{$form}_{$key}");
             $dep->setTrigger(new Trigger($triggerExp, $triggerFields));
             foreach ($actions as $aDef) {
                 $dep->addAction(ActionFactory::getNewAction($aDef['name'], $aDef['params']));
             }
             foreach ($notActions as $aDef) {
                 $dep->addFalseAction(ActionFactory::getNewAction($aDef['name'], $aDef['params']));
             }
             $dep->setFireOnLoad(!isset($def['onload']) || $def['onload'] !== false);
             $deps[] = $dep;
         }
     }
     return $deps;
 }