Skip to content

Commit

Permalink
Merge pull request #766 from dpfaffenbauer/jms-pimcore-object-serializer
Browse files Browse the repository at this point in the history
[ResourceBundle] add JMS Serializer Handler for Pimcore Objects
  • Loading branch information
dpfaffenbauer authored Jan 11, 2019
2 parents e3699a1 + 8a68c90 commit 85a586e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ services:
- { name: jms_serializer.handler, type: relation<?>, direction: serialization, format: json, method: serializeRelation}
- { name: jms_serializer.handler, type: relation<?>, direction: deserialization, format: json, method: deserializeRelation}

coreshop.jms_serializer.handler.pimcore_object:
class: CoreShop\Bundle\ResourceBundle\Serialization\PimcoreObjectHandler
tags:
- { name: jms_serializer.handler, type: pimcoreObject, direction: serialization, format: json, method: serializeRelation}

jms_serializer.object_constructor:
alias: jms_serializer.doctrine_object_constructor
public: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Bundle\ResourceBundle\Serialization;

use JMS\Serializer\Context;
use JMS\Serializer\JsonSerializationVisitor;
use Pimcore\Model\DataObject\Concrete;

class PimcoreObjectHandler
{
public function serializeRelation(JsonSerializationVisitor $visitor, $relation, array $type, Context $context)
{
if ($relation instanceof Concrete) {
return $relation->getId();
}

return null;
}
}

0 comments on commit 85a586e

Please sign in to comment.