eZ Community » Forums » Developer » modify classes by script
expandshrink

modify classes by script

modify classes by script

Tuesday 12 June 2012 11:58:38 am - 1 reply

who can help me ?

 

i wnat to script my classes attributes  modification ...

 

Alex

Tuesday 12 June 2012 12:08:27 pm

This snippet worked for me some years ago

$class will be the class you're trying to modify. As this was inside a class i build, $this->Language is used, but you can replace that harcoding it for the language you want. 

 $attributes = $class->fetchAttributes();
 $new_attribute = eZContentClassAttribute::create( $class->attribute( 'id'), "ezstring", array(),
 $this->Language );
 $attrcnt = count( $attributes ) + 1;
 $new_attribute->setName( "Valor",  $this->Language );
 $dataType = $new_attribute->dataType();
 $dataType->initializeClassAttribute( $new_attribute );
 $new_attribute->setAttribute( "version", 0 );
 $new_attribute->setAttribute( "identifier", "valor" );
 $new_attribute->setAttribute( "is_required", false );
 $new_attribute->setAttribute( "placement", $attrcnt );
$new_attribute->store();
expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from