Skip to content

Commit

Permalink
Merge pull request #867 from sebsasto/fix-embedded-class
Browse files Browse the repository at this point in the history
Make Embedded Class compatible with Pimcore 5.6
  • Loading branch information
dpfaffenbauer authored Mar 16, 2019
2 parents 8e972e3 + e2b31a5 commit c43a97b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
18 changes: 15 additions & 3 deletions src/CoreShop/Bundle/PimcoreBundle/CoreExtension/EmbeddedClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@

final class EmbeddedClass extends Multihref
{
/**
* Static type of this element
*
* @var string
*/
public $fieldtype = 'coreShopEmbeddedClass';

/**
* @var int
*/
Expand Down Expand Up @@ -199,10 +206,15 @@ public function preGetData($object, $params = [])

if (!is_array($data)) {
$data = $this->load($object, ['force' => true]);
$setter = 'set' . ucfirst($this->getName());

if (method_exists($object, $setter)) {
$object->$setter($data);
//TODO: Remove once CoreShop requires min Pimcore 5.5
if (method_exists($object, 'setObjectVar')) {
$object->setObjectVar($this->getName(), $data);
} else {
$setter = 'set' . ucfirst($this->getName());
if (method_exists($object, $setter)) {
$object->$setter($data);
}
}
}

Expand Down
37 changes: 17 additions & 20 deletions src/CoreShop/Component/Pimcore/DataObject/EditmodeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,29 @@

class EditmodeHelper
{
private $objectData = [];
private $metaData = [];

public function getDataForObject(DataObject\Concrete $object, $objectFromVersion = false)
{
$this->objectData = [];

foreach ($object->getClass()->getFieldDefinitions(['object' => $object]) as $key => $def) {
$this->getDataForEditmode($object, $key, $def, $objectFromVersion);
}

return [
'objectData' => $this->objectData,
'metaData' => $this->metaData,
];
}

private function getDataForEditmode($object, $key, $fielddefinition, $objectFromVersion, $level = 0)
{
$dataObjectController = new DataObjectController();
$trackerReflector = new \ReflectionClass(DataObjectController::class);
$method = $trackerReflector->getMethod('getDataForField');
$method = $trackerReflector->getMethod('getDataForObject');
$method->setAccessible(true);
$method->invoke($dataObjectController, $object, $objectFromVersion);
$method->setAccessible(false);

$method->getClosure($dataObjectController)($object, $key, $fielddefinition, $objectFromVersion, $level);
$objectData = $trackerReflector->getProperty('objectData');
$metaData = $trackerReflector->getProperty('metaData');

$method->setAccessible(false);
$objectData->setAccessible(true);
$finalObjectData = $objectData->getValue($dataObjectController);
$objectData->setAccessible(false);

$metaData->setAccessible(true);
$finalMetaData = $metaData->getValue($dataObjectController);
$metaData->setAccessible(false);

return [
'objectData' => $finalObjectData,
'metaData' => $finalMetaData,
];
}
}

0 comments on commit c43a97b

Please sign in to comment.