You are here

function field_validation_menu in Field Validation 7

Implements hook_menu().

File

./field_validation.module, line 14

Code

function field_validation_menu() {
  $items = array();
  foreach (entity_get_info() as $entity_type => $entity_info) {
    if ($entity_info['fieldable']) {
      foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
        if (isset($bundle_info['admin'])) {

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

          // Different bundles can appear on the same path (e.g. %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.
          if (isset($bundle_info['admin']['bundle argument'])) {
            $bundle_arg = $bundle_info['admin']['bundle argument'];
            $bundle_pos = (string) $bundle_arg;
          }
          else {
            $bundle_arg = $bundle_name;
            $bundle_pos = '0';
          }

          // This is the position of the %field_ui_menu placeholder in the
          // items below.
          $field_position = count(explode('/', $path)) + 1;

          // Extract access information, providing defaults.
          $access = array_intersect_key($bundle_info['admin'], drupal_map_assoc(array(
            'access callback',
            'access arguments',
          )));
          $access += array(
            'access callback' => 'user_access',
            'access arguments' => array(
              'administer site configuration',
            ),
          );
          $items["{$path}/fields/%field_ui_menu/validation"] = array(
            'load arguments' => array(
              $entity_type,
              $bundle_arg,
              $bundle_pos,
              '%map',
            ),
            'title' => 'Validation',
            'page callback' => 'field_validation_callback_dispatch',
            'page arguments' => array(
              $field_position,
            ),
            'type' => MENU_LOCAL_TASK,
            'file' => 'field_validation.admin.inc',
          ) + $access;
          $items[$path . '/fields/%field_ui_menu/validation/add'] = array(
            'load arguments' => array(
              $entity_type,
              $bundle_arg,
              $bundle_pos,
              '%map',
            ),
            'title' => 'Add validation',
            'page callback' => 'drupal_get_form',
            'page arguments' => array(
              'field_validation_manage_rule',
              $field_position,
              'add',
            ),
            'type' => MENU_CALLBACK,
            'file' => 'field_validation.admin.inc',
          ) + $access;
          $items["{$path}/fields/%field_ui_menu/validation/edit"] = array(
            'load arguments' => array(
              $entity_type,
              $bundle_arg,
              $bundle_pos,
              '%map',
            ),
            'title' => 'Edit rule',
            'page callback' => 'drupal_get_form',
            'page arguments' => array(
              'field_validation_manage_rule',
              $field_position,
              'edit',
            ),
            'type' => MENU_CALLBACK,
            'file' => 'field_validation.admin.inc',
          ) + $access;
          $items["{$path}/fields/%field_ui_menu/validation/overwrite"] = array(
            'load arguments' => array(
              $entity_type,
              $bundle_arg,
              $bundle_pos,
              '%map',
            ),
            'title' => 'Overwrite rule',
            'page callback' => 'drupal_get_form',
            'page arguments' => array(
              'field_validation_manage_rule',
              $field_position,
              'overwrite',
            ),
            'type' => MENU_CALLBACK,
            'file' => 'field_validation.admin.inc',
          ) + $access;
          $items["{$path}/fields/%field_ui_menu/validation/delete"] = array(
            'load arguments' => array(
              $entity_type,
              $bundle_arg,
              $bundle_pos,
              '%map',
            ),
            'title' => 'Delete rule',
            'page callback' => 'drupal_get_form',
            'page arguments' => array(
              'field_validation_delete_rule',
            ),
            'type' => MENU_CALLBACK,
            'file' => 'field_validation.admin.inc',
          ) + $access;
        }
      }
    }
  }
  return $items;
}