In OctoberCMS, I would like to change a page process simply by attaching a different plugin component.
I have a plugin component (makeform
) which inserts a form (defined in a database table).
Clicking the form's submit
button calls onSubmit()
which calls process()
.
process()
is a function defined in another plugin component.
i) Can I call process()
from within makeform
without knowing the name of the other plugin or its component? That is, without having to use 'Acme\Plugin\Components\ProcessForm', 'processForm';
ii) Alternatively, can I programmatically discover the name of the other attached component and it's plugin, and then somehow specify it's process()
function?
iii) Or is it a case of using a static properties
dropdown to choose which process, and then adding the component dynamically. Always assuming I can $this->addComponent('Acme\Plugin\Components\ProcessForm', 'processForm');
beyond init()
.
Edit: Experimentation
I was hoping to dynamically addComponent()
.
Wherever I place it, in init()
or elsewhere, I get the error:
Class name is not registered for the component "Acme\Plugin\Components\ProcessForm". Check the component plugin.
Even if I'm not using one of it's classes.
Many online references to this error message, but not one that has helped me.
Edit: Further explanation
A (hopefully) simplified explanation of what I'm trying to achieve.
In essence I imagine a page process consisting of a string of components.
Each component calls a function in the next component until the process ends.
The overall process can be modified simply by replacing components.
I am guessing the only way to connect components is by standardizing the function names. So this (probably?) requires components to belong to particular stages of the process, although it would be ideal if each of them can fit in at any stage (where appropriate).