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 inside Core folder, but I'm looking for an alternative way.


  • Global Moderator

    @zedee

    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 LaravelCollective

    In your module just create macros.php and add that file in module.json in files array.

    Form::macro('coolMacro', function($cool, $macro) {
        return $cool . $macro;
    });
    
    Form::coolMacro('Hello', 'world!');
    


  • @armababy

    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 the Core, the checkboxes are too tied to the styling of iCheck (using class flat-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?


  • Global Moderator

    @zedee No idea :D Personally i don't use core macros. Might be good question for @nWidart


  • admin

    Hello @zedee ,

    You can create your own macros.php file with your own custom checkboxes. :)



  • @nWidart

    But that macros.php can be overriden from the Core?


  • admin

    No, it should be new macros. Ie: with new unique names.



  • @nWidart

    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 for icheck.blue.css, and pointing it to the green.css skin, but even with that I have to change flat-blue class by flat-green class).


  • admin

    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.



  • @nWidart

    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.


  • admin

    hm yes, that's correct.



  • @nWidart

    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 ?


  • admin

    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 :)



  • @nWidart

    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.


  • admin

    Hehe yea no worries, I have the same "issue" too, buried under work and less time to dedicate to the cms.


Log in to reply
 

Looks like your connection to AsgardCms was lost, please wait while we try to reconnect.