bolt / docs

Documentation for Bolt.
45 stars 194 forks source link

Local extensions are not installed #956

Open gpothier opened 5 years ago

gpothier commented 5 years ago

Hi, first of all thanks for making this awesome CMS! So I am trying to write an extension, and the documentation says:

in any Bolt site you can put local extensions within extensions/local/{author_name}/{extension_name}

(this is at https://docs.bolt.cm/3.6/extensions/basics/testing#phase-1-develop-your-extension-within-a-bolt-project)

However, there is probably something else to do, because Bolt does not seem to pick up the extension (it does not appear as an installed extension on the extensions page, and calling extension methods fail).

I did change the minimum-stability to dev in config.yml

And to exclude a problem with the extension itself, I downloaded a known-working extensions from github (https://github.com/designspike/bolt-extension-menuchain) and I renamed the directories so that the extension is in extensions/local/designspike/menuchain, as suggested in the docs above:

gpothier@tadzim4:~/myboltroot$ ls extensions/local/designspike/menuchain/
composer.json  README.md  src

The documentation doesn't mention any additional step for this to work. What am I missing?

JarJak commented 5 years ago

Did you register your extension in .bolt.yml?

gpothier commented 5 years ago

No, I didn't. The .bolt.yml file is not mentioned in the "Extending Bolt" chapter until much, much farther, in the "Custom bootstrapping" and "Bundled extensions" sections.

Just to be clear: I am able to develop my extension in an external repository using the steps in the "Creating a new extension" section. But there is a documentation issue, because the "Testing and debugging" section mentions that "the fastest way to get started" is putting the extensions in extensions/local, which doesn't work if one follows the documentation in order.

JarJak commented 5 years ago

Feel free to provide a Pull Request with proposed changes in documentation :)

gpothier commented 5 years ago

With your help I could do that! There are a few other (rather minor) details in the first sections of the Extending Bolt chapter that could be improved upon to help newcomers like me getting started, and I could propose something in addition to the particular fix regarding the local extensions.

The thing is, I'm learning Bolt and I am not familiar at all with PHP's ecosystem, so I have absolutely no idea what to put in the .bolt.yml file. If I add the extension's class to the list of extensions, Bolt fails:

Extension class name "Bolt\Extension\DesignSpike\MenuChain\MenuChainExtension" is defined in .bolt.yml or .bolt.php, but the class name is misspelled or not loadable by Composer.

This is what I tried:

    "local-repo": {
        "type": "path",
        "url": "extensions/local/designspike",
        "options": {
            "symlink": false
        }
    }

"designspike/menuchain": "dev-master@dev"

Also, I am not trying to create a bundled extension: I want to start developing an extension that I will publish on the marketplace, and the local extensions looked like a good option to start with.

JarJak commented 5 years ago

https://github.com/bolt/docs/tree/3.6/docs/extensions here you can edit any part of extensions doecumentation :)

There is probably something wrong with your extension namespace. It should follow PSR-4. So if your extension class is in extensions/local/designspike/MenuChain/MenuChainExtension.php then the Fully-Qualified Class Name (FQCN) should be DesignSpike\MenuChain\MenuChainExtension (without Bolt\Extension part), at least unless you define new psr-4 root in composer.json.

Can you show your whole extensions/composer.json file?

gpothier commented 5 years ago

Sure, here is extensions/composer.json:

{
    "autoload": {
        "psr-4": {
            "Bolt\\Composer\\EventListener\\": "../vendor/bolt/bolt/src/Composer/EventListener",
            "DesignSpike\\MenuChain\\": "local/designspike/menuchain/src/"
        }
    },
    "config": {
        "discard-changes": true,
        "preferred-install": "dist"
    },
    "description": "Bolt extension installation interface",
    "extra": {
        "bolt-web-path": "../public",
        "bolt-root-path": ".."
    },
    "license": "MIT",
    "minimum-stability": "dev",
    "name": "bolt/extensions",
    "prefer-stable": true,
    "provide": {
        "bolt/bolt": "3.6.6"
    },
    "repositories": {
        "packagist": false,
        "bolt": {
            "type": "composer",
            "url": "https://market.bolt.cm/satis/"
        }
    },
    "scripts": {
        "post-autoload-dump": "Bolt\\Composer\\EventListener\\PackageEventListener::dump",
        "post-package-install": "Bolt\\Composer\\EventListener\\PackageEventListener::handle",
        "post-package-update": "Bolt\\Composer\\EventListener\\PackageEventListener::handle"
    }
}

I added a PSR-4 root in extensions/composer.json because the extension class is in extensions/local/designspike/menuchain/src/:

gpothier@tadzim4:~/myboltroot$ head extensions/local/designspike/menuchain/src/MenuChainExtension.php 
<?php

namespace DesignSpike\MenuChain;

use Bolt\Application;
use Bolt\Extension\SimpleExtension;

class MenuChainExtension extends SimpleExtension
{
    public function registerTwigFunctions()

And here is .bolt.yml:

extensions:
    - Bundle\Site\CustomisationExtension
    - DesignSpike\MenuChain\MenuChainExtension

I have tried putting the additional PSR-4 root in the main composer.json (adding the extensions/ path prefix), tried with and without the Bolt\Extension\ namespace prefix (also adapting the PSR-4 roots and the namespace declaration in the extension file accordingly), deleted the extension's own composer.json file in case it interfered, also tried putting the extension class outside the src directory (directly in extensions/local/designspike/menuchain) and removing the additional PSR-4 root. Nothing worked so far.

JarJak commented 5 years ago

Composer.json file looks ok.

Extension class name "Bolt\Extension\DesignSpike\MenuChain\MenuChainExtension" is defined in .bolt.yml or .bolt.php, but the class name is misspelled or not loadable by Composer.

Remove Bolt\Extension\ from your extension's line in .bolt.yml.

gpothier commented 5 years ago

I did remove it (you can see my .bolt.yml file in my previous comment). The error message you quoted was from before this change.

JarJak commented 5 years ago

So what is the error message now?

gpothier commented 5 years ago

The same without said prefix:

Extension class name "DesignSpike\MenuChain\MenuChainExtension" is defined in .bolt.yml or .bolt.php, but the class name is misspelled or not loadable by Composer.

JarJak commented 5 years ago

Did you run nut extensions:setup command?

gpothier commented 5 years ago

I had not, but I tried it and it gives the same error:

gpothier@tadzim4:~/Documents/mirrored/clients/caligrafix/web2019-caligrafix-bolt$ ./app/nut extensions:setup

  [LogicException]                                                                                                                                      
  Extension class name "DesignSpike\MenuChain\MenuChainExtension" is defined in .bolt.yml or .bolt.php, but the class name is misspelled or not loadab  
  le by Composer.                                                                                                                                       

Exception trace:
 () at /home/gpothier/Documents/mirrored/clients/caligrafix/web2019-caligrafix-bolt/vendor/bolt/bolt/src/Bootstrap.php:169
 Bolt\Bootstrap::Bolt\{closure}() at /home/gpothier/Documents/mirrored/clients/caligrafix/web2019-caligrafix-bolt/vendor/pimple/pimple/lib/Pimple.php:201
 Pimple->{closure}() at /home/gpothier/Documents/mirrored/clients/caligrafix/web2019-caligrafix-bolt/vendor/pimple/pimple/lib/Pimple.php:126
 Pimple::{closure}() at /home/gpothier/Documents/mirrored/clients/caligrafix/web2019-caligrafix-bolt/vendor/pimple/pimple/lib/Pimple.php:83
 Pimple->offsetGet() at /home/gpothier/Documents/mirrored/clients/caligrafix/web2019-caligrafix-bolt/vendor/bolt/bolt/src/Provider/ExtensionServiceProvider.php:156
 Bolt\Provider\ExtensionServiceProvider->boot() at /home/gpothier/Documents/mirrored/clients/caligrafix/web2019-caligrafix-bolt/vendor/silex/silex/src/Silex/Application.php:197
 Silex\Application->boot() at /home/gpothier/Documents/mirrored/clients/caligrafix/web2019-caligrafix-bolt/vendor/bolt/bolt/app/nut:15