Wednesday 02 February 2011 2:04:19 am
Thank you, I've tested your advice now. I have a class 'cars_article' and I want to create a new attribute 'keywords'. I have done like this:
class MyTestingHandler extends eZContentObjectEditHandler
{
function publish($contentObjectID, $contentObjectVersion)
{
$articleClass = eZContentClass::fetchByIdentifier('cars_article');
if (is_object($articleClass))
{
$contentClassID = $articleClass->attribute('id');
$classVersion = $articleClass->attribute('version');
$DataTypeString = 'ezstring';
$new_attribute = eZContentClassAttribute::create($contentClassID, $DataTypeString);
$new_attribute->setAttribute('version', $classVersion);
$new_attribute->setAttribute('name', 'Keywords');
$new_attribute->setAttribute('is_required', 0);
$new_attribute->setAttribute('is_searchable', 0);
$new_attribute->setAttribute('can_translate', 0);
$new_attribute->setAttribute('identifier','keywords');
$dataType = $new_attribute->dataType();
$dataType->initializeClassAttribute($new_attribute);
$new_attribute->store();
} I fetched the object like this: $object = eZContentObject::fetch($contentObjectID);
2 problems I got:
- In backend creating new article of class 'cars_article' I have now a new field 'keywords'. BUT if I want to add keywords to an existing article, I don't have the field. What's wrong here?
- How can I add keywords into the article programmatically?
I have a knot in my brain :D
Thanks & greetings Tom
|