Skip to content

Commit

Permalink
PSR-2 refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon committed Jan 1, 2018
1 parent 6815c86 commit 6afe698
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 75 deletions.
16 changes: 6 additions & 10 deletions Block/Adminhtml/System/Config/Form/Composer/Version.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2017 MagePal LLC. All rights reserved.
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
*/

Expand Down Expand Up @@ -55,7 +55,6 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
return parent::render($element);
}


/**
* Return element html
*
Expand All @@ -68,13 +67,13 @@ protected function _getElementHtml(\Magento\Framework\Data\Form\Element\Abstract
return 'v' . $this->getVersion();
}


/**
* Get Module version number
*
* @return string
*/
public function getVersion(){
public function getVersion()
{
return $this->getComposerVersion($this->getModuleName());
}

Expand All @@ -101,21 +100,18 @@ public function getComposerVersion($moduleName)
$moduleName
);

try{
try {
$directoryRead = $this->readFactory->create($path);
$composerJsonData = $directoryRead->readFile('composer.json');

if($composerJsonData){
if ($composerJsonData) {
$data = json_decode($composerJsonData);
return !empty($data->version) ? $data->version : __('Unknown');
}

}
catch (\Exception $e){
} catch (\Exception $e) {
//
}

return 'Unknown';

}
}
7 changes: 3 additions & 4 deletions Block/Adminhtml/System/Config/Form/Module/Version.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2017 MagePal LLC. All rights reserved.
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
*/

Expand Down Expand Up @@ -41,7 +41,6 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
return parent::render($element);
}


