You are here

function eck__entity__menu in Entity Construction Kit (ECK) 7.3

Same name and namespace in other branches
  1. 7 eck.entity.inc \eck__entity__menu()
  2. 7.2 eck.entity.inc \eck__entity__menu()

Entity related menu items.

1 call to eck__entity__menu()
eck__bundle__menu in ./eck.bundle.inc
This function creates the menu items relevant to bundle administration.

File

./eck.entity.inc, line 10
All the menus, pages, and functionality related to administering entities.

Code

function eck__entity__menu($entity_type, $bundle) {
  $path = eck__entity_type__path();
  $menu = array();

  // DELETE Bundle.
  $menu["{$path}/{$entity_type->name}/{$bundle->name}/delete"] = array(
    'title' => "Delete",
    'page callback' => "drupal_get_form",
    'page arguments' => array(
      'eck__bundle__delete_form',
      3,
      4,
    ),
    'access callback' => 'eck_access',
    'access arguments' => array(
      'delete',
      'bundle',
      $entity_type,
    ),
    'file' => 'eck.bundle.inc',
    'type' => MENU_LOCAL_TASK,
  );

  // EDIT Bundle.
  $menu["{$path}/{$entity_type->name}/{$bundle->name}/edit"] = array(
    'title' => 'Edit',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'eck__bundle__edit_form',
      $entity_type->name,
      $bundle->name,
    ),
    'access callback' => 'eck_access',
    'access arguments' => array(
      'update',
      'bundle',
      $bundle,
    ),
    'file' => 'eck.bundle.inc',
    'type' => MENU_LOCAL_TASK,
  );

  // Managing a bundle's properties as extra fields.
  $menu["{$path}/{$entity_type->name}/{$bundle->name}/properties/%"] = array(
    'title arguments' => array(
      6,
    ),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'eck__manage_extra_field_form',
      $entity_type->name,
      $bundle->name,
      6,
    ),
    'access callback' => 'eck_access',
    'access arguments' => array(
      'update',
      'bundle',
      $bundle,
    ),
    'file' => 'eck.bundle.inc',
  );
  $menu["{$path}/{$entity_type->name}/{$bundle->name}/properties/%/edit"] = array(
    'title' => 'Edit',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => 0,
  );
  $menu["{$path}/{$entity_type->name}/{$bundle->name}/properties/%/widget-type"] = array(
    'title' => 'Widget Type',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'eck__extra_field_widget_form',
      $entity_type->name,
      $bundle->name,
      6,
    ),
    'access callback' => 'eck_access',
    'access arguments' => array(
      'update',
      'bundle',
      $bundle,
    ),
    'file' => 'eck.bundle.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => 5,
  );
  $menu["{$path}/{$entity_type->name}/{$bundle->name}/properties/%/remove"] = array(
    'title' => 'Remove',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'eck__remove_extra_field_form',
      $entity_type->name,
      $bundle->name,
      6,
    ),
    'access callback' => 'eck_access',
    'access arguments' => array(
      'update',
      'bundle',
      $bundle,
    ),
    'file' => 'eck.bundle.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => 10,
  );
  $admin_info = get_bundle_admin_info($entity_type->name, $bundle->name);

  // OVERVIEW Entity.
  $menu[$admin_info['path']] = array(
    'title' => "{$bundle->label}",
    'description' => "View all entites of type {$entity_type->label} with bundle {$bundle->label}",
    'page callback' => "eck__entity__list",
    'page arguments' => array(
      $entity_type->name,
      $bundle->name,
    ),
    'access callback' => 'eck_access',
    'access arguments' => array(
      'list',
      'entity',
      $bundle,
    ),
    'weight' => 0,
    'file' => 'eck.entity.inc',
  );
  $menu[$admin_info['path'] . "/list"] = array(
    'title' => "Entity List",
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => 100,
  );
  $crud_info = get_bundle_crud_info($entity_type->name, $bundle->name);
  foreach ($crud_info as $action => $info) {
    switch ($action) {
      case 'add':
        $perm_op = 'create';
        break;
      case 'edit':
        $perm_op = 'update';
        break;
      default:
        $perm_op = $action;
        break;
    }
    $perm_args = array(
      $perm_op,
      'entity',
    );
    $action_label = ucfirst($action);
    $args = array();
    if (array_key_exists('entity_id', $info)) {
      $args[] = $info['entity_id'];
      $perm_args[] = $info['entity_id'];
    }
    else {
      $perm_args[] = $bundle;
    }
    $args = array_merge(array(
      $entity_type->name,
      $bundle->name,
    ), $args);
    $menu[$info['path']] = array(
      'title' => "{$action_label} {$bundle->label}",
      'description' => "{$action_label} an entity of type {$entity_type->label} with bundle {$bundle->label}",
      'page callback' => "eck__entity__{$action}",
      'page arguments' => $args,
      'load arguments' => array(
        $entity_type->name,
      ),
      'access callback' => 'eck_access',
      'access arguments' => $perm_args,
      'file' => 'eck.entity.inc',
    );
    if ($action == 'view') {
      $menu[$info['path'] . "/view"] = array(
        'title' => "View",
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'weight' => 0,
      );
    }
  }
  return $menu;
}