How to assign a section to a specific node with Workbench?

1.4k views Asked by At

I'm creating nodes using a custom modules

$node = new stdClass();
$node->type = $link['content_type'];

node_object_prepare($node);

$node->uid = $user->uid;
$node->name = $user->name;

$node->title = $html['title'];
$node->language = LANGUAGE_NONE;
$node->body[$node->language][0]['value'] = $html['html'];
$node->body[$node->language][0]['summary'] = $html['summary'];
$node->body[$node->language][0]['format'] = 'filtered_html';

$node->menu['enabled'] = 0; // 1 to enable providing a link in main menu
$node->menu['link_title'] = urlencode($html['title']);
$node->menu['description'] = urlencode($html['summary']);
$node->menu['parent'] = 'main-menu:0';

$node->menu['weight'] = 5;
$node->path['alias'] = urlencode($html['title']) . time();
$node->comment = 1;

$node->status = 1;        // 1 means published
$node->promote = 0;
$node->revision = 0;

$node->changed = $_SERVER['REQUEST_TIME'];
$node->created = $_SERVER['REQUEST_TIME'];

node_submit($node);
@node_save($node);

$node->path['alias'] .= '+' . $node->nid;

node_submit($node);
@node_save($node);

db_update('node_revision')
    ->fields(array('uid' => $node->uid))
    ->condition('vid', $node->vid)
    ->execute();

But now I need to assign each node a I create a workbench section, so I tried doing this:

$node->workbench_access = array('66');

node_submit($node);
@node_save($node);

$node->path['alias'] .= '+' . $node->nid;

node_submit($node);
@node_save($node);

db_update('node_revision')
    ->fields(array('uid' => $node->uid))
    ->condition('vid', $node->vid)
    ->execute();

This add the workbench access id temporarily, but when the page is refreshed it doesn't apply it. Is there a way to assign a node to a workbench section using php?

2

There are 2 answers

1
Clive On BEST ANSWER

I just installed this module for the first time today funnily enough, it looks good :-)

Having a look at the workbench_access_node_insert() function (in the workbench_access.module file) it looks like the node object key it's looking for is workbench_access_id, not workbench_access.

Also you need to provide an access scheme (either menu or taxonomy depending on what access scheme you've chosen at admin/config/workbench/access/settings). I think your code should look a bit like this:

$node->workbench_access_scheme['access_scheme'] = 'taxonomy'; // or 'menu'
$node->workbench_access_id = array('66');

That's untested but looking at the module file it should work.

1
Silambarasan On

The following line didn't work for me.

$node->workbench_access_id = array('66');

It worked when I changed it to

$node->workbench_access = array('66');