Proof of concept for plugins (still WIP) #655
Replies: 2 comments 7 replies
-
Hi Sebastien, thank you for sharing the proof of concept. I think we could have plugins with Formwork 2.1, since we're in a late development stage for the 2.0 release. I like your implementation, I'd do just some little changes to fit more into the existing structure, naming and internal conventions. Of course Plugins will be a class under src/Formwork, and from the panel there will be access for plugin views and assets too. What we could do for now, in preparation, is to use a content folder with a structure like site/content/{type}/... Another change to do now would be to make a better use of the Assets class, now it's just a convenience wrapper to version assets, etc. But it has no knowledge of which assets are really there. Thank you, and please let me know of future developments of your implementation! |
Beta Was this translation helpful? Give feedback.
-
Continuation of ideas 😊 Ok same idea I said before lol.. but maybe with more visual stuff Maybe a new panel section like this (Content) (don't bother with 'Pages' missing from the nav.. I was just using Chrome dev options to play with pages 🤣) Then What I like on this idea.. is, if for some reason, I'd like to manage or store other content than pages, but noting special about it to make a plugin... just manage various content (ie: simply process front-end contact forms and create new content here... no plugin needed). Also, on a specific page scheme, having the ability to refer to a content, using a new 'content field'. And vice-versa.. in my example, content 'reservations' will refer to page 'guided tours' because tour is also a page. Also, by having this UI.. I would remove 'create new reservation' on my plugin calendar view.. because from a user's perspective, it's super clear to go under content type reservations, and click on Create new... user don't have to bother with options like template, page type, parent, etc. as the system already know the context. Or as you said before.. simply create a new nav item for each content type. If so... the content type schema would have an option like 'includeToPanelMenu: true|false' |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to share some minor modifications I made to introduce the notion of plugins.
Notes:
Context:
I'm trying to convert my friend's website I made with Flextype. His company is about guided kayaking tours. His website is basic, but it has the "complexity" of letting visitors to book and pay online for a tour. So I orignally made a small booking Flextype plugin that enable online booking, validation, online payment with Square and email confirmations.
My idea is to migrate his website to Formwork
Page structure in Formwork:
I made a 'guided tour' scheme with all tours available for booking. Tours are also displayed on website with all info (desc, images, price, schedule, etc).
I made a 'reservation-data' scheme to store all reservations. Info such as : first/last name, selected tour, date, info on group size, status, info about square payment (transaction id, status, payment receipt id, etc).
Note: As I mention in another post, I use the concept of 'pages' to store all content from website.. not only front end pages. I might rename 'pages' label to 'content' in the final published site and remove badge for page count as it make no sense for this website.
Sorry for French screenshot ;) First after home page is the list of available guided tours and second is list of reservations (not routable, not visible, not listed, etc, to avoid any personal information leak on webiste or via URL)
Plugin I made
Plugin structure (into site folder)
Definitions of each file
Plugins.php
This class initialize the loading of plugins. It would make sense to have this object part of Formwork folder but again, goal here is to minimize the modifcations to make updates easier (by re-applying the core modificaiton after an update).
I modified formwork\src\cms\App.php to use this class, call init function, add also register a function plugins() that return the class
calendar/autoload.php
self explanatory.. load all php files
calendar/routes.php
contains panel routes
calendar/app/Controller.php
panel controller that extends Formwork\Panel\Controllers\AbstractController
used to process panel routes
calendar/app/Model.php
Store all logics. WIP. Will handle front-end reservation, payment, email, etc

example:
calendar/assets folder
any asset needed for the panel UI
The controller, when rendering the view, registers new variable "assets". Then I modified the panel layout.php to include assets in header (css) and at the end of body for js. Example for css
calendar/config/calendar.yaml
Config file of the plugin.
I also modified formwork\src\Panel\Controllers\AbstractController.php and its function loadDefaults() that build the panel nav, to include any plugin menu items. I merge this nav with built-in nav array later.
edit: the part that builds the additional nav items from plugins for the panel, will move to Plugins class, which make more sense. And the only small modification to this core function loadDefaults() will be the merge of built-in nav + plugin nav items.
Result:
calendar/translations folder
self explanatory, but here is example
calendar/views folder
IMPORTANT
This folder would contain the panel views. But right now in Formwork, views for panel are all defined into panel/views. I would require a lot more changes to the core to allow different paths for the views. So I created a 'calendar' folder here and copied all views
How to use plugin functions in the front end:
Example: in the front end controller, I can get the model and use any logic.
This is where I'll call the model to handle form-submission and store reservation, redirect to payment etc.
In summary, here are all the core files I needed to modify. Most of the changes are really small, and only add a reference to Plugins class and functions
Feel free to comment and add suggestions! Obviously, it's still WIP and some code has hardcoded stuff that will be replaced. Things like paths for '/panel/' or '/site', etc
Hopefully the concept of plugins can be implemented officially soon!
Side note, I also want to migrate my personal website which is a photography portfolio. In the same idea, I'll make a small plugin that adds panel menu item "Gallery" that will simply displays a gallery of thumbnails. Again, justs a view over Formwork pages that I'll use to store each photography information (image, title, desc, tags, purchase option links, etc). Managing pictures is easier with actual images than just a list of image titles (unlike a blog)
Beta Was this translation helpful? Give feedback.
All reactions