Skip to content

Commit

Permalink
Update copyright and target blank #8
Browse files Browse the repository at this point in the history
  • Loading branch information
devamitbera committed Apr 26, 2020
1 parent 38335f4 commit 5f8ff27
Show file tree
Hide file tree
Showing 26 changed files with 410 additions and 136 deletions.
23 changes: 16 additions & 7 deletions Api/MenuLinkManagementInterface.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php
/**
* A Magento 2 module named DevBera/CmsLinkToMenu
* Copyright (C) 2019 Copyright 2019 © amitbera.com. All Rights Reserved
* DevBera
*
* This file included in DevBera/CmsLinkToMenu is licensed under OSL 3.0
*
* http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* Please see LICENSE.txt for the full text of the OSL 3.0 license
* @category DevBera
* @package DevBera_CmsLinkToMenu
* @author Amit Bera (dev.amitbera@gmail.com)
* @copyright Copyright (c) 2020 Amit Bera (https://www.amitbera.com/)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/


namespace DevBera\CmsLinkToMenu\Api;

interface MenuLinkManagementInterface
Expand All @@ -20,4 +19,14 @@ interface MenuLinkManagementInterface
* @return void
*/
public function addLinks($subject, $position = 'left');

/**
* @return string []
*/
public function getTargetBlanksLinks();
/**
* get open tab
* @return int
*/
public function isOpenInTab();
}
14 changes: 7 additions & 7 deletions Block/Adminhtml/Form/Field/CmsPageCustomLinker.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

/**
* A Magento 2 module named DevBera/CmsLinkToMenu
* Copyright (C) 2019 Copyright 2019 © amitbera.com. All Rights Reserved
*
* This file included in DevBera/CmsLinkToMenu is licensed under OSL 3.0
* DevBera
*
* http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* Please see LICENSE.txt for the full text of the OSL 3.0 license
* @category DevBera
* @package DevBera_CmsLinkToMenu
* @author Amit Bera (dev.amitbera@gmail.com)
* @copyright Copyright (c) 2020 Amit Bera (https://www.amitbera.com/)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace DevBera\CmsLinkToMenu\Block\Adminhtml\Form\Field;

use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
Expand Down
15 changes: 7 additions & 8 deletions Block/Adminhtml/Form/Field/CmsPagesList.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

/**
* A Magento 2 module named DevBera/CmsLinkToMenu
* Copyright (C) 2019 Copyright 2019 © amitbera.com. All Rights Reserved
*
* This file included in DevBera/CmsLinkToMenu is licensed under OSL 3.0
* DevBera
*
* http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* Please see LICENSE.txt for the full text of the OSL 3.0 license
* @category DevBera
* @package DevBera_CmsLinkToMenu
* @author Amit Bera (dev.amitbera@gmail.com)
* @copyright Copyright (c) 2020 Amit Bera (https://www.amitbera.com/)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace DevBera\CmsLinkToMenu\Block\Adminhtml\Form\Field;
Expand All @@ -29,7 +28,7 @@ public function __construct(
parent::__construct($context, $data);
$this->cmsPages = $cmsPages;
}

private function getCmsPagesRenderer()
{
if (!$this->cmsPagesRenderer) {
Expand Down
13 changes: 6 additions & 7 deletions Block/Adminhtml/Form/Field/LinkTypes.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

/**
* A Magento 2 module named DevBera/CmsLinkToMenu
* Copyright (C) 2019 Copyright amitbera.com. All Rights Reserved
*
* This file included in DevBera/CmsLinkToMenu is licensed under OSL 3.0
* DevBera
*
* http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* Please see LICENSE.txt for the full text of the OSL 3.0 license
* @category DevBera
* @package DevBera_CmsLinkToMenu
* @author Amit Bera (dev.amitbera@gmail.com)
* @copyright Copyright (c) 2020 Amit Bera (https://www.amitbera.com/)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace DevBera\CmsLinkToMenu\Block\Adminhtml\Form\Field;
Expand Down
13 changes: 6 additions & 7 deletions Block/Adminhtml/Form/Field/Pages.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

/**
* A Magento 2 module named DevBera/CmsLinkToMenu
* Copyright (C) 2019 Copyright 2019 © amitbera.com. All Rights Reserved
*
* This file included in DevBera/CmsLinkToMenu is licensed under OSL 3.0
* DevBera
*
* http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* Please see LICENSE.txt for the full text of the OSL 3.0 license
* @category DevBera
* @package DevBera_CmsLinkToMenu
* @author Amit Bera (dev.amitbera@gmail.com)
* @copyright Copyright (c) 2020 Amit Bera (https://www.amitbera.com/)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/


Expand Down
14 changes: 7 additions & 7 deletions Block/Adminhtml/Form/Field/StaticLinks.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

/**
* A Magento 2 module named DevBera/CmsLinkToMenu
* Copyright (C) 2019 Copyright 2019 © amitbera.com. All Rights Reserved
*
* This file included in DevBera/CmsLinkToMenu is licensed under OSL 3.0
* DevBera
*
* http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* Please see LICENSE.txt for the full text of the OSL 3.0 license
* @category DevBera
* @package DevBera_CmsLinkToMenu
* @author Amit Bera (dev.amitbera@gmail.com)
* @copyright Copyright (c) 2020 Amit Bera (https://www.amitbera.com/)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace DevBera\CmsLinkToMenu\Block\Adminhtml\Form\Field;

use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
Expand Down
9 changes: 9 additions & 0 deletions Block/Adminhtml/System/Config/Form/Fieldset/Support.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<?php
/**
* DevBera
*
* @category DevBera
* @package DevBera_CmsLinkToMenu
* @author Amit Bera (dev.amitbera@gmail.com)
* @copyright Copyright (c) 2020 Amit Bera (https://www.amitbera.com/)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace DevBera\CmsLinkToMenu\Block\Adminhtml\System\Config\Form\Fieldset;

Expand Down
49 changes: 49 additions & 0 deletions Block/Html/Topmenu/Js.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
namespace DevBera\CmsLinkToMenu\Block\Html\Topmenu;

use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use DevBera\CmsLinkToMenu\Api\MenuLinkManagementInterface;

class Js extends Template
{
/**
* @var MenuLinkManagementInterface
*/
private $menuLinkManagement;
/**
* @var Json
*/
private $jsonEncoder;

