FrozenNode / Laravel-Administrator

An administrative interface package for Laravel
http://administrator.frozennode.com/
MIT License
1.94k stars 503 forks source link

Creating custom fields with version tracking possibilities #805

Open frzsombor opened 9 years ago

frzsombor commented 9 years ago

It would be great to create custom fields with version tracking possibilities and not loosing them on a composer update/install.

Seeing a lot of requests about custom fields (like maps, coordinates, etc) and knowing that this would be only part of v5, I was thinking about making it possible to create custom fields with a new method instead of creating new classes in Fields folder. This way you will not loose your fields on a composer update/install. I don't know yet if it's possible, or how complicated it would be, it's just a sudden brainstorm right now.

Here are my ideas, for creating Enum2 field (same as and based on Enum):

Create a new option in administrator config just like settings_config_path: 'custom_fields_path' => app('path') . '/config/administrator/fields',

For this example Enum2 field the user should create:

In this example Enum2.php looks like the same as Enum.php So administrator should look for classes in _custom_fieldspath when loading all the classes from the Fields folder.

In this example we only want to display the Enum2 field in edit view, so enum2.edit.js should contain something like this: https://github.com/FrozenNode/Laravel-Administrator/blob/v4.16.1/public/js/knockout/custom-bindings.js#L649-L668

And finally enum2.edit.php should contain something like this: https://github.com/FrozenNode/Laravel-Administrator/blob/v4.16.1/src/views/templates/edit.php#L142-L150

Knowing the class name "Enum2", administrator should look for enum2.edit.php, enum2.edit.js, etc (as listed above), and if a .php file is found, include it into the corrensponding view, and if a .js is found, include it in a <script ...></script> on the bottom of the page next to the other js files.

I hope you got the point of this. Is this even possible? (especially to load the custom js files to work with KO)

Any ideas on this?

davemathews commented 9 years ago

@frzsombor you still looking at this? also isn't this the most fringe case where only someone very involved would need this?