thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.8k stars 2.67k forks source link

Allow adding custom input types #1513

Closed tricki closed 6 years ago

tricki commented 7 years ago

I'd like to create a new custom input type for the add/edit, browse and view routes.

As I understand the code (haven't tested it) I would have to call Voyager::addFormField($handler) and pass a class which implements TCG\Voyager\FormFields\HandlerInterface. This class is responsible for rendering the form element(s) for the field in the add/edit routes. This can be done easily.

The problem is in the browse and view routes. There the rendering of the field types is done using if/elseif directly in the route. This is obviously not easy to extend.

My thought was to add two new methods to HandlerInterface and AbstractHandler that return the HTML needed to render the input type for each route. Also I would rename all form field routes (in resources/views/bread/formfields/) to edit-add.blade.php and move them to a separate subfolder.

Any thoughts?

akazorg commented 7 years ago

Hi @tricki,

I added support for a new data type color on PR #1494, you can see a complete list of the files changed, maybe this can help you.

Fell free to send a PR with your idea.

tricki commented 7 years ago

Thanks for the answer.

That's exactly what I thought I needed to change. But the type I want to add is one that won't be of any use to anyone else.

After looking through issues I saw several mentions of a plugin system (hooks) but I couldn't find any documentation on it. Installing it also didn't work because larapack/voyager-hooks requires larapack/hooks@^0.1.1 even though larapack/hooks has no versions..

I'm still evaluating whether to use Voyager for a project but I think I'll have to wait until the hooks feature is ready.

lancepioch commented 7 years ago

Labels: feature, question, discussion

gantoday commented 6 years ago

This is very necessary.

handiwijoyo commented 6 years ago

We already has this feature in 1.0. You can submit new form fields directly to Voyager via PR or add new Hook via FormFieldsRegistered event.

See: https://github.com/the-control-group/voyager/blob/1.0/src/VoyagerServiceProvider.php#L294

ToshKoevoets commented 6 years ago

@handiwijoyo This only allows for the edit screen, the browse screen is still done with if statements.

github-actions[bot] commented 4 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.