Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
haitv282 committed Oct 13, 2020
1 parent ab62815 commit e54bf3e
Show file tree
Hide file tree
Showing 43 changed files with 758 additions and 755 deletions.
6 changes: 3 additions & 3 deletions Block/Adminhtml/Hook/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ protected function _construct()
parent::_construct();

$this->buttonList->add('save-and-continue', [
'label' => __('Save and Continue Edit'),
'class' => 'save',
'label' => __('Save and Continue Edit'),
'class' => 'save',
'data_attribute' => [
'mage-init' => [
'button' => [
'event' => 'saveAndContinueEdit',
'event' => 'saveAndContinueEdit',
'target' => '#edit_form'
]
]
Expand Down
6 changes: 3 additions & 3 deletions Block/Adminhtml/Hook/Edit/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ protected function _prepareForm()
$form = $this->_formFactory->create(
[
'data' => [
'id' => 'edit_form',
'action' => $this->getData('action'),
'method' => 'post',
'id' => 'edit_form',
'action' => $this->getData('action'),
'method' => 'post',
'enctype' => 'multipart/form-data'
]
]
Expand Down
82 changes: 41 additions & 41 deletions Block/Adminhtml/Hook/Edit/Tab/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public function __construct(
Authentication $authentication,
array $data = []
) {
$this->fieldFactory = $fieldFactory;
$this->method = $method;
$this->contentType = $contentType;
$this->fieldFactory = $fieldFactory;
$this->method = $method;
$this->contentType = $contentType;
$this->authentication = $authentication;

parent::__construct($context, $registry, $formFactory, $data);
Expand All @@ -111,104 +111,104 @@ protected function _prepareForm()

$fieldset = $form->addFieldset('actions_fieldset', [
'legend' => __('Actions'),
'class' => 'fieldset-wide'
'class' => 'fieldset-wide'
]);
$fieldset->addField('payload_url', 'text', [
'name' => 'payload_url',
'label' => __('Payload URL'),
'title' => __('Payload URL'),
'required' => true,
'note' => __('You can insert a variable'),
'name' => 'payload_url',
'label' => __('Payload URL'),
'title' => __('Payload URL'),
'required' => true,
'note' => __('You can insert a variable'),
'after_element_html' => '<a id="insert-variable-upload" class="btn">' . __('Insert Variable') . '</a>',
]);
$fieldset->addField('method', 'select', [
'name' => 'method',
'label' => __('Method'),
'title' => __('Method'),
'name' => 'method',
'label' => __('Method'),
'title' => __('Method'),
'values' => $this->method->toOptionArray(),
]);

$authentication = $fieldset->addField('authentication', 'select', [
'name' => 'authentication',
'label' => __('Authentication'),
'title' => __('Authentication'),
'name' => 'authentication',
'label' => __('Authentication'),
'title' => __('Authentication'),
'values' => $this->authentication->toOptionArray(),

]);
$username = $fieldset->addField('username', 'text', [
'name' => 'username',
$username = $fieldset->addField('username', 'text', [
'name' => 'username',
'label' => __('Username'),
'title' => __('Username'),
]);
$realm = $fieldset->addField('realm', 'text', [
'name' => 'realm',
$realm = $fieldset->addField('realm', 'text', [
'name' => 'realm',
'label' => __('Realm'),
'title' => __('Realm'),
]);
$password = $fieldset->addField('password', 'password', [
'name' => 'password',
$password = $fieldset->addField('password', 'password', [
'name' => 'password',
'label' => __('Password'),
'title' => __('Password'),
]);
$nonce = $fieldset->addField('nonce', 'text', [
'name' => 'nonce',
$nonce = $fieldset->addField('nonce', 'text', [
'name' => 'nonce',
'label' => __('Nonce'),
'title' => __('Nonce'),
]);
$algorithm = $fieldset->addField('algorithm', 'text', [
'name' => 'algorithm',
$algorithm = $fieldset->addField('algorithm', 'text', [
'name' => 'algorithm',
'label' => __('Algorithm'),
'title' => __('Algorithm'),
]);
$qop = $fieldset->addField('qop', 'text', [
'name' => 'qop',
$qop = $fieldset->addField('qop', 'text', [
'name' => 'qop',
'label' => __('qop'),
'title' => __('qop'),
]);
$nonceCount = $fieldset->addField('nonce_count', 'text', [
'name' => 'nonce_count',
$nonceCount = $fieldset->addField('nonce_count', 'text', [
'name' => 'nonce_count',
'label' => __('Nonce Count'),
'title' => __('Nonce Count'),
]);
$clientNonce = $fieldset->addField('client_nonce', 'text', [
'name' => 'client_nonce',
$clientNonce = $fieldset->addField('client_nonce', 'text', [
'name' => 'client_nonce',
'label' => __('Client Nonce'),
'title' => __('Client Nonce'),
]);
$opaque = $fieldset->addField('opaque', 'text', [
'name' => 'opaque',
$opaque = $fieldset->addField('opaque', 'text', [
'name' => 'opaque',
'label' => __('Opaque'),
'title' => __('Opaque'),
]);
/** @var RendererInterface $rendererBlock */
$rendererBlock = $this->getLayout()
->createBlock(Headers::class);
$fieldset->addField('headers', 'text', [
'name' => 'headers',
'name' => 'headers',
'label' => __('Header'),
'title' => __('Header'),
])->setRenderer($rendererBlock);
$fieldset->addField('content_type', 'select', [
'name' => 'content_type',
'label' => __('Content Type'),
'title' => __('Content Type'),
'name' => 'content_type',
'label' => __('Content Type'),
'title' => __('Content Type'),
'values' => $this->contentType->toOptionArray(),

]);
/** @var RendererInterface $rendererBlock */
$rendererBlock = $this->getLayout()->createBlock(Body::class);
$fieldset->addField('body', 'textarea', [
'name' => 'body',
'name' => 'body',
'label' => __('Body'),
'title' => __('Body'),
'note' => __(
'note' => __(
'Supports <a href="%1" target="_blank">Liquid template</a>',
'https://shopify.github.io/liquid/'
)
])->setRenderer($rendererBlock);

$refField = $this->fieldFactory->create([
'fieldData' => ['value' => 'basic,digest', 'separator' => ','],
'fieldData' => ['value' => 'basic,digest', 'separator' => ','],
'fieldPrefix' => ''
]);

Expand Down Expand Up @@ -289,7 +289,7 @@ public function isHidden()
*/
public function getFormHtml()
{
$formHtml = parent::getFormHtml();
$formHtml = parent::getFormHtml();
$childHtml = $this->getChildHtml();

return $formHtml . $childHtml;
Expand Down
34 changes: 17 additions & 17 deletions Block/Adminhtml/Hook/Edit/Tab/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public function __construct(
array $data = []
) {
$this->enabledisable = $enableDisable;
$this->systemStore = $systemStore;
$this->orderStatus = $orderStatus;
$this->systemStore = $systemStore;
$this->orderStatus = $orderStatus;

parent::__construct($context, $registry, $formFactory, $data);
}
Expand All @@ -98,23 +98,23 @@ protected function _prepareForm()

$fieldset = $form->addFieldset('base_fieldset', [
'legend' => __('General Information'),
'class' => 'fieldset-wide'
'class' => 'fieldset-wide'
]);

$fieldset->addField('name', 'text', [
'name' => 'name',
'label' => __('Name'),
'title' => __('Name'),
'name' => 'name',
'label' => __('Name'),
'title' => __('Name'),
'required' => true
]);
$fieldset->addField('hook_type', 'hidden', [
'name' => 'hook_type',
'name' => 'hook_type',
'value' => $this->_request->getParam('type') ?: HookType::ORDER
]);
$fieldset->addField('status', 'select', [
'name' => 'status',
'label' => __('Status'),
'title' => __('Status'),
'name' => 'status',
'label' => __('Status'),
'title' => __('Status'),
'values' => $this->enabledisable->toOptionArray()
]);

Expand All @@ -131,24 +131,24 @@ protected function _prepareForm()
/** @var RendererInterface $rendererBlock */
$rendererBlock = $this->getLayout()->createBlock(Element::class);
$fieldset->addField('store_ids', 'multiselect', [
'name' => 'store_ids',
'label' => __('Store Views'),
'title' => __('Store Views'),
'name' => 'store_ids',
'label' => __('Store Views'),
'title' => __('Store Views'),
'required' => true,
'values' => $this->systemStore->getStoreValuesForForm(false, true)
'values' => $this->systemStore->getStoreValuesForForm(false, true)
])->setRenderer($rendererBlock);
} else {
$fieldset->addField('store_ids', 'hidden', [
'name' => 'store_ids',
'name' => 'store_ids',
'value' => $this->_storeManager->getStore()->getId()
]);
}

$fieldset->addField('priority', 'text', [
'name' => 'priority',
'name' => 'priority',
'label' => __('Priority'),
'title' => __('Priority'),
'note' => __('0 is highest')
'note' => __('0 is highest')
]);

$form->addValues($hook->getData());
Expand Down
38 changes: 19 additions & 19 deletions Block/Adminhtml/Hook/Edit/Tab/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function __construct(
Status $status,
array $data = []
) {
$this->_status = $status;
$this->coreRegistry = $coreRegistry;
$this->_status = $status;
$this->coreRegistry = $coreRegistry;
$this->historyCollectionFactory = $historyCollectionFactory;

parent::__construct($context, $backendHelper, $data);
Expand All @@ -96,7 +96,7 @@ public function _construct()
*/
protected function _prepareCollection()
{
$hook = $this->getHook();
$hook = $this->getHook();
$collection = $this->historyCollectionFactory->create();
$collection = $collection->addFieldToFilter('hook_id', $hook->getId());
$this->setCollection($collection);
Expand All @@ -111,37 +111,37 @@ protected function _prepareCollection()
protected function _prepareColumns()
{
$this->addColumn('id', [
'header' => __('ID'),
'sortable' => true,
'index' => 'id',
'type' => 'number',
'header' => __('ID'),
'sortable' => true,
'index' => 'id',
'type' => 'number',
'header_css_class' => 'col-id',
'column_css_class' => 'col-id'
]);
$this->addColumn('hook_name', [
'header' => __('Hook Name'),
'name' => 'hook_name',
'index' => 'hook_name'
'name' => 'hook_name',
'index' => 'hook_name'
]);
$this->addColumn('status', [
'header' => __('Status'),
'name' => 'status',
'index' => 'status',
'type' => 'options',
'sortable' => false,
'options' => $this->_status->toArray(),
'header' => __('Status'),
'name' => 'status',
'index' => 'status',
'type' => 'options',
'sortable' => false,
'options' => $this->_status->toArray(),
'header_css_class' => 'col-status',
'column_css_class' => 'col-status'
]);
$this->addColumn('hook_type', [
'header' => __('Entity'),
'name' => 'hook_type',
'index' => 'hook_type'
'name' => 'hook_type',
'index' => 'hook_type'
]);
$this->addColumn('message', [
'header' => __('Message'),
'name' => 'message',
'index' => 'message'
'name' => 'message',
'index' => 'message'
]);

return $this;
Expand Down
28 changes: 14 additions & 14 deletions Block/Adminhtml/Hook/Edit/Tab/Renderer/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,18 @@ public function __construct(
Subscriber $subscriber,
array $data = []
) {
$this->liquidFilters = $liquidFilters;
$this->orderFactory = $orderFactory;
$this->invoiceResource = $invoiceResource;
$this->shipmentResource = $shipmentResource;
$this->creditmemoResource = $creditmemoResource;
$this->hookFactory = $hookFactory;
$this->liquidFilters = $liquidFilters;
$this->orderFactory = $orderFactory;
$this->invoiceResource = $invoiceResource;
$this->shipmentResource = $shipmentResource;
$this->creditmemoResource = $creditmemoResource;
$this->hookFactory = $hookFactory;
$this->orderStatusResource = $orderStatusResource;
$this->customerResource = $customerResource;
$this->customerResource = $customerResource;
$this->catalogEavAttribute = $catalogEavAttribute;
$this->categoryFactory = $categoryFactory;
$this->quoteResource = $quoteResource;
$this->subscriber = $subscriber;
$this->categoryFactory = $categoryFactory;
$this->quoteResource = $quoteResource;
$this->subscriber = $subscriber;

parent::__construct($context, $data);
}
Expand All @@ -183,8 +183,8 @@ public function getHookType()
$type = $this->_request->getParam('type');
if (!$type) {
$hookId = $this->getRequest()->getParam('hook_id');
$hook = $this->hookFactory->create()->load($hookId);
$type = $hook->getHookType();
$hook = $this->hookFactory->create()->load($hookId);
$type = $hook->getHookType();
}
if (!$type) {
$type = 'order';
Expand Down Expand Up @@ -272,7 +272,7 @@ protected function getAttrCollectionFromDb($collection)
$attrCollection = [];
foreach ($collection as $item) {
$attrCollection[] = new DataObject([
'name' => $item['COLUMN_NAME'],
'name' => $item['COLUMN_NAME'],
'title' => ucwords(str_replace('_', ' ', $item['COLUMN_NAME']))
]);
}
Expand All @@ -290,7 +290,7 @@ protected function getAttrCollectionFromEav($collection)
$attrCollection = [];
foreach ($collection as $item) {
$attrCollection[] = new DataObject([
'name' => $item->getAttributeCode(),
'name' => $item->getAttributeCode(),
'title' => $item->getDefaultFrontendLabel()
]);
}
Expand Down
Loading

0 comments on commit e54bf3e

Please sign in to comment.