Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grav 1.7 Migration Blueprints #859

Open
NicoHood opened this issue Nov 22, 2020 · 5 comments
Open

Grav 1.7 Migration Blueprints #859

NicoHood opened this issue Nov 22, 2020 · 5 comments

Comments

@NicoHood
Copy link
Contributor

NicoHood commented Nov 22, 2020

Please add:
slug: folder-name
type: plugin|theme

https://learn.getgrav.org/17/advanced/grav-development/grav-17-upgrade-guide#plugin-theme-blueprints-blueprints-yaml

Could that get clarified, please? What is the slug used for? What about page blueprints or partials? What type should I use in the following usecases:

plugins/ratings/blueprints.yaml                  -> type: plugin, slug: ???
plugins/ratings/blueprints/rating_page.yaml      -> type: ???, slug: ???
plugins/ratings/blueprints/partials/ratings.yaml -> type: ???, slug: ???
themes/quark/blueprints.yaml                     -> type: theme, slug: ???
themes/quark/blueprints/rating_page.yaml         -> type: ???, slug: ???
themes/quark/blueprints/partials/ratings.yaml    -> type: ???, slug: ???

Second question

If your plugins has blueprints folder, initializing it in the event will be too late. Do this instead:

class MyPlugin extends Plugin
{
    /** @var array */
    public $features = [
        'blueprints' => 0, // Use priority 0
    ];
}

https://learn.getgrav.org/17/advanced/grav-development/grav-17-upgrade-guide#blueprints

Do we still need the event code? I am using the event code from here:
https://learn.getgrav.org/16/admin-panel/extending#adding-a-custom-page-blueprint-to-a-theme-plugin

public function onPluginsInitialized(): void
{
    // If in an Admin page.
    if ($this->isAdmin()) {
        $this->enable([
            'onGetPageBlueprints' => ['onGetPageBlueprints', 0],
            'onGetPageTemplates' => ['onGetPageTemplates', 0],
        ]);
    }
}

/**
 * Add blueprint directory.
 */
public function onGetPageBlueprints(Event $event): void
{
    $types = $event->types;
    $types->scanBlueprints('plugin://' . $this->name . '/blueprints');
}

/**
 * Add templates directory.
 */
public function onGetPageTemplates(Event $event): void
{
    $types = $event->types;
    $types->scanTemplates('plugin://' . $this->name . '/templates');
}

However I was always wondering why there are 2 more docs with different examples:
https://learn.getgrav.org/16/forms/blueprints/example-page-blueprint#in-a-plugin
https://learn.getgrav.org/16/plugins/event-hooks#ongetpagetemplates

Maybe those examples should also get updated?

  • Is onGetPageTemplates even required? It does not seem to in my usecase, I might be wrong.
  • getSubscribedEvents should be replaced by onPluginsInitialized and an isAdmin check, correct?
  • The last link has completely different examples for onGetPageTemplates and onGetPageBlueprints. Are those outdated or what is this code used for? I am completely confused here
@mahagr
Copy link
Member

mahagr commented Dec 10, 2020

The docs talk only plugin/theme blueprint, not other blueprints. Slug and type was added for GPM not to have to guess if your extension is a plugin or a theme.

Nothing else has been changed. I take a deeper look into this when I am looking into documentation.

@NicoHood
Copy link
Contributor Author

Why is it required to add a slug? Can't grav just parse the folder name itself? this looks duplicated to me.

What about the second question?

@mahagr
Copy link
Member

mahagr commented Jan 15, 2021

Yes, Grav does use the folder name, but check all the zip files -- there's no good way to figure out the name when you're installing the plugins/themes. This has caused some issues during installation.

@NicoHood
Copy link
Contributor Author

Alright, that is clear now.

Could you please explain the different between onGetPageTemplates and onGetPageBlueprints and if you should always use both or just one or the other? I will update the docs then accordingly...

@mahagr
Copy link
Member

mahagr commented Jan 18, 2021

I guess one is for getting blueprints and another is for twig files. Both methods are from the time before streams.

Getting the templates is still relevant as you're not required to define blueprints to have a custom looks. But blueprints should generally be using streams instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants