views:

24

answers:

3

I dont know if im asking the impossible, but i want to have a tab in my user edit area that houses all blog related items (ie blog theme, blog info, user blogroll) as opposed to them being inside the user/%/edit and user/%/edit profile.

Im putting together a multi-user site and this is crucial for user-friendliness.

Thanks for any ideas!

A: 

Nothing is impossible with Drupal, but doing this would be a challenge.

With hook_form_alter you can alter any form you want. The code for this would have to go to a custom module. Then you would have to recreate the form, with a page callback, and handle the validation and submission. You can probably recreate the code from the modules that create the forms in the first place.

Alternative, you can just leave the settings at user/%/edit and other places, and just create a special form with all blog relevant info. That way the users choose where to edit their info. It will probably be a better choice, since the "blog settings" that's location at user/%/edit, will be more tied to the user, than to the blog. So when a user wants to edit some of his personal details, that's when he would want to edit those blog settings as well.

Your specific might be different, but the default setup is usually a very good default.

googletorp
Thank you so much for your response.I was able to write the correct function that imported the visual form into the new tab and take it out of the user tab...but the form was only visual and not functional. It would not save the information entered. I suppose this has to do withthe validation and submission. Any ideas?
MAds
@MAds: Update your question with the code for the form you created.
googletorp
A: 

Yes, of course, sorry...

for example using the following, I get the form, but no function

function blog_theme_menu() { $items = array(); $items['user/%user/blog_settings'] = array( 'title' => 'Blog Settings', 'page callback' => 'drupal_get_form', 'page arguments' => array('blog_theme_select'), 'access arguments' => array('access content'), 'type' => MENU_LOCAL_TASK, );

return $items; }

function blog_theme_select() { global $user; $form = array(); $form['themes'] = array( '#type' => 'fieldset', '#title' => t('Your blog theme configuration'), '#description' => t('Selecting a different theme will change the look of your own blog for both yourself and other visitors.'), '#collapsible' => TRUE, '#theme' => 'blog_theme_select_form' ); if (user_access('select different blog theme')) { foreach (list_themes() as $theme) { if ($theme->status) { $enabled[] = $theme; } } } if (count($enabled) > 1) { ksort($enabled); } foreach ($enabled as $info) {
// For the default theme, revert to an empty string so the user's theme updates when the site theme is changed. $info->key = $info->name == variable_get('theme_default', 'garland') ? '' : $info->name;

      $info->screenshot = dirname($info->filename) .'/screenshot.png';
      $screenshot = file_exists($info->screenshot) ? theme('image', $info->screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), FALSE) : t('no screenshot');

      $form['themes'][$info->key]['screenshot'] = array('#value' => $screenshot);
      $form['themes'][$info->key]['description'] = array(
        '#type' => 'item', 
        '#title' => $info->name,  
      );
      $options[$info->key] = '';
    }

    $form['themes']['blog_theme'] = array(
      '#type' => 'radios', 
      '#options' => $options, 
      '#default_value' => !empty($edit['blog_theme']) ? $edit['blog_theme'] : ''
    );

$form['submit'] = array('#type' => 'submit', '#value' => t('Save'), ); $form['#weight'] = 2.5; $form_to_return['blog_theme_select'] = $form; return $form_to_return; }

I also have another alternative which i will post following this

MAds
A: 

the alternative was to create a new module based onthe chgpwd module and copy the user/%/edit form into a new tab and then hide the feilds you dont want.

Again, I was able to do this and have the forms function, but i wasnt able to hide the unwanted forms..

/** * Implementation of hook_menu(). */

function blog_settings_menu() {

$items['user/%user_category/edit/blog_settings'] = array(

'title' => 'Blog Settings',
'page callback' => 'theme_blog_settings_page',

'page arguments' => array(1),

'access callback' => 'user_edit_access',

'access arguments' => array(1),

'file' => 'user.pages.inc',

'file path' => drupal_get_path('module' , 'user') . '/',

'load arguments' => array('%map', '%index'),

'type' => MENU_LOCAL_TASK,

);

return $items;

}

/** * Implements hook_form_FORM_ID_alter(). */

function blogtheme_form_user_profile_form_alter(&$form, $form_state) {

// category will be 'account' //$categoy = $form['_category']['#value'];

if (is_null(arg(3)) || arg(3) == 'account'){ // to hide from default user edit $form['account']['blog_theme']['#access'] = FALSE; }else if (arg(3) == 'blog_settings'){ $form['account']['#title'] = t('Blog Settings');

// hide other than password
foreach($form as $mkey=>$mval){
  if ($mkey == 'account'){
    foreach($form['account'] as $akey=>$aval){
      // hide all but pass

      if ($akey != 'blog_theme' && is_array($form['account'][$akey])){
        $form['account'][$akey]['#access'] = FALSE;
      }
    }
  }else{
    $ignore = array(
      '_category', '_account', 'submit', '#attributes',
      '#parameters', '#build_id', '#type', 'form_build_id',
      'form_token', 'form_id', '#parents', '#validate',
      '#submit',
      'blog_theme_current', // for password_change module
    );
    // just hide it
    if (!array_search($mkey, $ignore)  && is_array($form[$mkey])){
      $form[$mkey]['#access'] = FALSE;
    }
  }
}


$form['account']['blog_theme']['#required'] = TRUE;
$form['submit']['#value'] = t('Blog Settings');

}

}

function theme_blog_settings_page($account, $category = 'account'){

drupal_set_title(t('Blog Settings'));

return drupal_get_form('user_profile_form', $account, $category);

}

/** * Implementation of hook_user(). */

function blog_settings_user($type, &$edit, &$account, $category = NULL) {

if ($type == 'categories') { return array(array('name' => 'blog_settings', 'title' => t('Blog Settings'), 'weight' => 1)); } }

MAds