Skip to content

Commit

Permalink
feat: Ajuste boas praticas Magento e menu de configurações no admin
Browse files Browse the repository at this point in the history
  • Loading branch information
gihovani committed May 30, 2022
1 parent fe6e99d commit 9bae924
Show file tree
Hide file tree
Showing 33 changed files with 280 additions and 174 deletions.
1 change: 1 addition & 0 deletions Block/Adminhtml/System/Config/Form/Field/ColorPicker.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Gg2\ToastMessage\Block\Adminhtml\System\Config\Form\Field;

Expand Down
12 changes: 2 additions & 10 deletions Block/Message.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Gg2\ToastMessage\Block;

Expand All @@ -13,16 +14,7 @@
class Message extends Messages
{
const MAGENTO_DEFAULT_TEMPLATE = 'Magento_Theme::messages.phtml';

/**
* @var Settings
*/
protected $settings;

/**
* @var ManagerInterface
*/
protected $messageManager;
protected Settings $settings;

public function __construct(
Context $context,
Expand Down
2 changes: 1 addition & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Gg2\ToastMessage\Helper;

Expand All @@ -14,7 +15,6 @@ class Data extends AbstractHelper
const TYPE_INFO = 'info';

const XML_PATH_ACTIVE = 'gg2_toast/%s/active';
const XML_PATH_REMOVECOOKIEAFTER = 'gg2_toast/%s/removeCookieAfter';
const XML_PATH_POSITION = 'gg2_toast/%s/position';
const XML_PATH_BGCOLOR = 'gg2_toast/%s/bgColor';
const XML_PATH_ICON = 'gg2_toast/%s/icon';
Expand Down
33 changes: 0 additions & 33 deletions Model/AdditionalConfigProvider.php

This file was deleted.

1 change: 1 addition & 0 deletions Model/Config/Source/Icon.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Gg2\ToastMessage\Model\Config\Source;

Expand Down
1 change: 1 addition & 0 deletions Model/Config/Source/Position.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Gg2\ToastMessage\Model\Config\Source;

Expand Down
1 change: 1 addition & 0 deletions Model/Config/Source/TextAlignment.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Gg2\ToastMessage\Model\Config\Source;

Expand Down
1 change: 1 addition & 0 deletions Model/Config/Source/Transition.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Gg2\ToastMessage\Model\Config\Source;

Expand Down
51 changes: 51 additions & 0 deletions Observer/ClearMessages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);

namespace Gg2\ToastMessage\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Message\Session;
use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Framework\Stdlib\Cookie\FailureToSendException;

/**
* Class ClearMessages
* @package Gg2\ToastMessage\Observer
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class ClearMessages implements ObserverInterface
{
protected Session $session;
protected CookieManagerInterface $cookieManager;

/**
* ClearMessages constructor.
* @param Session $session
* @param CookieManagerInterface $cookieManager
*/
public function __construct(
Session $session,
CookieManagerInterface $cookieManager
)
{
$this->session = $session;
$this->cookieManager = $cookieManager;
}

/**
* @param Observer $observer
* @throws InputException
* @throws FailureToSendException
* @SuppressWarnings("unused")
*/
public function execute(Observer $observer)
{
$messages = $this->session->getData('default');
if ($messages && !empty($messages->getItems())) {
$messages->clear();
$this->cookieManager->deleteCookie('mage-messages');
}
}
}
34 changes: 34 additions & 0 deletions Plugin/AdditionalConfig/AdditionalConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);

namespace Gg2\ToastMessage\Plugin\AdditionalConfig;

use Gg2\ToastMessage\ViewModel\Settings;

class AdditionalConfigProvider
{
private Settings $settings;

/**
* AdditionalConfigProvider constructor.
* @param Settings $settings
*/
public function __construct(Settings $settings)
{
$this->settings = $settings;
}

/**
* @param \Magento\Checkout\Model\DefaultConfigProvider $subject
* @param $output
* @return array
* @SuppressWarnings("unused")
*/
public function afterGetConfig(
\Magento\Checkout\Model\DefaultConfigProvider $subject,
$output
): array {
$output['toastMessageSettings'] = $this->settings->getSettings();
return $output;
}
}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Requisitos
----------
---
- [Magento] Community 2.3+
- [PHP] 7.3+
- [PHP] 7.4+


Instalação
Expand Down Expand Up @@ -70,6 +70,10 @@ Changelog
1.1.4
- Ajuste boas praticas magento

1.1.5
- Ajuste boas praticas magento
- Ajuste menu de configuracoes no admin

Contribuições
-------------
---
Expand Down
4 changes: 2 additions & 2 deletions Test/Unit/Block/Adminhtml/System/Config/ColorPickerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ColorPickerTest extends TestCase
*
* @return void
*/
public function setUp(): void
protected function setUp() : void
{
$this->elementMock = $this->getMockBuilder(AbstractElement::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -74,6 +74,6 @@ public function testRender()

$expected = 'let $el = $("#' . $htmlId . '");';
$render = $this->object->render($this->elementMock);
$this->assertContains($expected, $render);
$this->assertStringContainsString($expected, $render);
}
}
2 changes: 1 addition & 1 deletion Test/Unit/Block/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MessageTest extends TestCase
*
* @return void
*/
public function setUp(): void
protected function setUp() : void
{
$context = $this->getMockBuilder(Context::class)
->disableOriginalConstructor()
Expand Down
2 changes: 1 addition & 1 deletion Test/Unit/Helper/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DataTest extends TestCase
*
* @return void
*/
public function setUp(): void
protected function setUp() : void
{
$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)
->setMethods(['getValue'])
Expand Down
52 changes: 0 additions & 52 deletions Test/Unit/Model/AdditionalConfigProviderTest.php

This file was deleted.

2 changes: 1 addition & 1 deletion Test/Unit/Model/Config/Source/IconTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class IconTest extends TestCase
*
* @return void
*/
public function setUp(): void
protected function setUp() : void
{
$this->object = new Icon();
}
Expand Down
2 changes: 1 addition & 1 deletion Test/Unit/Model/Config/Source/PositionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PositionTest extends TestCase
*
* @return void
*/
public function setUp(): void
protected function setUp() : void
{
$this->object = new Position();
}
Expand Down
2 changes: 1 addition & 1 deletion Test/Unit/Model/Config/Source/TextAlignmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TextAlignmentTest extends TestCase
*
* @return void
*/
public function setUp(): void
protected function setUp() : void
{
$this->object = new TextAlignment();
}
Expand Down
2 changes: 1 addition & 1 deletion Test/Unit/Model/Config/Source/TransitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TransitionTest extends TestCase
*
* @return void
*/
public function setUp(): void
protected function setUp() : void
{
$this->object = new Transition();
}
Expand Down
Loading

0 comments on commit 9bae924

Please sign in to comment.