Skip to content

Commit

Permalink
Merge pull request #42 from jbclaudio/feature/php-8.2-compatibility
Browse files Browse the repository at this point in the history
Install and run Rector + PHP 8.2 compatibility + Refactor
  • Loading branch information
jbclaudio authored Mar 14, 2024
2 parents 93b000b + cbfe024 commit cc12e04
Show file tree
Hide file tree
Showing 49 changed files with 558 additions and 939 deletions.
30 changes: 10 additions & 20 deletions Block/Adminhtml/Akeneo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace JustBetter\AkeneoBundle\Block\Adminhtml;

use JustBetter\AkeneoBundle\Block\Adminhtml\Akeneo\Grid;
use Magento\Backend\Block\Widget\Button\SplitButton;
use Magento\Backend\Block\Widget\Container;
use Magento\Backend\Block\Widget\Context;

class Akeneo extends \Magento\Backend\Block\Widget\Container
class Akeneo extends Container
{
/**
* @var string
Expand All @@ -23,32 +26,27 @@ public function __construct(Context $context, array $data = [])
/**
* Prepare button and grid
*/
protected function _prepareLayout()
protected function _prepareLayout(): Akeneo
{
$addButtonProps = [
'id' => 'add_new',
'label' => __('Add New'),
'class' => 'add',
'button_class' => '',
'class_name' => 'Magento\Backend\Block\Widget\Button\SplitButton',
'class_name' => SplitButton::class,
'options' => $this->_getAddButtonOptions(),
];
$this->buttonList->add('add_new', $addButtonProps);


$this->setChild(
'grid',
$this->getLayout()->createBlock('JustBetter\AkeneoBundle\Block\Adminhtml\Akeneo\Grid', 'justbetter.akeneo.grid')
$this->getLayout()->createBlock(Grid::class, 'justbetter.akeneo.grid')
);
return parent::_prepareLayout();
}

/**
*
*
* @return array
*/
protected function _getAddButtonOptions()
protected function _getAddButtonOptions(): array
{
$splitButtonOptions[] = [
'label' => __('Add New'),
Expand All @@ -58,22 +56,14 @@ protected function _getAddButtonOptions()
return $splitButtonOptions;
}

/**
* @return string
*/
protected function _getCreateUrl()
protected function _getCreateUrl(): string
{
return $this->getUrl(
'akeneomanager/*/new'
);
}

/**
* Render grid
*
* @return string
*/
public function getGridHtml()
public function getGridHtml(): string
{
return $this->getChildHtml('grid');
}
Expand Down
46 changes: 13 additions & 33 deletions Block/Adminhtml/Akeneo/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,26 @@

namespace JustBetter\AkeneoBundle\Block\Adminhtml\Akeneo;

use Magento\Framework\Registry;
use Magento\Backend\Block\Widget\Context;
use Magento\Backend\Block\Widget\Form\Container;
use Magento\Framework\Phrase;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\AbstractBlock;

class Edit extends \Magento\Backend\Block\Widget\Form\Container
class Edit extends Container
{
/**
* Core registry
*
* @var Registry
*/
protected $_coreRegistry = null;

/**
* @param Context $context
* @param Registry $registry
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
protected Registry $coreRegistry,
array $data = []
) {
$this->_coreRegistry = $registry;
parent::__construct($context, $data);
}

/**
* Initialize akeneo edit block
*
* @return void
*/
protected function _construct()
protected function _construct(): void
{
$this->_objectId = 'id';
$this->_blockGroup = 'JustBetter_AkeneoBundle';
Expand Down Expand Up @@ -61,13 +49,11 @@ protected function _construct()

/**
* Retrieve text for header element depending on loaded post
*
* @return \Magento\Framework\Phrase
*/
public function getHeaderText()
public function getHeaderText(): Phrase
{
if ($this->_coreRegistry->registry('akeneo')->getId()) {
return __("Edit Akeneo '%1'", $this->escapeHtml($this->_coreRegistry->registry('akeneo')->getTitle()));
if ($this->coreRegistry->registry('akeneo')->getId()) {
return __("Edit Akeneo '%1'", $this->escapeHtml($this->coreRegistry->registry('akeneo')->getTitle()));
} else {
return __('New Akeneo');
}
Expand All @@ -76,20 +62,13 @@ public function getHeaderText()
/**
* Getter of url for "Save and Continue" button
* tab_id will be replaced by desired by JS later
*
* @return string
*/
protected function _getSaveAndContinueUrl()
protected function _getSaveAndContinueUrl(): string
{
return $this->getUrl('akeneomanager/*/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '{{tab_id}}']);
}

/**
* Prepare layout
*
* @return \Magento\Framework\View\Element\AbstractBlock
*/
protected function _prepareLayout()
protected function _prepareLayout(): AbstractBlock
{
$this->_formScripts[] = "
function toggleEditor() {
Expand All @@ -100,6 +79,7 @@ function toggleEditor() {
}
};
";

return parent::_prepareLayout();
}
}
34 changes: 6 additions & 28 deletions Block/Adminhtml/Akeneo/Edit/Tab/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace JustBetter\AkeneoBundle\Block\Adminhtml\Akeneo\Edit\Tab;

use IntlDateFormatter;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;
use Magento\Store\Model\System\Store;
use Magento\Framework\Data\FormFactory;
Expand All @@ -16,34 +17,14 @@
*/
class Main extends Generic implements TabInterface
{
/**
* @var Store
*/
protected $_systemStore;

/**
* @var Status
*/
protected $_status;

/**
* @param Context $context
* @param Registry $registry
* @param FormFactory $formFactory
* @param Store $systemStore
* @param Status $status
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
FormFactory $formFactory,
Store $systemStore,
Status $status,
protected Store $systemStore,
protected Status $status,
array $data = []
) {
$this->_systemStore = $systemStore;
$this->_status = $status;
parent::__construct($context, $registry, $formFactory, $data);
}

Expand All @@ -52,14 +33,14 @@ public function __construct(
*
* @return $this
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @throws LocalizedException
*/
protected function _prepareForm()
protected function _prepareForm(): static
{
$model = $this->_coreRegistry->registry('akeneo');

$isElementDisabled = false;

/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create();

$form->setHtmlIdPrefix('page_');
Expand Down Expand Up @@ -187,9 +168,6 @@ protected function _isAllowedAction($resourceId)

public function getTargetOptionArray()
{
return array(
'_self' => "Self",
'_blank' => "New Page",
);
return ['_self' => 'Self', '_blank' => 'New Page'];
}
}
Loading

0 comments on commit cc12e04

Please sign in to comment.