Created
September 8, 2015 08:41
-
-
Save johanb/f2b08b56703e44d7eb72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function transformAttribute($attribute) | |
{ | |
if ($attribute instanceof DateTime) { | |
// Convert dates to ISO-8601 | |
return $attribute->format(\DateTime::ISO8601); | |
} elseif ($attribute instanceof RichTextData) { | |
// RichTextData | |
return $attribute->getRawContent(); | |
} elseif ($attribute instanceof ElementCriteriaModel) { | |
// ElementCriteriaModel | |
if ($attribute->elementType instanceof AssetElementType) { | |
$asset = $attribute->first(); | |
return $asset ? UrlHelper::getSiteUrl($asset->getUrl()) : null; | |
} elseif ($attribute->elementType instanceof MatrixBlockElementType) { | |
$arrBlocks = []; | |
foreach ($attribute->find() as $block) { | |
$arrBlocks[] = $this->transformAttribute($block->getContent()); | |
} | |
return $arrBlocks; | |
} | |
} else { | |
return ModelHelper::packageAttributeValue($attribute); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment