2

I have a drupal website, in which I wanted to add a new URL. This menu have two arguements which should be passed from the client side.

function campaign_management_menu() {
  $items = array();
  $items['campaign-management/test/%/%'] = array(
    'title' => 'Campaign Management',
    'description' => 'A section where you can manage your campaigns',
    'page callback' => 'cm_home',
    'page arguments' => array(3, 4),
    'access callback' => TRUE,
  );
  return $items
}

Here, for the fourth argument, there should be only two options {add/edit}. Is there any option in drupal to set these two keywords explicitely. ie,

$items['campaign-management/test/%/{add|edit}'] = array(
  'title' => 'Campaign Management',
  'description' => 'A section where you can manage your campaigns',
  'page callback' => 'cm_home',
  'page arguments' => array(3, 4),
  'access callback' => TRUE,
);
0

There isn't such an option; you just define two route items.

$items['campaign-management/test/%/add'] = array(
  'title' => 'Campaign Management',
  'description' => 'A section where you can manage your campaigns',
  'page callback' => 'cm_home',
  'page arguments' => array(3, 4),
  'access callback' => TRUE,
);

$items['campaign-management/test/%/edit'] = array(
  'title' => 'Campaign Management',
  'description' => 'A section where you can manage your campaigns',
  'page callback' => 'cm_home',
  'page arguments' => array(3, 4),
  'access callback' => TRUE,
);

Alternatively, you define your route as follows.

$items['campaign-management/test/%/%'] = array(
  'title' => 'Campaign Management',
  'description' => 'A section where you can manage your campaigns',
  'page callback' => 'cm_home',
  'page arguments' => array(3, 4),
  'access callback' => TRUE,
);

Your page callback then will do something when the last argument it get is 'add' or 'edit'; eventually, it can return a 404 error when the argument doesn't have one of the desired values.

Keep in mind that in Drupal 7, a user visiting (for example) node/1/sgsdrgdfgdfe45t63635wsg will normally see the node page (node/1, in this case). To keep that behavior, you should define the campaign-management/test/%/add and campaign-management/test/%/edit routes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.