acf-composer
acf-composer copied to clipboard
Proposal: AcfComposer - relative path calculation
Hello Brandon,
before adding a new PR, I would like to ask if it is worth it for you.
I am adding blocks using a reusable custom plugin each. For example, this is a simple block for adding a custom Call to Action:
# my-plugin.php
// Initialise plugin
add_filter('after_setup_theme', function () {
if (!function_exists('app')) {
return;
}
// Register plugin to Acorn
app()->register(
Encodia\BlockCta\Providers\PluginServiceProvider::class
);
}, 20);
# PluginServiceProvider.php
public function boot(): void
{
$this->app->make('AcfComposer')->registerPlugin(
plugin_dir_path(__DIR__),
__NAMESPACE__
);
// Registra manualmente il Component
Blade::component('cta', Cta::class);
}
I am able to use it only if I change one line into the AcfComposer.php class, line 91. In this way both implementations should work: by a plugin or by a classic block into the theme.
From:
$relativePath = str_replace(
$this->app->path() . DIRECTORY_SEPARATOR,
'',
$file->getPathname()
);
To:
$relativePath = str_replace(
rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR,
'',
$file->getPathname()
);
I'm not sure if I was clear enough, I hope so. Do you think I could send you a PR or maybe I'm making a mistake in initializing our plugins?
Thank you