Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResourceBundle] add JMS Serializer Handler for Pimcore Objects #766

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}