Skip to content

Commit

Permalink
Merge pull request #294 from SnowdogApps/feature/101741
Browse files Browse the repository at this point in the history
#101741 Added exception when level of depth field is not a valid number
  • Loading branch information
adamwaclawczyk authored Jul 5, 2024
2 parents db54d42 + 5b55eda commit 0024ff2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Controller/Adminhtml/Menu/ImportCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Snowdog\Menu\Controller\Adminhtml\Menu;

use Exception;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\JsonFactory;
use Snowdog\Menu\Api\MenuManagementInterface;
use Magento\Framework\Exception\NoSuchEntityException;

class ImportCategories extends Action implements HttpPostActionInterface
{
Expand Down Expand Up @@ -47,24 +47,27 @@ public function execute()
{
$categoryId = (int) $this->_request->getParam('category_id');
$depth = $this->_request->getParam('depth');
if (!is_numeric($depth)) {
$depth = null;
}

$result = $this->resultJsonFactory->create();
try {
if ($depth != 'NaN' && !is_numeric($depth)) {
throw new Exception('Please add a valid number for Level of depth field');
}

$categoryTree = $this->menuManagement->getCategoryNodeList($categoryId, $depth);

$output = [
'success' => 1,
'list' => $categoryTree
];
} catch (NoSuchEntityException $exception) {
} catch (Exception $exception) {
$output = [
'success' => 0,
'message' => $exception->getMessage(),
'list' => []
];
}

$result = $this->resultJsonFactory->create();
$result->setData($output);

return $result;
Expand Down
1 change: 1 addition & 0 deletions view/adminhtml/ui_component/snowmenu_menu_form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
</field>
<field name="depth" formElement="input">
<settings>
<elementTmpl>Snowdog_Menu/form/element/depth-input</elementTmpl>
<dataType>int</dataType>
<label translate="true">Level of depth</label>
<validation>
Expand Down
17 changes: 17 additions & 0 deletions view/adminhtml/web/template/form/element/depth-input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<input
class="admin__control-text"
type="number"
min="0"
data-bind="
event: {change: userChanges},
value: value,
hasFocus: focused,
valueUpdate: valueUpdate,
attr: {
name: inputName,
placeholder: placeholder,
'aria-describedby': noticeId,
id: uid,
disabled: disabled,
}"
/>

0 comments on commit 0024ff2

Please sign in to comment.