diff --git a/page_manager/plugins/tasks/user_edit.inc b/page_manager/plugins/tasks/user_edit.inc index 3d98426..6d0135d 100644 --- a/page_manager/plugins/tasks/user_edit.inc +++ b/page_manager/plugins/tasks/user_edit.inc @@ -52,6 +52,17 @@ function page_manager_user_edit_menu_alter(&$items, $task) { $items['user/%user/edit']['page arguments'] = array(1); $items['user/%user/edit']['file path'] = $task['path']; $items['user/%user/edit']['file'] = $task['file']; + if (($categories = _user_categories()) && (count($categories) > 1)) { + foreach ($categories as $key => $category) { + // 'account' is already handled by the MENU_DEFAULT_LOCAL_TASK. + if ($category['name'] != 'account') { + $items['user/%user_category/edit/' . $category['name']]['page callback'] = 'page_manager_user_edit_page'; + $items['user/%user_category/edit/' . $category['name']]['page arguments'] = array(1, 3); + $items['user/%user_category/edit/' . $category['name']]['file path'] = $task['path']; + $items['user/%user_category/edit/' . $category['name']]['file'] = $task['file']; + } + } + } } else { // automatically disable this task if it cannot be enabled. @@ -69,7 +80,9 @@ function page_manager_user_edit_menu_alter(&$items, $task) { * to run with it. If no one does, it passes through to Drupal core's * user edit, which is drupal_get_form('user_profile_form',$account). */ -function page_manager_user_edit_page($account) { +function page_manager_user_edit_page($account, $category = 'account') { + // Store the category on the user for later usage. + $account->user_category = $category; // Load my task plugin: $task = page_manager_get_task('user_edit'); diff --git a/plugins/contexts/user_edit_form.inc b/plugins/contexts/user_edit_form.inc index 89ee2b4..f33fe3f 100644 --- a/plugins/contexts/user_edit_form.inc +++ b/plugins/contexts/user_edit_form.inc @@ -30,16 +30,20 @@ * are not always created from the UI. */ function ctools_context_create_user_edit_form($empty, $user = NULL, $conf = FALSE) { - static $created; + // Determine the user category. + $category = !empty($conf['category']) ? $conf['category'] : 'account'; + unset($conf['category']); + + // Return previously created contexts, per category. + static $created = array(); + if ($empty || !empty($created[$category])) { + return $created[$category]; + } + $context = new ctools_context(array('form', 'user_edit', 'user_form', 'user_edit_form', 'user', 'entity:user')); $context->plugin = 'user_edit_form'; - if ($empty || (isset($created) && $created)) { - return $context; - } - $created = TRUE; - - if ($conf) { + if (!empty($conf)) { // In this case, $user is actually our $conf array. $uid = is_array($user) && isset($user['uid']) ? $user['uid'] : (is_object($user) ? $user->uid : 0); @@ -58,7 +62,7 @@ function ctools_context_create_user_edit_form($empty, $user = NULL, $conf = FALS if (!empty($user)) { $form_id = 'user_profile_form'; - $form_state = array('want form' => TRUE, 'build_info' => array('args' => array($user))); + $form_state = array('want form' => TRUE, 'build_info' => array('args' => array($user, $category))); $file = drupal_get_path('module', 'user') . '/user.pages.inc'; require_once DRUPAL_ROOT . '/' . $file; @@ -78,6 +82,8 @@ function ctools_context_create_user_edit_form($empty, $user = NULL, $conf = FALS $context->form_id = $form_id; $context->form_title = isset($user->name) ? $user->name : ''; $context->restrictions['form'] = array('form'); + // Store this context for later. + $created[$category] = $context; return $context; } } diff --git a/plugins/relationships/user_category_edit_form_from_user.inc b/plugins/relationships/user_category_edit_form_from_user.inc new file mode 100644 index 0000000..28dac72 --- /dev/null +++ b/plugins/relationships/user_category_edit_form_from_user.inc @@ -0,0 +1,31 @@ + t('User category edit form from user'), + 'keyword' => 'user_category_form', + 'description' => t('Adds user category edit form from a user context.'), + 'required context' => new ctools_context_required(t('User'), 'user'), + 'context' => 'ctools_user_category_edit_form_from_user_context', +); + +/** + * Return a new context based on an existing context. + */ +function ctools_user_category_edit_form_from_user_context($context, $conf) { + if (empty($context->data)) { + return ctools_context_create_empty('user_edit_form', NULL); + } + + if (isset($context->data->user_category)) { + return ctools_context_create('user_edit_form', $context->data, array('category' => $context->data->user_category)); + } +}