Is it possible to define a new addon type like 'Button' ?
Created 7 years ago by dali

I want to define an upload button with some config pushed in to be used in builders' $buttons This button would work very similar to normal file field in UI side. (like modals and other stuff)

Andd I want to reuse this elsewhere. how can this be achieved?

I actually defined a button addon, pyro didnt complain about it. but how to bind a button to addon (???) I tried adding and handler to button, which points to a handler in the button addon but didnt work

any redirections?

ryanthompson  —  7 years ago Best Answer

Check out docs for buttons: http://pyrocms.com/documentation/streams-platform/v1.1#ui/buttons

Particularly the part about the definition and the button parameter.

Then the button registry section outlines the register method below a ways.

Those two sections should get you started on your way! Every registry for UI components has register methods as well.

ryanthompson  —  7 years ago

Can you describe a little more about what you are trying to do? You absolutely CAN define and include custom addon types in Pyro but sounds like maybe you want to just register some custom buttons? Why make them an addon? You can register custom button classes as well if that helps. Let me know what you are trying to do and I will show you the way!

dali  —  7 years ago

Here's my case; I can not use the current files-module for my upload needs because of some limitations (too much detail) Now I have a button which directly shows dropzone in a modal preconfigured with some parameters. Then I handle everything in that modal.

My main concern is reusability and making it distributable.

ryanthompson  —  7 years ago

I think a registered button would do nicely. However if you want to redistribute perhaps wrap up the register and supporting button classes / logic in an extension. Then the extensions service provider can register the buttons / actions / etc as needed during load.

dali  —  7 years ago

ee.. soo... how to register custom button classes, and how to use them?

ryanthompson  —  7 years ago Best Answer

Check out docs for buttons: http://pyrocms.com/documentation/streams-platform/v1.1#ui/buttons

Particularly the part about the definition and the button parameter.

Then the button registry section outlines the register method below a ways.

Those two sections should get you started on your way! Every registry for UI components has register methods as well.

ryanthompson  —  7 years ago

What did you come up with?

dali  —  7 years ago

I came up with an upload module which has a single Files stream, similar to the one in the original files module. In additional it has a related field which morphs to any other Model

This module also registers a button and can be configurable like:

 'buttons' => [
                        'vzr_upload' => [
                            'config' => [
                                'related'    => ProductModel::class,
                                'related_id' => '{request.route.parameters.product}',
                            ],
                        ],
                    ]

And the main difference of this module is, It previews the files before uploading. This was the most important thing I needed. And no folder selection is allowed, the file goes directly related folder. If the model is ProductModel it goes under product folder. If you provide related_id then it is products/{id} (inspired from pyro's guessmaker 😄

Currently serves my needs, I'd appreciate if you can review when I have several refactoring cycles.

ryanthompson  —  7 years ago

Excellent work! Glad to see you've come up with something 😊