From f7162f879c7e4c80a8741340f2a124183291ee34 Mon Sep 17 00:00:00 2001 From: Frederik Rommel Date: Sun, 11 Aug 2024 15:10:35 +0200 Subject: [PATCH] add support for array-data in content --- Api/Data/NodeInterface.php | 2 +- Model/Menu/Node.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Api/Data/NodeInterface.php b/Api/Data/NodeInterface.php index 8f10a24a..5788a913 100644 --- a/Api/Data/NodeInterface.php +++ b/Api/Data/NodeInterface.php @@ -82,7 +82,7 @@ public function getContent(); /** * Set content * - * @param string $content + * @param string|array $content * @return $this */ public function setContent($content); diff --git a/Model/Menu/Node.php b/Model/Menu/Node.php index 4291d991..cc673ee1 100644 --- a/Model/Menu/Node.php +++ b/Model/Menu/Node.php @@ -7,6 +7,7 @@ use Magento\Framework\Model\Context; use Magento\Framework\Model\ResourceModel\AbstractResource as AbstractResource; use Magento\Framework\Registry; +use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\Serialize\SerializerInterface; use Snowdog\Menu\Api\Data\NodeInterface; @@ -97,7 +98,13 @@ public function setType($type) */ public function getContent() { - return $this->_getData(NodeInterface::CONTENT); + $content = $this->_getData(NodeInterface::CONTENT); + + if (strpos($content, '{') === 0 && strpos($content, '}') === strlen($content) - 1) { + $content = $this->serializer->unserialize($content) ?: $content; + } + + return $content; } /** @@ -105,6 +112,10 @@ public function getContent() */ public function setContent($content) { + if (is_array($content)) { + $content = $this->serializer->serialize($content); + } + return $this->setData(NodeInterface::CONTENT, $content); }