I’m trying to onboard a pre-existing site which uses Sage theme (Version: 8.4.2) and Bedrock and I’ve managed to set it up in Local so that the site is functioning, and I can access wp-admin. However when I activate the Sage theme I get this PHP Error on the front end: Fatal error: Uncaught Error: Class ‘Fetchers\Other\CustomFieldFetcher’ not found in /app/bedrock/web/app/themes/ag/lib/helpers.php on line 38
It seem that this is an issue with any Namespaced class that is being called from another file. Any namespaced class that’s referenced from helpers.php is failing in the same way.
There wasn’t a composer.json in the theme directory.
However I figured maybe there should be so I ran this command elsewhere (composer create-project roots/sage adamsage 8.4.2) and copied the resulting composer.json from the theme that was generated into my theme and ran composer install, it installed something but it doesn’t seem to have affected the error at all.
It looks like the project you copied is missing the package Fetchers\Other\CustomFieldFetcher.
You’ll need to review the codebase you copied from and find what is missing.
Also, rather than creating a new composer.json using composer create-project roots/sage adamsage 8.4.2, you should copy from the pre-existing project.
Thanks for replying. The thing that’s confusing is that the theme does appear to have that file:
And on the server this theme with these exact files is running fine with no fatal errors so it appears to me that what I have includes all the dependencies.
In Sage projects, Composer’s autoloader is generally used to autoload namespaced functions, etc. If packages are installed 2ith composer, they it automatically adds them to it’s autoloader. It looks like your Fetchers are outside of the vendor folder, so the original developer probably configured rules for autoloading them in the there’s composer.json so that Composer could generate correct autoloading rules. Composer docs explain this process: https://getcomposer.org/doc/01-basic-usage.md#autoloading
There should definitely have been a composer.json in the original theme, which would contain this information. If you can’t find it, and can’t get ahold of the original developer, you may need to rebuild it from scratch. The new (presumably empty) composer.json you just created probably overwrote the existing autoloader when you ran composer install.
Thanks everyone for your help! Helping me understand a bit more about autoloaders and Sage got me going in the right direction.
I have managed to get it working, in the end it turned out the config that was being used for dependencies was in the composer.json file a few levels up at the bedrock level, so I had everything that was needed already I was just screwing up the nginx config I think.
So I started again by pulling all the files down from the server and double checking the site’s nginx config pointed to the right place. Ran composer install from there (although I guess I didn’t need to really since the deps were there already) and everything within the theme seems to work properly now