Skip to content

Commit

Permalink
Merge branch 'feature/102271' into test/stage
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Ortega committed Sep 15, 2023
2 parents 9d189b8 + b15979c commit 46713b7
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 9 deletions.
28 changes: 26 additions & 2 deletions Api/Data/NodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface NodeInterface
const TARGET = 'target';
const IMAGE = 'image';
const IMAGE_ALT_TEXT = 'image_alt_text';
const IMAGE_WIDTH = 'image_width';
const IMAGE_HEIGHT = 'image_heigth';
const CREATION_TIME = 'creation_time';
const UPDATE_TIME = 'update_time';
const IS_ACTIVE = 'is_active';
Expand Down Expand Up @@ -192,18 +194,40 @@ public function setImage($image);
/**
* Get image alt text
*
* @return string
* @return string|null
*/
public function getImageAltText();

/**
* Set image alt text
*
* @param string $altText
* @param string|null $altText
* @return $this
*/
public function setImageAltText($altText);

/**
* @return int|null
*/
public function getImageWidth();

/**
* @param int|null $width
* @return $this
*/
public function setImageWidth($width);

/**
* @return int|null
*/
public function getImageHeight();

/**
* @param int|null $height
* @return $this
*/
public function setImageHeight($height);

/**
* Get creation time
*
Expand Down
2 changes: 2 additions & 0 deletions Block/Adminhtml/Edit/Tab/Nodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ private function renderNodeList($level, $parent, $data)
'image' => $node->getImage(),
'image_url' => $node->getImage() ? $this->imageFile->getUrl($node->getImage()) : null,
'image_alt_text' => $node->getImageAltText(),
'image_width' => $node->getImageWidth(),
'image_height' => $node->getImageHeight(),
'columns' => $this->renderNodeList($level + 1, $node->getId(), $data) ?: [],
'selected_item_id' => $node->getSelectedItemId()
];
Expand Down
10 changes: 7 additions & 3 deletions Block/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\View\Element\Template;
use Magento\Framework\Event\Manager as EventManager;
use Magento\Framework\Escaper;
use Snowdog\Menu\Api\Data\NodeInterface;
use Snowdog\Menu\Api\MenuRepositoryInterface;
use Snowdog\Menu\Api\NodeRepositoryInterface;
use Snowdog\Menu\Model\Menu\Node\Image\File as ImageFile;
Expand Down Expand Up @@ -268,7 +269,7 @@ public function isViewAllLinkAllowed($nodeType)
}

/**
* @param NodeRepositoryInterface $node
* @param NodeInterface $node
* @return string
*/
public function renderViewAllLink($node)
Expand All @@ -279,7 +280,7 @@ public function renderViewAllLink($node)
}

/**
* @param NodeRepositoryInterface $node
* @param NodeInterface $node
* @return string
*/
public function renderMenuNode($node)
Expand Down Expand Up @@ -381,7 +382,7 @@ public function getMenuCssClass($defaultClass = '')
}

/**
* @param NodeRepositoryInterface $node
* @param NodeInterface $node
* @return Template
*/
private function getMenuNodeBlock($node)
Expand All @@ -404,6 +405,9 @@ private function getMenuNodeBlock($node)
->setImage($node->getImage())
->setImageUrl($node->getImage() ? $this->imageFile->getUrl($node->getImage()) : null)
->setImageAltText($node->getImageAltText())
->setImageWidth($node->getImageWidth())
->setImageHeight($node->getImageHeight())
->setImageAltText($node->getImageAltText())
->setCustomTemplate($node->getNodeTemplate())
->setAdditionalData($node->getAdditionalData())
->setSelectedItemId($node->getSelectedItemId());
Expand Down
2 changes: 2 additions & 0 deletions Model/GraphQl/Resolver/DataProvider/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ private function convertData(NodeInterface $node): array
NodeInterface::TARGET => (bool) $node->getTarget(),
NodeInterface::IMAGE => $node->getImage(),
NodeInterface::IMAGE_ALT_TEXT => $node->getImageAltText(),
NodeInterface::IMAGE_WIDTH => $node->getImageWidth(),
NodeInterface::IMAGE_HEIGHT => $node->getImageHeight(),
self::TEMPLATE_FIELD => $node->getNodeTemplate(),
self::SUBMENU_TEMPLATE_FIELD => $node->getSubmenuTemplate(),
NodeInterface::CREATION_TIME => $node->getCreationTime(),
Expand Down
32 changes: 32 additions & 0 deletions Model/Menu/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,38 @@ public function setImageAltText($altText)
return $this->setData(NodeInterface::IMAGE_ALT_TEXT, $altText);
}

/**
* @inheritdoc
*/
public function getImageWidth()
{
return $this->_getData(NodeInterface::IMAGE_WIDTH);
}

/**
* @inheritdoc
*/
public function setImageWidth($width)
{
return $this->setData(NodeInterface::IMAGE_WIDTH, $width);
}

/**
* @inheritdoc
*/
public function getImageHeight()
{
return $this->_getData(NodeInterface::IMAGE_HEIGHT);
}

/**
* @inheritdoc
*/
public function setImageHeight($height)
{
return $this->setData(NodeInterface::IMAGE_HEIGHT, $height);
}

/**
* @inheritdoc
*/
Expand Down
8 changes: 8 additions & 0 deletions Model/Menu/Node/Image/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ public function clone(string $file): string
return $fileClonePath;
}

