eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\TextLineConverter::toStorageFieldDefinition PHP Method

toStorageFieldDefinition() public method

Converts field definition data in $fieldDef into $storageFieldDef.
public toStorageFieldDefinition ( eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef, StorageFieldDefinition $storageDef )
$fieldDef eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition
$storageDef eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition
    public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
    {
        if (isset($fieldDef->fieldTypeConstraints->validators[self::STRING_LENGTH_VALIDATOR_IDENTIFIER]['maxStringLength'])) {
            $storageDef->dataInt1 = $fieldDef->fieldTypeConstraints->validators[self::STRING_LENGTH_VALIDATOR_IDENTIFIER]['maxStringLength'];
        } else {
            $storageDef->dataInt1 = 0;
        }
        if (isset($fieldDef->fieldTypeConstraints->validators[self::STRING_LENGTH_VALIDATOR_IDENTIFIER]['minStringLength'])) {
            $storageDef->dataInt2 = $fieldDef->fieldTypeConstraints->validators[self::STRING_LENGTH_VALIDATOR_IDENTIFIER]['minStringLength'];
        } else {
            $storageDef->dataInt2 = 0;
        }
        $storageDef->dataText1 = $fieldDef->defaultValue->data;
    }

Usage Example

 /**
  * @group fieldType
  * @group textLine
  * @covers \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\TextLineConverter::toStorageFieldDefinition
  */
 public function testToStorageFieldDefinitionNoValidator()
 {
     $defaultText = 'This is a default text';
     $storageFieldDef = new StorageFieldDefinition();
     $defaultValue = new FieldValue();
     $defaultValue->data = $defaultText;
     $fieldTypeConstraints = new FieldTypeConstraints();
     $fieldDef = new PersistenceFieldDefinition(array('fieldTypeConstraints' => $fieldTypeConstraints, 'defaultValue' => $defaultValue));
     $this->converter->toStorageFieldDefinition($fieldDef, $storageFieldDef);
     self::assertSame(0, $storageFieldDef->dataInt1);
     self::assertSame($fieldDef->defaultValue->data, $storageFieldDef->dataText1);
 }