You are here

function file_entity_menu in D7 Media 7

Implements hook_menu().

File

file_entity/file_entity.module, line 33
Extends Drupal file entities to be fieldable and viewable.

Code

function file_entity_menu() {
  $items['admin/config/media/file-types'] = array(
    'title' => 'File types',
    'description' => 'Manage files used on your site.',
    'page callback' => 'file_entity_list_types_page',
    'access arguments' => array(
      'administer site configuration',
    ),
    'file' => 'file_entity.admin.inc',
  );
  $items['admin/config/media/file-types/manage/%'] = array(
    'title' => 'Manage file types',
    'description' => 'Manage files used on your site.',
  );

  // Attach a "Manage file display" tab to each file type in the same way that
  // Field UI attaches "Manage fields" and "Manage display" tabs. Note that
  // Field UI does not have to be enabled; we're just using the same IA pattern
  // here for attaching the "Manage file display" page.
  $entity_info = entity_get_info('file');
  foreach ($entity_info['bundles'] as $file_type => $bundle_info) {
    if (isset($bundle_info['admin'])) {

      // Get the base path and access.
      $path = $bundle_info['admin']['path'];
      $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',
        ),
      );

      // The file type must be passed to the page callbacks. It might be
      // configured as a wildcard (multiple file types sharing the same menu
      // router path).
      $file_type_argument = isset($bundle_info['admin']['bundle argument']) ? $bundle_info['admin']['bundle argument'] : $file_type;

      // Add the 'Manage file display' tab.
      $items["{$path}/file-display"] = array(
        'title' => 'Manage file display',
        'page callback' => 'drupal_get_form',
        'page arguments' => array(
          'file_entity_file_display_form',
          $file_type_argument,
          'default',
        ),
        'type' => MENU_LOCAL_TASK,
        'weight' => 3,
        'file' => 'file_entity.admin.inc',
      ) + $access;

      // Add a secondary tab for each view mode.
      $weight = 0;
      $view_modes = array(
        'default' => array(
          'label' => t('Default'),
        ),
      ) + $entity_info['view modes'];
      foreach ($view_modes as $view_mode => $view_mode_info) {
        $items["{$path}/file-display/{$view_mode}"] = array(
          'title' => $view_mode_info['label'],
          'page arguments' => array(
            'file_entity_file_display_form',
            $file_type_argument,
            $view_mode,
          ),
          'type' => $view_mode == 'default' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
          'weight' => $view_mode == 'default' ? -10 : $weight++,
          'file' => 'file_entity.admin.inc',
          // View modes for which the 'custom settings' flag isn't TRUE are
          // disabled via this access callback. This needs to extend, rather
          // than override normal $access rules.
          'access callback' => '_file_entity_view_mode_menu_access',
          'access arguments' => array_merge(array(
            $file_type_argument,
            $view_mode,
            $access['access callback'],
          ), $access['access arguments']),
        );
      }
    }
  }
  return $items;
}