Friday 15 April 2011 4:19:16 am
Hi, I have created the project http://projects.ez.no/nmcontentclass which is supposed to make it easier to work with a class specification, and have that spec imported as new and modified classes into eZ Publish. The extension works as intended, except for one thing: When I try to add an attribute to an existing class, the attribute is only displayed when creating a new object from that class, and not when modifying an object which existed before the attribute was added. I suspect that this is related to class and/or class attribute versioning, but I can't wrap my head around how this is supposed to work. When a attribute is created, here's an exerpt of code that is run (I've removed some code which I assume is irrelevant). For more code, check out the updateClasses() method in http://svn.projects.ez.no/nmcontentclass/trunk/classes/contentclass.php
// create attribute$attribute = eZContentClassAttribute::create( $classID, $dataType, array(), $languageLocale);
$dt = $attribute->dataType();
$dt->initializeClassAttribute( $attribute );
$attribute->store();
// update attribute
$attrParams = array();
$attrParams['identifier'] = $attributeData['identifier'];
$attrParams['name'] = $attributeData['name'];
$attrParams['is_searchable'] = 1;
$attrParams['is_required'] = 0;
$attrParams['placement'] = $attributeData['placement'];
$attrParams['version'] = $classVersionID; // this is defined earlier in the code
foreach($attrParams as $key => $val)
{
if($val != $attribute->attribute($key))
{
$attribute->setAttribute( $key, $val);
}
}
$attribute->store();
Sincerely,
Eirik Alfstad Johansen
http://www.netmaking.no/
|