Last updated December 26, 2008. Created on December 26, 2008.
Edited by yurtboy. Log in to edit this page.

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',
));

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

pbm160’s picture

Thanks for the code! Now a silly question from someone who doesn't know any coding. Where do I copy this code to? Can someone please help!

sumaiyajaved’s picture

Thanks .. the view works perfectly!

Regards,

Sumaiya Javed
Web Developer
www.sumaiyajaved.com
www.phpjavascript.com

sheckay’s picture

when I go to mydomain.com/admin/build/views/import I just get a "404 Not found". Can I enter it anywhere via my website's "file manager" on my hosts' server?

iRex’s picture

substitute your domain name for "mydomain.com" and you'll be good to go

... this Rock...

LeneB’s picture

I am not sure how to import the code above. When I go to http://mysite.com/admin/build/views/import, I get the admin "dashboard" with links to edit the Dashboard, Content, Structure, Appearance etc. Where/how exactly am I supposed to import the code?

yelvington’s picture

Views can't import anything unless you activate (and have permissions to use) the PHP filter.

ryanfc78’s picture

Thank you this is exactly what I was looking to do. I do have one question. How would you set it up if you wanted to create an Add Content tab next to it or on the My Content page? My users can create a Member Portfolio and if they don't have content I want them to be able to add it. It could be another tab or an option on the My Content page. Thanks.

svn7svn’s picture

Awesome! this should be built in to core.

dreba’s picture

It's what i was looking for :)

Anticosti’s picture

Exactly what I was looking for with Drupal 7.39 :)