public function __construct(
Context $context,
MenuLinkManagementInterface $menuLinkManagement,
Json $jsonEncoder,
array $data = []
) {
parent::__construct($context, $data);
$this->menuLinkManagement = $menuLinkManagement;
$this->jsonEncoder = $jsonEncoder;
}

/**
* Get List of External Link list
*
* @return bool|false|string
*/
public function getJsonLinks()
{
return $this->jsonEncoder->serialize($this->menuLinkManagement->getTargetBlanksLinks());
}

/**
* Target Blank flag
* @return int
*/
public function isOpenInNewTab()
{
return $this->menuLinkManagement->isOpenInTab();
}
}
13 changes: 6 additions & 7 deletions Model/Config/Source/LinkTypes.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

/**
* A Magento 2 module named DevBera/CmsLinkToMenu
* Copyright (C) 2019 Copyright 2019 © amitbera.com. All Rights Reserved
*
* This file included in DevBera/CmsLinkToMenu is licensed under OSL 3.0
* DevBera
*
* http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* Please see LICENSE.txt for the full text of the OSL 3.0 license
* @category DevBera
* @package DevBera_CmsLinkToMenu
* @author Amit Bera (dev.amitbera@gmail.com)
* @copyright Copyright (c) 2020 Amit Bera (https://www.amitbera.com/)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace DevBera\CmsLinkToMenu\Model\Config\Source;
Expand Down
13 changes: 6 additions & 7 deletions Model/Config/Source/Pages.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

/**
* A Magento 2 module named DevBera/CmsLinkToMenu
* Copyright (C) 2019 Copyright 2019 © amitbera.com. All Rights Reserved
*
* This file included in DevBera/CmsLinkToMenu is licensed under OSL 3.0
* DevBera
*
* http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* Please see LICENSE.txt for the full text of the OSL 3.0 license
* @category DevBera
* @package DevBera_CmsLinkToMenu
* @author Amit Bera (dev.amitbera@gmail.com)
* @copyright Copyright (c) 2020 Amit Bera (https://www.amitbera.com/)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace DevBera\CmsLinkToMenu\Model\Config\Source;
Expand Down
18 changes: 18 additions & 0 deletions Model/LinkTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* DevBera
*
* @category DevBera
* @package DevBera_CmsLinkToMenu
* @author Amit Bera (dev.amitbera@gmail.com)
* @copyright Copyright (c) 2020 Amit Bera (https://www.amitbera.com/)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace DevBera\CmsLinkToMenu\Model;

class LinkTypes
{
const TYPE_LEFT = 'left';
const TYPE_RIGHT = 'right';
}
81 changes: 69 additions & 12 deletions Model/MenuLinkManagement.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

/**
* A Magento 2 module named DevBera/CmsLinkToMenu
* Copyright (C) 2019 Copyright 2019 © amitbera.com. All Rights Reserved
*
* This file included in DevBera/CmsLinkToMenu is licensed under OSL 3.0
* DevBera
*
* http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* Please see LICENSE.txt for the full text of the OSL 3.0 license
* @category DevBera
* @package DevBera_CmsLinkToMenu
* @author Amit Bera (dev.amitbera@gmail.com)
* @copyright Copyright (c) 2020 Amit Bera (https://www.amitbera.com/)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace DevBera\CmsLinkToMenu\Model;
Expand All @@ -23,6 +22,7 @@
use Magento\Framework\UrlInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use DevBera\CmsLinkToMenu\Model\LinkTypes;

class MenuLinkManagement implements MenuLinkManagementInterface
{
Expand Down Expand Up @@ -99,11 +99,7 @@ public function __construct(

public function addLinks($subject, $position = 'left')
{
$fieldValue = $this->scopeConfig->getValue(
self::XML_PATH_PRE_CMS_CUSTOM_LINKS . '/' . $position,
ScopeInterface::SCOPE_STORE
);

$fieldValue = $this->getMenuConfigValue($position);
$menuItems = $this->getLinksWithSortOrder($fieldValue);

if (!empty($menuItems) && is_array($menuItems)) {
Expand Down Expand Up @@ -282,4 +278,65 @@ private function getCmsPageUrl($page)
}
return $this->urlBuilder->getUrl(null, ['_direct' => $page->getIdentifier()]);
}

private function getMenuConfigValue($position = 'left')
{
return $this->scopeConfig->getValue(
self::XML_PATH_PRE_CMS_CUSTOM_LINKS . '/' . $position,
ScopeInterface::SCOPE_STORE
);
}

/**
* @return array
*/
public function getTargetBlanksLinks()
{
$leftMenuItems = [];
$rightMenuItems = [];

$leftMenuItems = $this->getLinksWithSortOrder(
$this->getMenuConfigValue(LinkTypes::TYPE_LEFT)
);
$rightMenuItems = $this->getLinksWithSortOrder(
$this->getMenuConfigValue(LinkTypes::TYPE_RIGHT)
);
$leftMenuItems = (!empty($leftMenuItems) && is_array($leftMenuItems))?
$leftMenuItems:[];

$rightMenuItems = (!empty($rightMenuItems) && is_array($rightMenuItems))?
$rightMenuItems:[];
$result = [];
$result = $this->getOnlyLinks(array_merge($leftMenuItems, $rightMenuItems));

return $result;
}

/**
* @param array $links
* @return array
*
*/
private function getOnlyLinks($links = [])
{
$result = [];
foreach ($links as $link) {
if ($link['link_type'] == 3) {
$result[] = $link;
}
}
return $result;
}

/**
* get open tab
* @return int
*/
public function isOpenInTab()
{
return (int) $this->scopeConfig->isSetFlag(
self::XML_PATH_PRE_CMS_CUSTOM_LINKS . '/open_in_new_tab',
ScopeInterface::SCOPE_STORE
);
}
}
Loading

0 comments on commit 5f8ff27

Please sign in to comment.