Skip to content

Commit

Permalink
Issues #4 - Code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon committed Aug 29, 2018
1 parent 438eab3 commit bc28df7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 32 deletions.
89 changes: 58 additions & 31 deletions Model/Config/Source/Sections.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
*/
*/

namespace MagePal\CustomerAccountLinksManager\Model\Config\Source;

Expand All @@ -14,6 +14,8 @@ class Sections implements \Magento\Framework\Option\ArrayInterface

protected $links;

protected $list = [];

public function __construct(
\Magento\Framework\App\Utility\Files $utilityFiles,
\Magento\Framework\View\Element\Html\Links $links
Expand All @@ -36,47 +38,72 @@ public function getSections()
{
$fileList = $this->utilityFiles->getLayoutFiles(['area_name' => 'frontend'], false);

$list = [];

foreach ($fileList as $configFile) {
if (strpos($configFile, 'customer_account.xml') !== false) {
$configXml = simplexml_load_file($configFile);
$this->processXmlElement($configXml);
}
}

return $this->list;
}

if ($referenceBlocks = $configXml->body->referenceBlock) {
foreach ($referenceBlocks as $referenceBlock) {
if (!empty($referenceBlock->xpath('block/arguments/argument[@name="label"]'))) {
$list[(string) $referenceBlock->block['name']] = [
'value' => (string) $referenceBlock->block['name'],
'label' => (string) $referenceBlock->xpath('block/arguments/argument[@name="label"]')[0]
];
}
/**
* @param $configXml
*/
protected function processXmlElement($configXml)
{
if ($referenceBlocks = $configXml->body->referenceBlock) {
foreach ($referenceBlocks as $referenceBlock) {
if (!empty($referenceBlock->xpath('block/arguments/argument[@name="label"]'))) {
$this->updateReferenceBlockList($referenceBlock);
}
}
}

if (isset($configXml->body->referenceContainer) && isset($configXml->body->referenceContainer->block)) {
if (isset($configXml->body->referenceContainer->block->block)
&& isset($configXml->body->referenceContainer->block->block->block)
) {
$referenceContainerBlocks = $configXml->body->referenceContainer->block->block->block;

for ($count = 0; $count < count($referenceContainerBlocks); $count++) {
if (!empty($referenceContainerBlocks[$count]->xpath('arguments/argument[@name="label"]'))) {
$this->updateReferenceContainerList($referenceContainerBlocks, $count);
}
}
} elseif (isset($configXml->body->referenceContainer->block->block)) {
$referenceContainerBlocks = $configXml->body->referenceContainer->block->block;

if (isset($configXml->body->referenceContainer)) {
if ($referenceContainerBlocks = $configXml->body->referenceContainer->block->block->block) {
for ($count = 0; $count < count($referenceContainerBlocks); $count++) {
if (!empty($referenceContainerBlocks[$count]->xpath('arguments/argument[@name="label"]'))) {
$list[(string) $referenceContainerBlocks[$count]['name']] = [
'value' => (string) $referenceContainerBlocks[$count]['name'],
'label' => (string) $referenceContainerBlocks[$count]->xpath('arguments/argument[@name="label"]')[0]
];
}
}
} elseif ($referenceContainerBlocks = $configXml->body->referenceContainer->block->block) {
for ($count = 0; $count < count($referenceContainerBlocks); $count++) {
if (!empty($referenceContainerBlocks[$count]->xpath('arguments/argument[@name="label"]'))) {
$list[(string) $referenceContainerBlocks[$count]['name']] = [
'value' => (string) $referenceContainerBlocks[$count]['name'],
'label' => (string) $referenceContainerBlocks[$count]->xpath('arguments/argument[@name="label"]')[0]
];
}
}
for ($count = 0; $count < count($referenceContainerBlocks); $count++) {
if (!empty($referenceContainerBlocks[$count]->xpath('arguments/argument[@name="label"]'))) {
$this->updateReferenceContainerList($referenceContainerBlocks, $count);
}
}
}
}
}

return $list;
/**
* @param $rcb
* @param $count
*/
protected function updateReferenceContainerList($rcb, $count)
{
$this->list[(string) $rcb[$count]['name']] = [
'value' => (string) $rcb[$count]['name'],
'label' => (string) $rcb[$count]->xpath('arguments/argument[@name="label"]')[0]
];
}

/**
* @param $rb
*/
protected function updateReferenceBlockList($rb)
{
$this->list[(string) $rb->block['name']] = [
'value' => (string) $rb->block['name'],
'label' => (string) $rb->xpath('block/arguments/argument[@name="label"]')[0]
];
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"magento/framework": "100.0.*|100.1.*|101.0.*"
},
"type": "magento2-module",
"version": "1.1.4",
"version": "1.1.5",
"autoload": {
"files": [
"registration.php"
Expand Down

0 comments on commit bc28df7

Please sign in to comment.