Skip to content

Commit

Permalink
fix: replace global blade service (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbrink authored Feb 26, 2024
1 parent b5b581b commit 7c451f8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 39 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 as ComponentLibraryInit;

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

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
8 changes: 1 addition & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@
],
"minimum-stability": "stable",
"require": {},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/helsingborg-stad/modularity-timeline.git"
}
],
"autoload": {
"psr-4": {
"ModularityTimeline\\": "source/php/"
}
},
"version": "4.0.0"
}
}
21 changes: 0 additions & 21 deletions source/php/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,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 @@ -28,22 +25,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_TIMELINE_VIEW_PATH));
} else {
// Add view path first in the list if child theme is not active.
array_unshift($array, MODULARITY_TIMELINE_VIEW_PATH);
}

return $array;
}
}

0 comments on commit 7c451f8

Please sign in to comment.