Skip to content
Open
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
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$content is not always a string, when _getData() returns null this will throw an error

$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