You are here

function entity_rules_menu in Entity Rules 7

Implements hook_menu().

File

./entity_rules.module, line 47
Module file for the Entity Rules.

Code

function entity_rules_menu() {
  $items = array();
  $items['admin/config/workflow/entity_rules/settings'] = array(
    'title' => 'Settings',
    'description' => '',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'entity_rules_admin_form',
    ),
    'access arguments' => array(
      'administer rules',
    ),
    'file' => 'entity_rules.admin.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => 1000,
  );
  $rule_types = _entity_rules_get_rule_types();
  $first_rule_type = TRUE;
  foreach ($rule_types as $op => $rule_type) {

    // Add the menu items for the various Rules forms.
    $controller = new RulesUIController();
    $rule_path = 'admin/config/workflow/entity_rules' . "/{$op}";
    $items += $controller
      ->config_menu($rule_path);
    $items[$rule_path] = array(
      'title' => $rule_type['label'] . ' ' . t('Rules'),
      'description' => empty($rule_type['description']) ? '' : $rule_type['description'],
      'page callback' => 'entity_rules_list',
      'page arguments' => array(
        $op,
      ),
      'access arguments' => array(
        'administer rules',
      ),
      'file path' => drupal_get_path('module', 'entity_rules'),
      'file' => 'entity_rules.admin.inc',
      'type' => MENU_LOCAL_TASK,
    );
    if ($first_rule_type) {
      $items['admin/config/workflow/entity_rules'] = $items[$rule_path];
      $items[$rule_path]['type'] = MENU_DEFAULT_LOCAL_TASK;
      $items['admin/config/workflow/entity_rules']['type'] = MENU_NORMAL_ITEM;
      $items['admin/config/workflow/entity_rules']['title'] = 'Entity Rules';
      $items['admin/config/workflow/entity_rules']['description'] = 'Manage Rule components available for Entity Rules';
      $first_rule_type = FALSE;
    }
    $items["{$rule_path}/add"] = array(
      'title' => 'Add a @op rule',
      'title arguments' => array(
        '@op' => $rule_type['label'],
      ),
      'description' => "Adds an additional {$rule_type['label']} rule configuration.",
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        "entity_rules_add_rule_form",
        $rule_path,
      ),
      'access arguments' => array(
        'administer rules',
      ),
      'file path' => drupal_get_path('module', 'rules_admin'),
      'file' => 'rules_admin.inc',
      'type' => MENU_LOCAL_ACTION,
    );
    $items["{$rule_path}/manage/%rules_config"]['page arguments'][0] = 'entity_rules_form_edit_rules_config';
    $items["{$rule_path}/manage/%rules_config/clone"]['page arguments'][0] = 'entity_rules_form_clone_rules_config';
  }

  // Create tabs for all possible bundles.
  $permissions = variable_get('entity_rules_permissions', ENTITY_RULES_DEFAULT_PERMISSIONS);
  $enabled_types = variable_get('entity_rules_types', explode(',', ENTITY_RULES_DEFAULT_TYPES));
  $entity_infos = entity_get_info();
  $entity_infos = array_intersect_key($entity_infos, array_flip($enabled_types));
  $items["admin/config/workflow/entity-rules-triggers"] = array(
    'title' => 'Entity Rules - Triggers',
    'type' => MENU_NORMAL_ITEM,
    'file' => 'entity_rules.admin.inc',
    'page callback' => 'entity_rules_entity_type_list',
    'access callback' => 'entity_rules_overview_access',
    'weight' => 10,
  );
  foreach ($entity_infos as $entity_type => $entity_info) {
    if ($entity_info['fieldable']) {
      foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
        if (isset($bundle_info['admin'])) {

          // Each entity_type may support different rule types
          $rule_types = _entity_rules_get_rule_types($entity_type);

          // Extract path information from the bundle.
          $path = $bundle_info['admin']['path'];

          // Determine whether this path caters for several bundles (usually all)
          // of one entity type, or just one.
          if (isset($bundle_info['admin']['bundle argument'])) {

            /*
             * Different bundles can appear on the same path (for example %node_type and
             * %comment_node_type). To allow field_ui_menu_load() to extract the
             * actual bundle object from the translated menu router path
             * arguments, we need to identify the argument position of the bundle
             * name string ('bundle argument') and pass that position to the menu
             * loader. The position needs to be casted into a string; otherwise it
             * would be replaced with the bundle name string.
             */
            $bundle_arg = $bundle_info['admin']['bundle argument'];
          }
          else {

            // Otherwise, this path is for a single bundle. Things are much simpler!
            $bundle_arg = $bundle_name;
          }

          // This is the position of the %field_ui_menu placeholder in the
          // items below.
          $rule_type_position = count(explode('/', $path)) + 1;
          $access = _entity_rules_menu_access_settings($entity_type, $bundle_name, $bundle_info);
          $weight = 10;
          foreach ($rule_types as $op => $rule_type) {
            if ($weight == 10) {
              $menu_type = MENU_DEFAULT_LOCAL_TASK;
              $items["{$path}/entity-rules"] = array(
                'title' => 'Rules',
                'type' => MENU_LOCAL_TASK,
                'file' => 'entity_rules.admin.inc',
                'page callback' => 'entity_rules_type_op_rules',
                'page arguments' => array(
                  $op,
                  $entity_type,
                  $bundle_arg,
                ),
                'weight' => 10,
              ) + $access;
              if ($entity_type == 'comment') {
                $items["{$path}/entity-rules"]['title'] = 'Comment Rules';
              }
            }
            else {
              $menu_type = MENU_LOCAL_TASK;
            }
            $items["{$path}/entity-rules/{$op}"] = array(
              'title' => '@op Rules',
              'title arguments' => array(
                '@op' => $rule_type['label'],
              ),
              'page callback' => 'entity_rules_type_op_rules',
              'page arguments' => array(
                $op,
                $entity_type,
                $bundle_arg,
              ),
              'type' => $menu_type,
              'file' => 'entity_rules.admin.inc',
              'weight' => $weight++,
            ) + $access;

            // Have to make sure we don't go over MENU_MAX_PARTS(9)
            $rule_position = (int) $rule_type_position + 1;
            $items["{$path}/entity-rules-remove/{$op}/%"] = array(
              'title' => '@op Rules',
              'title arguments' => array(
                '@op' => $rule_type['label'],
              ),
              'page callback' => 'entity_rules_type_op_rules_remove',
              'page arguments' => array(
                $op,
                $entity_type,
                $bundle_arg,
                $rule_position,
              ),
              'type' => MENU_CALLBACK,
              'file' => 'entity_rules.admin.inc',
              'weight' => $weight++,
            ) + $access;
            if ($permissions != 'none') {

              // If permission are set then make separate menu
              $other_menu_item = $items["{$path}/entity-rules/{$op}"];
              if ($op == 'create') {
                $other_menu_item['type'] = MENU_DEFAULT_LOCAL_TASK;
              }
              else {
                $other_menu_item['type'] = MENU_LOCAL_TASK;
              }
              $other_menu_item['page arguments'] = array(
                $op,
                $entity_type,
                $bundle_name,
              );
              $items["admin/config/workflow/entity-rules-triggers/{$entity_type}-{$bundle_name}/{$op}"] = $other_menu_item;
              $other_menu_item = $items["{$path}/entity-rules-remove/{$op}/%"];
              $other_menu_item['page arguments'] = array(
                $op,
                $entity_type,
                $bundle_name,
                6,
              );
              $items["admin/config/workflow/entity-rules-remove-triggers/{$entity_type}-{$bundle_name}/{$op}"] = $other_menu_item;
            }
          }
          if ($permissions != 'none') {

            // If permission are set then make separate menu
            $other_menu_item = $items["{$path}/entity-rules"];
            $other_menu_item['type'] = MENU_NORMAL_ITEM;
            $other_menu_item['title'] = $entity_info['label'] . ' - ' . $bundle_info['label'];
            $other_menu_item['page arguments'] = array(
              'create',
              $entity_type,
              $bundle_name,
            );
            $items["admin/config/workflow/entity-rules-triggers/{$entity_type}-{$bundle_name}"] = $other_menu_item;
          }
        }
      }
    }
  }
  return $items;
}