Log1x / acf-composer

Compose ACF Fields, Blocks, Widgets, and Option Pages with ACF Builder on Sage 10.
https://github.com/Log1x/acf-composer
MIT License
413 stars 56 forks source link

Ability to set config option for Blocks in other folders? #136

Closed responsemktg closed 1 year ago

responsemktg commented 1 year ago

I know with the composers , you could set a config option that would be loaded by $this->app->config['view.composers'] by doing something similar to this:


    'composers' =>  [
            App\MyComposers\Composer::class,
    ]

Is there the equivalent of this for acf-composer blocks?

Log1x commented 1 year ago

Not at the moment but I'm not opposed to implementing it at some point.

responsemktg commented 1 year ago

@Log1x I took a look through the src, and I see I could do something like this:

Add some custom paths into config > view.php:

    'paths' => [
        get_theme_file_path('/My/Blocks'),
        get_parent_theme_file_path('/My/Blocks'),
        get_theme_file_path('/resources/views'),
        get_parent_theme_file_path('/resources/views'),
    ],

And then glob the directory of blocks to register their paths:

        $app = new AcfComposer(app());
        $dirs = glob(get_theme_file_path('/My/Blocks/*'), GLOB_ONLYDIR);

        foreach ($dirs as $d) {
            $name   = basename($d);
            $class  = "My\\Blocks\\" . $name . '\\';
            $p = $app->registerPath($d, $class);
        }

Which is cool, and then I just need to add the block view into the block.php:

    /**
     * The block view.
     *
     * @var string
     */
    public $view = 'TestBlock.view';

Badda Bing, Badda Boom. Cheers!

Log1x commented 1 year ago

🔥