Skip to content

Commit

Permalink
Merge pull request #10 from openclassify/vedat
Browse files Browse the repository at this point in the history
added addons params
  • Loading branch information
Muammer Top authored Jun 22, 2021
2 parents b845275 + 818655f commit 8e2bc15
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/AddblockExtensionPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public function getFunctions()
return [
new \Twig_SimpleFunction(
'addBlock',
function ($location, $params = []) {
function ($location, $params = [], $addons = []) {

if (!$addBlock = $this->dispatch(new addBlock($location, $params))) {
if (!$addBlock = $this->dispatch(new addBlock($location, $params, $addons))) {
return null;
}

Expand Down
51 changes: 33 additions & 18 deletions src/Command/addBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ class addBlock
* @param $location
* @param $params
*/
public function __construct($location, $params)
public function __construct($location, $params, $addons)
{
$this->location = $location;
$this->params = $params;
$this->addons = $addons;
}

public function handle()
Expand All @@ -31,23 +32,12 @@ public function handle()
$views = array();
$params = $this->params;
foreach ($installed_modules as $item) {
if (file_exists($item->path . "/resources/views/" . $this->location . ".twig")) {
$views[] = [
'order' => 10,
'view' => view($item->namespace . '::' . $this->location, compact('params'))
];
} elseif (count(glob($item->path . "/resources/views/" . $this->location . "_*.twig"))) {
$order = glob($item->path . "/resources/views/" . $this->location . "_*.twig")[0];
$location = str_replace('/', '\/', $this->location);
preg_match('/' . $location . '_(.*?)\.twig/', $order, $match);
$order = $match[1];
$views[] = [
'order' => $order,
'view' => view(
$item->namespace . '::' . $this->location . '_' . $order,
compact('params')
)
];
if (count($this->addons)) {
if (in_array($item->slug, $this->addons)) {
$views = $this->execute($item, $params, $views);
}
} else {
$views = $this->execute($item, $params, $views);
}
}

Expand All @@ -56,4 +46,29 @@ public function handle()

return implode('', array_column($views, 'view'));
}

public function execute($item, $params, $views)
{
if (file_exists($item->path . "/resources/views/" . $this->location . ".twig")) {
$views[] = [
'order' => 10,
'view' => view($item->namespace . '::' . $this->location, compact('params'))
];

} elseif (count(glob($item->path . "/resources/views/" . $this->location . "_*.twig"))) {
$order = glob($item->path . "/resources/views/" . $this->location . "_*.twig")[0];
$location = str_replace('/', '\/', $this->location);
preg_match('/' . $location . '_(.*?)\.twig/', $order, $match);
$order = $match[1];
$views[] = [
'order' => $order,
'view' => view(
$item->namespace . '::' . $this->location . '_' . $order,
compact('params')
)
];
}

return $views;
}
}

0 comments on commit 8e2bc15

Please sign in to comment.