Acorn tries to load config a second time when installed in a bedrock theme

Hi,

When installing acorn via composer inside bedrock and calling the following setup function in the functions file of my theme, I get error telling me that it’s trying to define the constants that are set in application.php a second time (and crashes).

add_action('after_setup_theme', function () {
	Application::configure()
		->withProviders([
			App\Providers\ThemeServiceProvider::class,
		])
		->boot();
}, 0);

I have tried installing a sage theme and following it via xdebug, but - in sage - it does not consider bedrock’s /config folder as config filees and so doesn’t cause the issue.

Is there a way to tell acorn that config files are already loaded when calling it without sage?

I’m not understanding the issue. Sage doesn’t do anything special in this context.

Can you provide a repo?

I’d have to recreate non-private project to provide a repo so that will have to wait.
Basically, what I’ve seen is that acorn being called inside a theme returns {project_root}/config as $app->configPath and sage returns {theme_root}/config as $app->configPath

I have managed to bypass this issue by doing

add_action('after_setup_theme', function () {
	Application::configure(get_template_directory())
		->withProviders([
			App\Providers\ThemeServiceProvider::class,
		])
		->boot();
}, 0);

The difference being in the configure() function.

Hopefully, I did not shoot myself in the foot because if this works I’ll be able to get my lead to buy radicle licenses

1 Like

Setting the base path like that would definitely make sense depending on the configuration. :+1:

One final note for people who might fall unto this issue in the future.
As written here : Directory Structure | Acorn Docs | Roots
With bedrock, you’re only supposed to install Acorn inside your theme.
As in, composer inside your theme folder.

I have so many years of pure laravel that when I fell into wordpress + bedrock and considered acorn, I instantly considered that it would go into the bedrock composer.

Either set up your acorn in your theme composer file or set the base path as defined above with configue().