Create a blade directive to use @editor

parent 1dfdda96
<?php
namespace Modules\Core\Blade;
class AsgardEditorDirective
{
private $content;
private $lang;
private $fieldName;
private $labelName;
public function show($arguments)
{
$this->extractArguments($arguments);
if ($this->lang !== null) {
return asgard_i18n_editor($this->fieldName, $this->labelName, $this->content, $this->lang);
}
}
/**
* Extract the possible arguments as class properties
* @param array $arguments
*/
private function extractArguments(array $arguments)
{
$this->fieldName = array_get($arguments, 0);
$this->labelName = array_get($arguments, 1);
$this->content = array_get($arguments, 2);
$this->lang = array_get($arguments, 3);
}
}
<?php
namespace Modules\Core\Blade\Facades;
use Illuminate\Support\Facades\Facade;
class AsgardEditorDirective extends Facade
{
protected static function getFacadeAccessor()
{
return 'core.asgard.editor';
}
}
......@@ -7,6 +7,7 @@ use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Blade\AsgardEditorDirective;
use Modules\Core\Console\DeleteModuleCommand;
use Modules\Core\Console\DownloadModuleCommand;
use Modules\Core\Console\InstallCommand;
......@@ -74,6 +75,10 @@ class CoreServiceProvider extends ServiceProvider
$this->registerCommands();
$this->registerServices();
$this->setLocalesConfigurations();
$this->app->bind('core.asgard.editor', function () {
return new AsgardEditorDirective();
});
}
/**
......@@ -307,6 +312,10 @@ class CoreServiceProvider extends ServiceProvider
*/
public function bladeDirectives()
{
if (app()->environment() === 'testing') {
return;
}
/**
* Set variable.
* Usage: @set($variable, value)
......@@ -316,6 +325,10 @@ class CoreServiceProvider extends ServiceProvider
return "<?php {$variable} = {$value}; ?>";
});
$this->app['blade.compiler']->directive('editor', function ($value) {
return "<?php echo AsgardEditorDirective::show([$value]); ?>";
});
}
/**
......
......@@ -20,7 +20,8 @@
"aliases": {
"Form": "Collective\\Html\\FormFacade",
"Flash": "Laracasts\\Flash\\Flash",
"LaravelLocalization": "Mcamara\\LaravelLocalization\\Facades\\LaravelLocalization"
"LaravelLocalization": "Mcamara\\LaravelLocalization\\Facades\\LaravelLocalization",
"AsgardEditorDirective": "Modules\\Core\\Blade\\Facades\\AsgardEditorDirective"
},
"files": [
"start.php",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment