Skip to content

minor enhancements for flex object plugin creation #84

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,36 @@ By default, devtools will perform a check with the online gpm repository to ensu
To create a new plugin you simply need to run: `bin/plugin devtools new-plugin` and fill in the few questions at the prompts:

```
> bin/plugin devtools new-plugin
Enter Plugin Name: MyPlugin
Enter Plugin Description: My New Custom Plugin
Enter Developer Name: Johnny Rotten
Enter GitHub ID (can be blank): pretty-vacant
Enter Developer Email: johnny@rotten.com
foo@bar:~$ bin/plugin devtools new-plugin

Enter Plugin Name:
> MyPlugin

Enter Plugin Description:
> My New Custom Plugin

Enter Developer Name:
> Johnny Rotten

Enter GitHub ID (can be blank):
> pretty-vacant

Enter Developer Email:
> johnny@rotten.com

Please choose an option:
[blank] Basic Plugin
[flex ] Basic Plugin prepared for custom Flex Objects
> flex

Enter Flex Object Name:
> myflex

Please choose a storage type:
[simple] Basic Storage (1 file for all objects) - no media support
[file ] File Storage (1 file per object)
[folder] Folder Storage (1 folder per object)
> folder

SUCCESS plugin myplugin -> Created Successfully

Expand Down Expand Up @@ -71,9 +95,11 @@ There are **three template creation options**

## Skipping Online Project Name Collision Checking

By default, devtools will check your project's name with the existing gpm ecosystem to ensure no collisions. In order to skip this check, add an `--offline` or `-o` to your command:
By default, devtools will check your project's name with the existing gpm ecosystem to ensure no collisions. In order to skip this check, add an `--offline` or `-o` to your command:

`bin/plugin devtools new-theme --offline`
or

`bin/plugin devtools new-theme -o`

In that case make shure to add `gpm: false` (e. g. on the next line after `licence:`) to your plugins or themes blueprint to avoid conflicts in the future.
3 changes: 3 additions & 0 deletions classes/DevToolsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ protected function createComponent(): bool

if ($this->component['flex_name']) {
$flex_classes_folder = $component_folder . DS . 'classes' . DS . 'Flex' . DS . 'Types';
$flex_templates_folder = $component_folder . DS . 'templates' . DS . 'flex';
$flex_name = strtolower($this->inflector::underscorize($this->component['flex_name']));
$flex_name_camel = $this->inflector::camelize($this->component['flex_name']);

Expand All @@ -270,6 +271,8 @@ protected function createComponent(): bool
rename($flex_classes_folder . DS . $flex_name_camel . DS . 'Collection' . '.php',$flex_classes_folder . DS . $flex_name_camel . DS . $flex_name_camel . 'Collection' . '.php');

rename($component_folder . DS . 'blueprints' . DS . 'flex-objects' . DS . $type . '.yaml', $component_folder . DS . 'blueprints' . DS . 'flex-objects' . DS . $flex_name . '.yaml');

rename($flex_templates_folder . DS . 'flex_name',$flex_templates_folder . DS . $flex_name);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ form:
fields:
published:
type: toggle
label: Published
label: PLUGIN_ADMIN.VISIBLE
highlight: 1
default: 1
options:
Expand Down
14 changes: 13 additions & 1 deletion components/plugin/flex/plugin.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class {{ component.name|camelize }}Plugin extends Plugin
// ['autoload', 100000],
['onPluginsInitialized', 0]
],
FlexRegisterEvent::class => [['onRegisterFlex', 0]],
FlexRegisterEvent::class => [['onRegisterFlex', 0]],
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 1],
];
}

Expand Down Expand Up @@ -63,6 +64,9 @@ class {{ component.name|camelize }}Plugin extends Plugin
]);
}

/**
* Automatically initialize flex object blueprints
*/
public function onRegisterFlex($event): void
{
$flex = $event->flex;
Expand All @@ -73,4 +77,12 @@ class {{ component.name|camelize }}Plugin extends Plugin
);

}

/**
* Add current directory to twig lookup paths.
*/
public function onTwigTemplatePaths() : void
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<section>
{% for item in collection %}
{% render item %}
{% endfor %}
</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<article>
<h2>
{{ object.name }}
</h2>
<div>
{{ object.description|markdown|raw }}
</div>
</article>