cancel
Showing results for 
Search instead for 
Did you mean: 

How to apply a custom property to a node

dallinns
Champ on-the-rise
Champ on-the-rise
I have the following code and I'm trying to create a new document of a custom type with a custom property. It successfully creates the node with the custom type({http://www.someco.com/model/content/1.0}mine) , but it's not assigning the custom property ({http://www.someco.com/model/content/1.0}section).

Any hints on how to accomplish this? What am I doing wrong?

$newNode = $companyHome->createChild('{http://www.someco.com/model/content/1.0}mine', 'cm_contains', $contentName);

$contentData = new ContentData($newNode, 'cm:content');

$contentData->mimetype = 'text/html';
$contentData->content= "<html><head><title>This is my content</title></head><body>Content</body></html>";
$newNode->cm_name = $contentName;
$newNode->cm_description = 'Page Description';
$newNode->sc_section = "ENGL316001";
$properties = $newNode->getProperties();
$properties['{http://www.someco.com/model/content/1.0}section'] = "ENGL316001";
$contentData->encoding = 'UTF-8';
$newNode->cm_content = $contentData;
$session->save();
2 REPLIES 2

dallinns
Champ on-the-rise
Champ on-the-rise
I solved it.

I needed to call
$upload->setProperties($properties);
after
$properties = $upload->getProperties();
$properties['{http://www.someco.com/model/content/1.0}section'] = "ENGL316001";
to apply the properties to the new node before calling save().

ddanninger
Champ in-the-making
Champ in-the-making
thats right … also a quick possibility is to edit the "NamespaceMap.php" and add your Custom Content Model namespace and prefix like


private $namespaceMap = array(
"d"        => "http://www.alfresco.org/model/dictionary/1.0",
"sc"      => "http://www.someco.com/model/content/1.0",
….
);

And then you can edit properties on a Node via the __get and __set like:


$Node->sc_section = "ENGL316001";
$Node->cm_title = "My Title";