/**
* Return element html
*
Expand All @@ -54,13 +53,13 @@ protected function _getElementHtml(\Magento\Framework\Data\Form\Element\Abstract
return 'v' . $this->getVersion();
}


/**
* Get Module version number
*
* @return string
*/
public function getVersion(){
public function getVersion()
{
$moduleInfo = $this->_moduleList->getOne($this->getModuleName());
return $moduleInfo['setup_version'];
}
Expand Down
39 changes: 22 additions & 17 deletions Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
<?php
/**
* Copyright © 2017 MagePal LLC. All rights reserved.
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
*/

namespace MagePal\FormFieldManager\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper {

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
const XML_PATH_ACTIVE = 'magepal_formfieldmanager/general/active';
const XML_CUSTOMER_ATTRIBUTE = 'magepal_formfieldmanager/general/customer_attribute';
const XML_CUSTOMER_ADDRESS_ATTRIBUTE = 'magepal_formfieldmanager/general/customer_address_attribute';

static $ignoreLazyLoad = 0;

public static $ignoreLazyLoad = 0;

/**
* If enabled
*
* @return bool
*/
public function isEnabled() {
public function isEnabled()
{
return $this->scopeConfig->isSetFlag(self::XML_PATH_ACTIVE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}

/**
* Check page type
* @return bool
*/
public function isCustomerEditAdminPage(){
public function isCustomerEditAdminPage()
{
return $this->_request->getFullActionName() === 'customer_index_edit';
}

/**
* Check page type
* @return bool
*/
public function isOrderCreationAdminPage(){
public function isOrderCreationAdminPage()
{
return $this->_request->getFullActionName() === 'sales_order_create_index'
|| $this->_request->getFullActionName() === 'sales_order_create_loadBlock';
}
Expand All @@ -45,23 +47,26 @@ public function isOrderCreationAdminPage(){
* Get list of customer attribute to disabled
* @return string|null
*/
public function getCustomerAttribute(){
public function getCustomerAttribute()
{
return $this->scopeConfig->getValue(self::XML_CUSTOMER_ATTRIBUTE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}

/**
* Get list of customer attribute to disabled
* @return string|null
*/
public function getCustomerAddressAttribute(){
public function getCustomerAddressAttribute()
{
return $this->scopeConfig->getValue(self::XML_CUSTOMER_ADDRESS_ATTRIBUTE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}

/**
* Get Array of customer attribute to disabled
* @return array
*/
public function getCustomerAttributeArray(){
public function getCustomerAttributeArray()
{
$list = $this->getCustomerAttribute();

return empty($list) ? [] : explode(',', $list);
Expand All @@ -71,7 +76,8 @@ public function getCustomerAttributeArray(){
* Get Array of customer attribute to disabled
* @return array
*/
public function getCustomerAddressAttributeArray(){
public function getCustomerAddressAttributeArray()
{
$list = $this->getCustomerAddressAttribute();

return empty($list) ? [] : explode(',', $list);
Expand All @@ -84,11 +90,12 @@ public function getCustomerAddressAttributeArray(){
* @param string $separator
* @return bool
*/
public function array_path_exists($array, $path, $separator = '/'){
public function array_path_exists($array, $path, $separator = '/')
{
$paths = explode($separator, $path);

foreach($paths as $sub){
if(!is_array($array) || !array_key_exists($sub, $array)){
foreach ($paths as $sub) {
if (!is_array($array) || !array_key_exists($sub, $array)) {
return false;
}

Expand All @@ -97,6 +104,4 @@ public function array_path_exists($array, $path, $separator = '/'){

return true;
}


}
11 changes: 4 additions & 7 deletions Model/Config/Source/AddressAttribute.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2017 MagePal LLC. All rights reserved.
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
*/
namespace MagePal\FormFieldManager\Model\Config\Source;
Expand All @@ -19,12 +19,10 @@ class AddressAttribute implements \Magento\Framework\Option\ArrayInterface

public function __construct(
\Magento\Customer\Model\Metadata\FormFactory $customerFormFactory
){
) {
$this->_customerFormFactory = $customerFormFactory;

}


/**
* @return array
*/
Expand All @@ -40,11 +38,10 @@ public function toOptionArray()

$ignoreList = ['created_at', 'created_in', 'disable_auto_group_change', 'region', 'region_id', 'postcode'];

foreach($attributes as $attribute){
if(!$attribute->isRequired() && !in_array($attribute->getAttributeCode(), $ignoreList)){
foreach ($attributes as $attribute) {
if (!$attribute->isRequired() && !in_array($attribute->getAttributeCode(), $ignoreList)) {
$fields[] = ['value' => $attribute->getAttributeCode(), 'label' => $attribute->getStoreLabel()];
}

}

return $fields;
Expand Down
11 changes: 4 additions & 7 deletions Model/Config/Source/CustomerAttribute.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2017 MagePal LLC. All rights reserved.
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
*/
namespace MagePal\FormFieldManager\Model\Config\Source;
Expand All @@ -19,12 +19,10 @@ class CustomerAttribute implements \Magento\Framework\Option\ArrayInterface

public function __construct(
\Magento\Customer\Model\Metadata\FormFactory $customerFormFactory
){
) {
$this->_customerFormFactory = $customerFormFactory;

}


/**
* @return array
*/
Expand All @@ -40,11 +38,10 @@ public function toOptionArray()

$ignoreList = ['created_at', 'created_in', 'disable_auto_group_change'];

foreach($attributes as $attribute){
if(!$attribute->isRequired() && !in_array($attribute->getAttributeCode(), $ignoreList)){
foreach ($attributes as $attribute) {
if (!$attribute->isRequired() && !in_array($attribute->getAttributeCode(), $ignoreList)) {
$fields[] = ['value' => $attribute->getAttributeCode(), 'label' => $attribute->getStoreLabel()];
}

}

return $fields;
Expand Down
25 changes: 10 additions & 15 deletions Plugin/Component/AbstractComponentPlugin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2017 MagePal LLC. All rights reserved.
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
*/
namespace MagePal\FormFieldManager\Plugin\Component;
Expand All @@ -11,7 +11,6 @@ class AbstractComponentPlugin
/* @var \MagePal\FormFieldManager\Helper\Data */
private $_dataHelper;


/**
* DataProviderPlugin constructor.
*/
Expand All @@ -29,35 +28,31 @@ public function __construct(
*/
public function afterGetChildComponents(\Magento\Ui\Component\AbstractComponent $subject, $result)
{

if($this->_dataHelper->isCustomerEditAdminPage() && $this->_dataHelper->isEnabled()){
if($subject->getName() == 'customer'){
if ($this->_dataHelper->isCustomerEditAdminPage() && $this->_dataHelper->isEnabled()) {
if ($subject->getName() == 'customer') {
$this->hideFields($result, $this->_dataHelper->getCustomerAttributeArray());
}
else if($subject->getName() == 'address'){
} elseif ($subject->getName() == 'address') {
$this->hideFields($result, $this->_dataHelper->getCustomerAddressAttributeArray());
}
}


return $result;
}

/**
* @param $result
* @param $fields
*/
private function hideFields(&$result, $fields){
if(is_array($result)){
foreach($fields as $field){
if(array_key_exists($field, $result)){

private function hideFields(&$result, $fields)
{
if (is_array($result)) {
foreach ($fields as $field) {
if (array_key_exists($field, $result)) {
$temp = $result[$field]->getConfig();
$temp['visible'] = false;
$result[$field]->setConfig($temp);
}
}

}
}
}
}
9 changes: 4 additions & 5 deletions Plugin/Model/Customer/DataProviderPlugin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2017 MagePal LLC. All rights reserved.
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
*/

Expand All @@ -26,7 +26,6 @@ public function __construct(
$this->timezone = $timezone;
}


/**
* @param \Magento\Customer\Model\Customer\DataProvider $subject
* @param $result
Expand All @@ -35,14 +34,14 @@ public function __construct(
public function afterGetData(\Magento\Customer\Model\Customer\DataProvider $subject, $result)
{
//check if dob is hidden and need to change the date format
if($this->_dataHelper->isCustomerEditAdminPage() && $this->_dataHelper->isEnabled()) {
if ($this->_dataHelper->isCustomerEditAdminPage() && $this->_dataHelper->isEnabled()) {
if (is_array($result) && in_array('dob', $this->_dataHelper->getCustomerAttributeArray())) {
if ($this->_dataHelper->array_path_exists($result, '1/customer/dob')) {
$result[1]['customer']['dob'] = $this->timezone->date($result[1]['customer']['dob'])->format('m/d/Y');
}
}
}

return $result;
return $result;
}
}
}
Loading

0 comments on commit 6afe698

Please sign in to comment.