Warning: You are browsing the documentation from version 4 to 10 of Pimcore. Please visit https://pimcore.com/docs/platform/ for the latest versions of Pimcore.
Version:

Locking Fields

Sometimes it's useful that a field cannot be modified/deleted in the class editor. Especially if a class is created by a plugin.

Pimcore offers the possibility to lock a field programmatically, you can call the method setLocked() on every Pimcore\Model\DataObject\Class\Data object.

Example

The following example will lock every field inside the class with the ID 7.

$class = DataObject\ClassDefinition::getById(7);
$fields = $class->getFielddefinitions();
 
foreach ($fields as $field) {
   $field->setLocked(true);
}
 
$class->save();