Skip to content

Commit

Permalink
add support for array-data in content
Browse files Browse the repository at this point in the history
  • Loading branch information
rommelfreddy committed Aug 11, 2024
1 parent 73681cd commit f7162f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Api/Data/NodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getContent();
/**
* Set content
*
* @param string $content
* @param string|array $content
* @return $this
*/
public function setContent($content);
Expand Down
13 changes: 12 additions & 1 deletion Model/Menu/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -97,14 +98,24 @@ 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;
}

/**
* @inheritdoc
*/
public function setContent($content)
{
if (is_array($content)) {
$content = $this->serializer->serialize($content);
}

return $this->setData(NodeInterface::CONTENT, $content);
}

Expand Down

0 comments on commit f7162f8

Please sign in to comment.