You are here

function flagging_form_menu in Flagging Form 7.3

Same name and namespace in other branches
  1. 7 flagging_form.module \flagging_form_menu()

Implements hook_menu().

We provide two sets of CRUD links. The first set is for casual use by end-users:

flag/flagging/%flag/%content_id/edit flag/flagging/%flag/%content_id/create flag/flagging/%flag/%content_id/delete

However, this set doesn't let us edit and delete specific flaggings. Therefore we provide another set, for privileged users only, to operate on specific flaggings:

flag/privileged-flagging/%flagging/edit flag/privileged-flagging/%flagging/delete

(This last set is patterned after 'node/%node/edit', or 'user/%user/edit'.)

Why do we need two sets? Why not follow the 'node/%node/edit' example, which, after all, works for both end-users and admins? Answer: mainly because flagging objects, in contrast to node objects (and users), have a transient nature; having the flagging ID embedded in a link might invalidate the link once a similar ajax link on that page is clicked. Another reason: admin links usually require a different interaction mode (e.g., they don't need ajax; e.g., could use the Overlay module) and having a separate namespace for them can be useful.

File

./flagging_form.module, line 236
Provides forms for editing and deleting a flagging.

Code

function flagging_form_menu() {

  // Links for end-users.
  // Editing a flagging.
  $items['flag/flagging/%flag/%content_id/edit'] = array(
    'page callback' => 'flagging_form_flagging_edit_page',
    'page arguments' => array(
      2,
      3,
    ),
    'title callback' => '_flag_menu_title',
    'title arguments' => array(
      2,
    ),
    'access callback' => '_flagging_form_flagging_access',
    'access arguments' => array(
      'update',
      2,
      3,
    ),
  );

  // Creating a flagging.
  $items['flag/flagging/%flag/%content_id/create'] = array(
    // It's effectively identical to the 'edit' callback.
    'page callback' => 'flagging_form_flagging_edit_page',
    'page arguments' => array(
      2,
      3,
    ),
    'title callback' => '_flag_menu_title',
    'title arguments' => array(
      2,
    ),
    'access callback' => '_flagging_form_flagging_access',
    'access arguments' => array(
      'create',
      2,
      3,
    ),
  );

  // Deleting a flagging.
  $items['flag/flagging/%flag/%content_id/delete'] = array(
    'page callback' => 'flagging_form_flagging_delete_page',
    'page arguments' => array(
      2,
      3,
    ),
    'title callback' => '_flag_menu_title',
    'title arguments' => array(
      2,
    ),
    'access callback' => '_flagging_form_flagging_access',
    'access arguments' => array(
      'delete',
      2,
      3,
    ),
  );

  // Links for privileged users.
  // Editing a flagging.
  $items['flag/privileged-flagging/%flagging/edit'] = array(
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'flagging_form_flagging_form',
      2,
      TRUE,
    ),
    'title callback' => '_flagging_form_flagging_menu_title',
    'title arguments' => array(
      2,
    ),
    // For now we simply check for the 'administer flags' permission, but it
    // could make sense to introduce a separate permission for this.
    // (Incidentally, this is why we avoid the word "admin" in discussing this
    // and instead use the more elastic one "privileged".)
    'access arguments' => array(
      'administer flags',
    ),
  );

  // Deleting a flagging.
  $items['flag/privileged-flagging/%flagging/delete'] = array(
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'flagging_form_flagging_delete_form',
      2,
      TRUE,
    ),
    'title callback' => '_flagging_form_flagging_menu_title',
    'title arguments' => array(
      2,
    ),
    'access arguments' => array(
      'administer flags',
    ),
  );
  return $items;
}