Extend/Override Form Macros
-
Hi, is there any chance or tips about how to customize or extend the form macros?
I've just unignored the
macros.php
file insideCore
folder, but I'm looking for an alternative way.
-
How exactly are you looking for to go about it? Asgard uses LaravelCollective for HTML, FORM macros.
You can create new ones as in documentation of LaravelCollectiveIn your module just create
macros.php
and add that file inmodule.json
infiles
array.Form::macro('coolMacro', function($cool, $macro) { return $cool . $macro; }); Form::coolMacro('Hello', 'world!');
-
Oh, great, fantastic! That's just what I needed to know
There's something I'd like to point out:
in the
macros.php
from theCore
, the checkboxes are too tied to the styling of iCheck (using classflat-blue
, as well as many of the core modules' views and config.It's a bit of a pain having to change them manually (not only in the macros but in all the
resources/views
of every module if you pretend to change the base AdminLTE theme. And obviously all the stuff in the.gitignore
doesn't keep updated when someone of my team clones the project.Are there any plans to 'decouple' this ties in a future?
-
-
Hello @zedee ,
You can create your own
macros.php
file with your own custom checkboxes.
-
But that macros.php can be overriden from the Core?
-
No, it should be new macros. Ie: with new unique names.
-
Hm... not sure if I get it.
The problem I'm facing is that if I change the backend theme, I'm tied to use the icheck.blue.css assets, and I'm not being able to change them unless I modify all core files that references to icheck-blue (those in views, and the asset pipeline in controllers).
Makes this any sense? I'm missing a workaround?
(The only workaround I've found so far is to edit the
asgard.core.core.php
and give a faux identifier foricheck.blue.css
, and pointing it to thegreen.css
skin, but even with that I have to changeflat-blue
class byflat-green
class).
-
Ah I see, you want to change all checkboxes to something else.
In that case you have to overwrite the adminlte theme yes, and probably the views of modules with checkboxes.
-
All right, so I should remove the core's
macros.php
from.gitignore
and switching the class I need there, isn't it?Alternatively, I've created a new theme over AdminLTE theme, but some stuff like the
icheck
is still a bit dependant of some core files.
-
hm yes, that's correct.
-
All right, understood.
A last question: about all those classes and JavaScript into the modules' views, then the way to go and to mantain it into a repo, affecting the less any potential
composer update
would be to publish all modules' views ?
-
Yeah that would fix the issue you're facing now. Having every module publish its views, just like the user module does. This way you can customise the form as you please.
Maybe a good idea for a pull request
-
Fantastic, thanks!
About that pull request, I'd certainly love to do so, but I'm a bit busy on the project I'm working on right now.
If possible, in a future, I will try to "untie" this dependency from the core modules, and letting this to be configurated from the theme, but I'll do with a vanilla installed CMS.
-
Hehe yea no worries, I have the same "issue" too, buried under work and less time to dedicate to the cms.