Creating a My Content Tab for each users My Account

Last modified: December 26, 2008 - 15:49

I wanted to make a quick tab where the user could go to My Account and see My Content.
I think there is a module to do this but I could not find it so I made a View (you will of course need this module for this to work)
Now when the user goes to My Account they see an extra tab called My Content which shows nodes authored by them. And the title field as well as the Edit field.
Here is the View Code you can import

$view = new view;
$view->name = 'my_content';
$view->description = 'users content';
$view->tag = 'Users';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'title' => array(
    'label' => 'Title',
    'link_to_node' => 0,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'edit_node' => array(
    'id' => 'edit_node',
    'table' => 'node',
    'field' => 'edit_node',
  ),
));
$handler->override_option('arguments', array(
  'uid' => array(
    'default_action' => 'empty',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'uid',
    'table' => 'users',
    'field' => 'uid',
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'blog' => 0,
      'poll' => 0,
      'forum' => 0,
      'panel' => 0,
      'book' => 0,
      'ecobytes' => 0,
      'event' => 0,
      'faq' => 0,
      'incentive' => 0,
      'job_notice' => 0,
      'office_docs' => 0,
      'page' => 0,
      'press_release' => 0,
      'program' => 0,
      'resource' => 0,
      'solutions' => 0,
      'staff_help' => 0,
      'story' => 0,
      'support_request' => 0,
      'tips' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '3' => 0,
      '1' => 0,
      '9' => 0,
      '2' => 0,
      '5' => 0,
      '4' => 0,
      '8' => 0,
      '7' => 0,
      '6' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_php' => '',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('title', 'My Content');
$handler->override_option('empty', 'Oops you have not content...');
$handler->override_option('empty_format', '2');
$handler->override_option('items_per_page', 100);
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
  'grouping' => '',
  'override' => 1,
  'sticky' => 0,
  'order' => 'asc',
  'columns' => array(
    'title' => 'title',
    'edit_node' => 'edit_node',
  ),
  'info' => array(
    'title' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'edit_node' => array(
      'separator' => '',
    ),
  ),
  'default' => '-1',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'user/%/mycontent');
$handler->override_option('menu', array(
  'type' => 'tab',
  'title' => 'My Content',
  'weight' => '6',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'weight' => '0',
));

Strange, I can't get it to

hobgobbler - February 14, 2009 - 23:11

Strange, I can't get it to work if it's embedded in a block or put into the template manually. I just says "Oops you have not content".

Page works though.

some how it is not getting the arg

yurtboy - February 17, 2009 - 14:30

this can be hard to pass args w/ blocks but not impossible.
I think the views empty text says 'Oops you have not content'
Ie if not content found show empy text.
So I think it is that.
Now how to pass the user arg to the block is the next question?
global $user;
and get the $user->uid
??

Brilliant! Thank you.

bwv - March 18, 2009 - 12:43

Brilliant! Thank you.

----------------------------------------------------------------------
http://classicvinyl.biz
http://music.classicvinyl.biz
http://association.drupal.org/user/1207

Just what I wanted ...Thanks

lammergier - September 4, 2009 - 06:35

Just what I wanted ...Thanks

Check if this is the current user

gagarine - September 20, 2009 - 14:31

To check if the user are realy the current user, I use this php code in the "Validator options" of the argument:

<?php
global $user;
if(
$user->uid == $argument){
return
TRUE;
}else{
return
FALSE;
}
?>

Awesome!

darioshanghai - October 31, 2009 - 11:25

Thanks!

 
 

Drupal is a registered trademark of Dries Buytaert.