-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ added object bricks and extended embed mechanism
- Loading branch information
1 parent
ec64295
commit 5d21d28
Showing
22 changed files
with
428 additions
and
40 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace DavesWeblab\RestBundle\Normalizer; | ||
|
||
use DavesWeblab\RestBundle\Serializer\Context\ContextInterface; | ||
use Pimcore\Model\DataObject\Objectbrick; | ||
use Pimcore\Model\DataObject\Objectbrick\Data\AbstractData; | ||
|
||
class ObjectbrickFieldNormalizer implements NormalizerInterface | ||
{ | ||
/** | ||
* @param mixed $data | ||
* | ||
* @return bool | ||
*/ | ||
public function supports($data) | ||
{ | ||
return $data instanceof Objectbrick; | ||
} | ||
|
||
/** | ||
* @param Objectbrick $data | ||
* @param ContextInterface $context | ||
* | ||
* @return string[] | ||
*/ | ||
public function getSupportedAttributes($data, ContextInterface $context) | ||
{ | ||
return $data->getAllowedBrickTypes(); | ||
} | ||
|
||
/** | ||
* @param array $attributes | ||
* @return array|string[] | ||
*/ | ||
public function removeUnsupportedAttributes(array $attributes) | ||
{ | ||
$unsupported = ["id"]; | ||
return array_filter($attributes, function ($attribute) use ($unsupported) { | ||
return !in_array($attribute, $unsupported); | ||
}); | ||
} | ||
|
||
/** | ||
* @param AbstractData $data | ||
* @param string $attribute | ||
* @param ContextInterface $context | ||
* | ||
* @param array|null $config | ||
* @return NormalizedValue | ||
*/ | ||
public function getAttribute($data, string $attribute, ContextInterface $context, array $config = null) | ||
{ | ||
$getter = "get" . ucfirst($attribute); | ||
|
||
if (!method_exists($data, $getter)) { | ||
return null; | ||
} | ||
|
||
$value = $data->$getter(); | ||
|
||
return $context->buildNormalizedValueFromFieldDefinition( | ||
$value, | ||
null, | ||
$data | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace DavesWeblab\RestBundle\Normalizer; | ||
|
||
use DavesWeblab\RestBundle\Normalizer\Transformer\ObjectBrickAsIdTransformer; | ||
use DavesWeblab\RestBundle\Serializer\Context\ContextInterface; | ||
use Pimcore\Model\DataObject\ClassDefinition\Data; | ||
use Pimcore\Model\DataObject\Objectbrick\Data\AbstractData; | ||
use Pimcore\Model\DataObject\Objectbrick\Definition; | ||
|
||
class ObjectbrickNormalizer implements NormalizerInterface | ||
{ | ||
/** | ||
* @param mixed $data | ||
* | ||
* @return bool | ||
*/ | ||
public function supports($data) | ||
{ | ||
return $data instanceof AbstractData; | ||
} | ||
|
||
/** | ||
* @param AbstractData $data | ||
* @param ContextInterface $context | ||
* | ||
* @return string[] | ||
*/ | ||
public function getSupportedAttributes($data, ContextInterface $context) | ||
{ | ||
$viewDefinition = $context->getConfig()->getViewDefinitionForObjectbrick($data->getType()); | ||
|
||
if (!$viewDefinition->isEmpty()) { | ||
return $viewDefinition->getSupportedAttributes(); | ||
} | ||
|
||
$attributes = []; | ||
|
||
/** | ||
* @var Definition $definition | ||
*/ | ||
$definition = $data->getDefinition(); | ||
|
||
/** | ||
* @var Data $fieldDefinition | ||
*/ | ||
foreach ($definition->getFieldDefinitions() as $fieldDefinition) { | ||
$attributes[] = $fieldDefinition->getName(); | ||
} | ||
|
||
return $attributes; | ||
} | ||
|
||
/** | ||
* @param array $attributes | ||
* @return array|string[] | ||
*/ | ||
public function removeUnsupportedAttributes(array $attributes) | ||
{ | ||
return $attributes; | ||
} | ||
|
||
/** | ||
* @param AbstractData $data | ||
* @param string $attribute | ||
* @param ContextInterface $context | ||
* | ||
* @param array|null $config | ||
* @return NormalizedValue | ||
*/ | ||
public function getAttribute($data, string $attribute, ContextInterface $context, array $config = null) | ||
{ | ||
if ($attribute == "id") { | ||
$id = ObjectBrickAsIdTransformer::transformObjectbrickId($data); | ||
|
||
return new NormalizedValue($id, $id); | ||
} | ||
|
||
$viewConfig = $context->getConfig()->getViewDefinitionForFieldCollection($data->getType()); | ||
|
||
if ($viewConfig->isMappedAttribute($attribute)) { | ||
$attribute = $viewConfig->getMappedAttribute($attribute); | ||
} | ||
|
||
/** | ||
* @var Definition $definition | ||
*/ | ||
$definition = $data->getDefinition(); | ||
$fieldDefinition = $definition->getFieldDefinition($attribute) ?: null; | ||
|
||
$getter = "get" . ucfirst($attribute); | ||
|
||
if (!method_exists($data, $getter)) { | ||
return null; | ||
} | ||
|
||
$value = $data->$getter(); | ||
|
||
return $context->buildNormalizedValueFromFieldDefinition( | ||
$value, | ||
$fieldDefinition, | ||
$data, | ||
$viewConfig->getAttributeConfig($attribute) | ||
); | ||
} | ||
} |
Oops, something went wrong.