Skip to content

Commit 183c933

Browse files
authored
Load error and help_block from package namespace instead of hardcoded path (#608)
* load error and help_block from package namespace * Added getFormBuilderViewPath function with *.php file restriction
1 parent ceb6942 commit 183c933

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/helpers.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,26 @@
33
use Kris\LaravelFormBuilder\Fields\FormField;
44
use Kris\LaravelFormBuilder\Form;
55

6+
if(!function_exists('getFormBuilderViewPath'))
7+
{
8+
function getFormBuilderViewPath($fileName)
9+
{
10+
$p = explode('.',$fileName);
11+
$c = count($p);
12+
if($c>2 || $p[$c-1]!='php')
13+
throw new Exception('You should use only *.php files with this function');
14+
15+
$path = base_path('resources/views/vendor/laravel-form-builder/'.$fileName);
16+
return file_exists($path) ? $path : __DIR__.'/views/'.$fileName;
17+
}
18+
}
619

720
if(!function_exists('errorBlockPath'))
821
{
922

1023
function errorBlockPath()
1124
{
12-
return __DIR__.'/views/errors.php';
25+
return getFormBuilderViewPath('errors.php');
1326
}
1427

1528
}
@@ -19,7 +32,7 @@ function errorBlockPath()
1932

2033
function helpBlockPath()
2134
{
22-
return __DIR__.'/views/help_block.php';
35+
return getFormBuilderViewPath('help_block.php');
2336
}
2437

2538
}

0 commit comments

Comments
 (0)