GithubHelp home page GithubHelp logo

Comments (6)

Log1x avatar Log1x commented on September 18, 2024 2

Try calling it from a service provider like:

app('AcfComposer')->registerPath(...)

But I admittedly need to test this stuff more. I think adding an option to load classes from the config would be a fine addition too.

from acf-composer.

drbroad avatar drbroad commented on September 18, 2024 1

@mike-sheppard Apologies, I just reread my post and I wasn't exactly clear.

I already have the view files registered as per your example, but I'm trying to get custom Block definitions registered. (Example.php for example)

I have tried doing the following:

Assuming I have a structure of:
`

  • CustomBlockFolder
    -- Carousel
    --- ...other assets for the carousel block
    --- Blocks
    ---- Block.php
    -- Slider
    --- ...other assets for the slider block
    --- Blocks
    ---- Block.php
    `

I have used the following in older versions to iterate over that folder and register all the Block files:

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

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

        var_dump($app->paths());

Again, this was code from 2.1.0 - but that method still exists in the latest release

I can see that it will add my block to the paths, but it still isn't viewable in the admin (I took the exact output of wp acorn acf:block Example and adjusted the namespace to match the folder structure)

In case you are wondering the motivation behind the request: I have all my block elements in separate repos that I can import into any of my projects. It is a self-contained folder with all the assets, scripts, block definition, and view - so that it can be dropped into any project and basically 'just work'.

from acf-composer.

mike-sheppard avatar mike-sheppard commented on September 18, 2024

@drbroad yep that's pretty much what we do to load block views in their own directory.

// config/view.php
'paths' => [
    resource_path('views'),
    resource_path('blocks'), // our custom blocks view dir
],
// app/Blocks/Hero.php
public $view = 'hero.hero';

Which will load in resources/blocks/hero/hero.blade.php

from acf-composer.

mike-sheppard avatar mike-sheppard commented on September 18, 2024

Aha, yeah, that does make sense 👍 Unfortunately I won't be much help on this so I'll leave it for @Log1x or other folks to follow up on! :)

from acf-composer.

drbroad avatar drbroad commented on September 18, 2024

If I hardcode the same values into AcfComposer.php on line 172 as I would be from my loop:

    /**
     * Register the default application path.
     */
    public function registerDefaultPath(): void
    {
        $this->registerPath($this->app->path());
        $this->registerPath('/Users/me/Desktop/www/acftest/site/web/app/themes/acftest/customBlockPaths/Carousel', 'CustomBlockPaths\Carousel\\');
);
    }

Everything works just fine.

it seems that when I am running the following, it isn't being registered at the same time / is being registered to a different instance of AcfComposer:

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

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

I can test it by running wp acorn acf:block Example and then:

$app = new AcfComposer(app());
var_dump($app->paths());

Which returns an empty array. My thinking was this should at least return the default path and existing blocks.

Should I be calling registerPath() a different way?

from acf-composer.

drbroad avatar drbroad commented on September 18, 2024

app('AcfComposer')->registerPath(...)

Boy, do I feel silly right now - this works perfectly, thank you!
Also, a config approach would be very useful too.

from acf-composer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.