Skip to content

Commit

Permalink
fix: replace global blade service (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbrink authored Feb 26, 2024
1 parent 04d02b4 commit 907103c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 38 deletions.
17 changes: 6 additions & 11 deletions Public.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
<?php

use HelsingborgStad\GlobalBladeService\GlobalBladeService;
use ComponentLibrary\Init;

if (!function_exists('modularity_products_render_blade_view')) {
function modularity_products_render_blade_view($view, $data = [], $compress = true)
{
$bladeEngine = GlobalBladeService::getInstance([
MODULARITY_PRODUCTS_MODULE_VIEW_PATH
]);
$componentLibrary = new Init([]);
$bladeEngine = $componentLibrary->getEngine();
$viewPath = MODULARITY_PRODUCTS_MODULE_VIEW_PATH;
$data = array_merge($data, array('errorMessage' => false));

try {
$markup = $bladeEngine->makeView(
$view,
array_merge(
$data,
array('errorMessage' => false)
)
)->render();
$markup = $bladeEngine->makeView($view, $data, [], $viewPath)->render();
} catch (\Throwable $e) {
$markup .= '<pre style="border: 3px solid #f00; padding: 10px;">';
$markup .= '<strong>' . $e->getMessage() . '</strong>';
Expand Down
6 changes: 0 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
],
"minimum-stability": "stable",
"require": {},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/helsingborg-stad/modularity-products.git"
}
],
"autoload": {
"psr-4": {
"ModularityProducts\\": "source/php/"
Expand Down
21 changes: 0 additions & 21 deletions source/php/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ public function __construct()

//Register module
add_action('plugins_loaded', array($this, 'registerModule'));

// Add view paths
add_filter('Municipio/blade/view_paths', array($this, 'addViewPaths'), 1, 1);
}

/**
Expand All @@ -32,22 +29,4 @@ public function registerModule()
);
}
}

/**
* Add searchable blade template paths
* @param array $array Template paths
* @return array Modified template paths
*/
public function addViewPaths($array)
{
// If child theme is active, insert plugin view path after child views path.
if (is_child_theme()) {
array_splice($array, 2, 0, array(MODULARITY_PRODUCTS_VIEW_PATH));
} else {
// Add view path first in the list if child theme is not active.
array_unshift($array, MODULARITY_PRODUCTS_VIEW_PATH);
}

return $array;
}
}

0 comments on commit 907103c

Please sign in to comment.