Skip to content

Commit

Permalink
Updated: prepared for FieldStorage::copyLegacyField() #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pspanja committed Jan 15, 2013
1 parent 07c0701 commit d8e769f
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions eZ/Publish/Core/Persistence/Legacy/Content/FieldHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,42 @@ public function createNewFields( Content $content )

foreach ( $contentType->fieldDefinitions as $fieldDefinition )
{
foreach ( array_keys( $languageCodes ) as $languageCode )
foreach ( $languageCodes as $languageCode )
{
// Skip fields passed from struct to handle them separately later
if ( isset( $fields[$fieldDefinition->id][$languageCode] ) )
{
$field = $fields[$fieldDefinition->id][$languageCode];
$this->createNewField( $field, $content );
continue;
}
else if ( $fieldDefinition->isTranslatable
|| !isset( $fields[$fieldDefinition->id][$content->versionInfo->contentInfo->mainLanguageCode] ) )

// Copy only for untranslatable field and when field in main language exists
if ( !$fieldDefinition->isTranslatable
&& isset( $fields[$fieldDefinition->id][$content->versionInfo->contentInfo->mainLanguageCode] )
)
{
$field = clone $fields[$fieldDefinition->id][$content->versionInfo->contentInfo->mainLanguageCode];
$content->fields[] = $field;
$this->copyLegacyField( $field, $languageCode, $content );
}
// In all other cases create empty field
else
{
$field = $this->getEmptyField( $fieldDefinition, $languageCode );
$content->fields[] = $field;
$this->createNewField( $field, $content );
}
else
}
}

// Create fields passed from struct
foreach ( $contentType->fieldDefinitions as $fieldDefinition )
{
foreach ( $languageCodes as $languageCode )
{
if ( isset( $fields[$fieldDefinition->id][$languageCode] ) )
{
// Use value from main language code
$field = clone $fields[$fieldDefinition->id][$content->versionInfo->contentInfo->mainLanguageCode];
$this->copyLegacyField( $field, $languageCode, $content );
$field = $fields[$fieldDefinition->id][$languageCode];
$this->createNewField( $field, $content );
}
}
}
Expand Down Expand Up @@ -351,7 +369,7 @@ public function updateFields( Content $content, UpdateStruct $updateStruct )

foreach ( $contentType->fieldDefinitions as $fieldDefinition )
{
foreach ( array_keys( $languageCodes ) as $languageCode )
foreach ( $languageCodes as $languageCode )
{
if ( isset( $updateFieldMap[$fieldDefinition->id][$languageCode] ) )
{
Expand All @@ -378,11 +396,18 @@ public function updateFields( Content $content, UpdateStruct $updateStruct )
else
{
// Use value from main language code for untranslatable field
$field = clone $contentFieldMap[$fieldDefinition->id][$content->versionInfo->contentInfo->mainLanguageCode];
if ( isset( $updateFieldMap[$fieldDefinition->id][$content->versionInfo->contentInfo->mainLanguageCode] ) )
{
$field = clone $updateFieldMap[$fieldDefinition->id][$content->versionInfo->contentInfo->mainLanguageCode];
}
else
{
$field = clone $contentFieldMap[$fieldDefinition->id][$content->versionInfo->contentInfo->mainLanguageCode];
}
$this->copyLegacyField( $field, $languageCode, $content );
}
}
// If existing language for untranslatable field, for which main language is updated,
// If field is not set for existing language and is untranslatable and main language is updated,
// also update copied field data
else if ( !$fieldDefinition->isTranslatable
&& isset( $updateFieldMap[$fieldDefinition->id][$content->versionInfo->contentInfo->mainLanguageCode] )
Expand Down Expand Up @@ -434,6 +459,11 @@ protected function getFieldMap( array $fields, &$languageCodes = null )
$fieldMap[$field->fieldDefinitionId][$field->languageCode] = $field;
}

if ( isset( $languageCodes ) )
{
$languageCodes = array_keys( $languageCodes );
}

return $fieldMap;
}

Expand Down

0 comments on commit d8e769f

Please sign in to comment.