I need to create a new default node(os page) as scholar site frontpage, when teacher registers a new site. I'm trying to achieve this by coding and adding a new node to the site.
I'm using SCHOLAR-3.4.x
So far i have modified the vsite_register.form.inc.
around line 295 where is - if ($vsite = vsite_create_vsite(...
inside that IF case i've written the following code:
// Prepares basic settings of our new node
$homenode = new stdClass();
$homenode->type = 'page';
$homenode->uid = $site_owner->uid;
$homenode->language = 'en';
$homenode->title = t('Node title');
$homenode->body[$homenode->language][0]['value'] = t('Node content text');
$homenode->body[$homenode->language][0]['format'] = 'filtered_html';
$homenode->status = 1;
$homenode->comment = 1;
$homenode->active = 1;
// Adds $node->nid and more properties
if ($homenode = node_submit($homenode)) {
node_save($homenode);
}
// Loads newly created node and adds to vsite.
$homenode = node_load($homenode->nid);
vsite_add_entity($homenode, 'node', $vsite);
//Add menu link
$item = array(
'link_path' => 'node/'.$homenode->nid,
'menu_name' => 'primary-menu',
'link_title' => $homenode->title,
'options' => array(),
'language' => 'en'
);
vsite_menu_menu_link_save($item, $vsite);
//Default homepage change to latest inserted node
$default_frontpage = db_insert('spaces_overrides') // Table name no longer needs {}
->fields(array(
'type' => 'og',
'id' => $node->nid,
'object_type' => 'variable',
'object_id' => 'site_frontpage',
'value' => serialize('node/'.$homenode->nid)
))
->execute();
So basically this code works. Upon creating a new site, a default page node is being added as front page and also inserted into the primary menu.
From here on, it gets weird.. When i go to view cp/content the page is listed and if i update the page, then its not listed anymore in cp/content view.
For some reason the node gets thrown out of og_membership table and thats why it is not listed anymore. I just cannot figure out why it gets deleted from og_membership table or which code calls the DELETE FROM og_membership ... function. Probably i am missing something in the automatic node generation...
Could someone please give me any suggestion how to fix it? Or maybe this can be done more easily by modifying the space_preset? Any help please?
Comments
That looks correct to me,
That looks correct to me, could you paste a link to your version of the form.inc file, one of us can throw it in place and see what is going on. May be a bug in the API.
Do you mean the Drupal's
Do you mean the Drupal's default form.inc file which is in /includes/ folder or openscholar specific file? If you mean the Drupal's default form.inc then it is the default for Drupal 7.21 and i have not modified it.
What would be the content of
What would be the content of the node ? Is it the same for everyone ? Most probably you dont need to changes the front page. Just modify the current one. E.g. if you want some text in front page, create a text/html box and make it display in the content_top region of front page/context
We had this solution for some
We had this solution for some time but for teachers it was too complicated to play around in layout and blocks.. so a default page node when creating a new site fitted us better. Also a default page node as a front page seems better when other pages a teacher creates are page nodes too.
Now i've been struggling on this for days and i have not yet found a solution why the programmatically created page node gets thrown out og_membership after update. I am wondering why is this happening, everything looks correct..
Finally, found the
Finally, found the solution!
The problem is that nodes created with coding are not set up in the cache and thats why they get deleted og_membership. If you clear cache just after node is created, then it wont be deleted.
I got the neccessary hint from here - https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function...
So basically i added this line at the end of my code -
entity_get_controller('node')->resetCache(array($homenode->nid));
Just after -
//Default homepage change to latest inserted node
$default_frontpage = db_insert('spaces_overrides') // Table name no longer needs {}
->fields(array(
'type' => 'og',
'id' => $node->nid,
'object_type' => 'variable',
'object_id' => 'site_frontpage',
'value' => serialize('node/'.$homenode->nid)
))
->execute();
And this solved my issue!