You are here

function auto_entitylabel_menu in Automatic Entity Label 7

Implements hook_menu().

File

./auto_entitylabel.module, line 47
Allows hiding of entity label fields and automatic label creation.

Code

function auto_entitylabel_menu() {
  $items = array();
  $items['admin/structure/auto-label'] = array(
    'title' => 'Automatic label',
    'page callback' => 'auto_entitylabel_settings_default_page',
    'access callback' => 'user_access',
    'file' => 'auto_entitylabel.admin.inc',
    'access arguments' => array(
      'administer site configuration',
    ),
  );

  // This logic is taken from the field_ui module.
  // Create tabs for all possible bundles.
  foreach (entity_get_info() as $entity_type => $entity_info) {
    if (isset($entity_info['entity keys']['label'])) {
      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'];
          }
          else {
            $bundle_arg = $bundle_name;
          }

          // 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}/auto_label"] = array(
            'title' => 'Auto label',
            'page callback' => 'drupal_get_form',
            'page arguments' => array(
              'auto_entitylabel_settings_form',
              $entity_type,
              $bundle_arg,
            ),
            'type' => MENU_LOCAL_TASK,
            'weight' => 2,
            'file' => 'auto_entitylabel.admin.inc',
          ) + $access;

          // Prefix comment entities, because otherwise there would be multiple
          // menu items that just said "Auto label".
          if ($entity_type == 'comment') {
            $items["{$path}/auto_label"]['title'] = '@type Auto label';
            $items["{$path}/auto_label"]['title arguments'] = array(
              '@type' => $entity_info['label'],
            );
            $items["{$path}/auto_label"]['weight'] = 4;
          }
        }
      }
    }
  }
  return $items;
}