Comments (6)
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.
@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.
@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.
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.
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.
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)
- How to enable usePostMeta in ACF Block HOT 8
- Default $supports values HOT 3
- 📝 Write new standalone documentation
- 🧑💻 Make generator commands interactive
- Required field validation in blocks HOT 1
- How to retrieve the anchor or the ID of a block in blade HOT 2
- Block enqueue assets HOT 1
- Best practise for Flexible Content HOT 5
- being able to know block position to add classes (feature request) HOT 1
- Is it possible to limit the color palette per block? HOT 1
- Localization of Block Name HOT 2
- Issues running acorn commands HOT 1
- Blocks inside of PostObject Blocks? HOT 1
- Changed behaviour of get_queried_object HOT 7
- Custom Block Icon HOT 2
- Nested inner blocks no longer render HOT 6
- Intellisense doesn't recognize `modifyField()` calls
- Using the same names for fields causes the fields not to appear in the editor. HOT 1
- Set position of field group to the side HOT 3
- Advanced Custom Fields does not appear to be activated. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acf-composer.