Forums / Developer / Creating content from code

Creating content from code

Author Message

Heiko Irrgang

Monday 24 January 2011 5:48:48 am

Hi, i am trying to create a page with content from php. So i read David Linnards wonderful tutorial about how to create objects in php, and it works in general, but i want to fill up the content with html or ezxml from inside the script.

Here is what i have so far:

$parentNode = eZContentObjectTreeNode::fetchByURLPath( $parentURL );
$user = eZUser::currentUser();
$p = array();
$p['class_identifier'] = 'folder';
$p['creator_id'] = $user->attribute( 'contentobject_id' );
$p['parent_node_id'] = $parentNode->attribute( 'node_id' );
$p['section_id'] = $parentNode->attribute( 'object' )->attribute( 'section_id' );
$attr = array ( ) ;
$attr['name'] = $fullName;
$attr['short_name'] = $shortName;
$attr['summary'] = '<p>AGGI</p>';
$attr['description'] = '<p>AGGI</p>';
$attr['tags'] = 'AGGI';
$p['attributes'] = $attr;
$o = eZContentFunctions::createAndPublishObject( $p );

Well, after this, the new folder is created and 'Name', 'Short Name' and 'Tags' are filled, but summary and description are both blank, what am i doing wrong?

Heiko Irrgang

Tuesday 25 January 2011 12:56:14 am

Ok, i am a little step closer: A) the correct field is 'short_description', not 'summary' and B) id does save the data in the fields, if i use

$parentNode = eZContentObjectTreeNode::fetchByURLPath( 'my_imported_stuff/test');

$m=$parentNode->dataMap();
var_dump($m['description']->content());

.... it displays the correct values, but it does not show the values in the admin interface.

Could this be some problem because i am running a multi lingual page?

Heiko Irrgang

Tuesday 25 January 2011 1:12:33 am

arrrrrr, found it: it is the visual editor, it filters out the <p>AGGI</p> :-/