public function getImageSize(string $file): array
{
$mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
$fileFullPath = $mediaDirectory->getAbsolutePath(self::PATH . $file);

return getimagesize($fileFullPath);
}

private function getAbsolutePath(): string
{
$mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
Expand Down
2 changes: 2 additions & 0 deletions Model/MenuManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ private function getCategoriesNodeList($level, $parent, array $data): array
'node_template' => null,
'image' => null,
'image_alt_text' => null,
'image_width' => null,
'image_height' => null,
'submenu_template' => null,
'columns' => $this->getCategoriesNodeList($level + 1, $nodeId, $data) ?: []
];
Expand Down
38 changes: 35 additions & 3 deletions Service/Menu/SaveRequestProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,46 @@ private function processNodeObject(
$nodeObject->setLevel((string) $level);
$nodeObject->setPosition((string) $position);

$this->processImageParameters($nodeData, $nodeObject);

$nodeObject->setSelectedItemId($nodeData['selected_item_id'] ?? null);
}

private function processImageParameters(array $nodeData, NodeInterface &$nodeObject): void
{
$nodeObject->setImageAltText($nodeData[NodeInterface::IMAGE_ALT_TEXT] ?? null);

if ($nodeObject->getImage() && empty($nodeData['image'])) {
$this->nodeImageFile->delete($nodeObject->getImage());
}

$nodeObject->setImage($nodeData['image'] ?? null);
$nodeObject->setImageAltText($nodeData['image_alt_text'] ?? null);
if (empty($nodeData[NodeInterface::IMAGE])) {
$nodeObject->setImageWidth(null);
$nodeObject->setImageHeight(null);
$nodeObject->setImage(null);
return;
}

$nodeObject->setSelectedItemId($nodeData['selected_item_id'] ?? null);
if (empty($nodeData[NodeInterface::IMAGE_WIDTH])
|| empty($nodeData[NodeInterface::IMAGE_HEIGHT])
) {
$imageSize = $this->nodeImageFile->getImageSize($nodeData[NodeInterface::IMAGE]);

if (!empty($imageSize)) {
$nodeObject
->setImageWidth(
!empty($nodeData[NodeInterface::IMAGE_WIDTH])
? $nodeData[NodeInterface::IMAGE_WIDTH]
: $imageSize[0]
);
$nodeObject
->setImageHeight(
!empty($nodeData[NodeInterface::IMAGE_HEIGHT])
? $nodeData[NodeInterface::IMAGE_HEIGHT]
: $imageSize[1]
);
}
}
}

/**
Expand Down
38 changes: 38 additions & 0 deletions Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class UpgradeSchema implements UpgradeSchemaInterface
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
Expand Down Expand Up @@ -59,6 +60,10 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
$this->addNodeSelectedItemId($setup);
}

if (version_compare($context->getVersion(), '0.2.7', '<')) {
$this->addNodeImageSizeFields($setup);
}

$setup->endSetup();
}

Expand Down Expand Up @@ -298,4 +303,37 @@ private function addNodeSelectedItemId(SchemaSetupInterface $setup)

return $this;
}

/**
* @return $this
*/
private function addNodeImageSizeFields(SchemaSetupInterface $setup)
{
$connection = $setup->getConnection();
$table = $setup->getTable('snowmenu_node');

$connection->addColumn(
$table,
NodeInterface::IMAGE_WIDTH,
[
'type' => Table::TYPE_INTEGER,
'nullable' => true,
'after' => NodeInterface::IMAGE_ALT_TEXT,
'comment' => 'Image Width'
]
);

$connection->addColumn(
$table,
NodeInterface::IMAGE_HEIGHT,
[
'type' => Table::TYPE_INTEGER,
'nullable' => true,
'after' => NodeInterface::IMAGE_WIDTH,
'comment' => 'Image Height'
]
);

return $this;
}
}
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Snowdog_Menu" setup_version="0.2.6">
<module name="Snowdog_Menu" setup_version="0.2.7">
<sequence>
<module name="Magento_GraphQl"/>
</sequence>
Expand Down
2 changes: 2 additions & 0 deletions view/adminhtml/templates/menu/nodes.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ $vueComponents = $block->getVueComponents();
"product" : "<?= __('Product') ?>",
"productId" : "<?= __('Product ID') ?>",
"imageAltText" : "<?= __('Image Alt text') ?>",
"imageWidth" : "<?= __('Image Width') ?>",
"imageHeight" : "<?= __('Image Height') ?>",
"selectedItemId" : "<?= __('Selected Item Id') ?>"
}
}
Expand Down
2 changes: 2 additions & 0 deletions view/adminhtml/web/vue/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@
content: null,
image: null,
image_alt_text: '',
image_width: '',
image_height: '',
node_template: null,
submenu_template: null,
columns: [],
Expand Down
16 changes: 16 additions & 0 deletions view/adminhtml/web/vue/menu-type.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@
type="text"
/>

<simple-field
v-if="showImage"
id="image_width"
v-model="item.image_width"
:label="config.translation.imageWidth"
type="text"
/>

<simple-field
v-if="showImage"
id="image_height"
v-model="item.image_height"
:label="config.translation.imageHeight"
type="text"
/>

<h2>
{{ templatesLabel }}
</h2>
Expand Down

0 comments on commit 46713b7

Please sign in to comment.