88
99class DocumentCrudController extends CrudController
1010{
11+ protected $ types = [
12+ 'plaintext ' => [
13+ 'field ' => 'textarea ' ,
14+ 'attrLabel ' => 'textareaAttributes '
15+ ],
16+ 'html ' => [
17+ 'field ' => 'summernote ' ,
18+ 'attrLabel ' => 'options '
19+ ],
20+ 'md ' => [
21+ 'field ' => 'simplemde ' ,
22+ 'attrLabel ' => 'simplemdeAttributesRaw '
23+ ],
24+ ];
25+
1126 public function setup ()
1227 {
1328 /*
@@ -16,7 +31,7 @@ public function setup()
1631 |--------------------------------------------------------------------------
1732 */
1833 $ this ->crud ->setModel (config ('webfactor.documents.model_class ' ));
19- $ this ->crud ->setRoute (config ('webfactor.documents.backend.route_prefix ' ). '/ ' . config ('webfactor.documents.backend.route ' ));
34+ $ this ->crud ->setRoute (config ('webfactor.documents.backend.route_prefix ' ) . '/ ' . config ('webfactor.documents.backend.route ' ));
2035 $ this ->crud ->setEntityNameStrings (trans ('webfactor::documents.entity_name_singular ' ),
2136 trans ('webfactor::documents.entity_name_plural ' ));
2237
@@ -29,23 +44,24 @@ public function setup()
2944 // ------ CRUD FIELDS
3045
3146 $ this ->crud ->addField ([
32- 'name ' => 'type ' ,
33- 'label ' => 'Dokumentenart ' ,
34- 'type ' => 'select_from_array ' ,
35- 'options ' => $ this ->getTypeOptions (),
36- 'allows_null ' => false ,
37- 'allows_multiple ' => false
47+ 'name ' => 'type ' ,
48+ 'label ' => 'Dokumentenart ' ,
49+ 'type ' => 'select_from_array ' ,
50+ 'options ' => $ this ->getTypeOptions (),
51+ 'allows_null ' => false ,
52+ 'allows_multiple ' => false ,
3853 ]);
3954
4055 $ this ->crud ->addField ([
41- 'name ' => 'title ' ,
42- 'label ' => trans ('webfactor::documents.title ' )
56+ 'name ' => 'title ' ,
57+ 'label ' => trans ('webfactor::documents.title ' ),
4358 ]);
44-
59+
4560 $ this ->crud ->addField ([
46- 'name ' => 'body ' ,
47- 'label ' => trans ('webfactor::documents.body ' ),
48- 'type ' => $ this ->bodyFieldType ()
61+ 'name ' => 'body ' ,
62+ 'label ' => trans ('webfactor::documents.body ' ),
63+ 'type ' => $ this ->bodyFieldType (),
64+ $ this ->bodyFieldAttributesLabel () => $ this ->bodyFieldAttributes (),
4965 ]);
5066
5167 // ------ CRUD COLUMNS
@@ -57,12 +73,12 @@ public function setup()
5773 ],
5874 [
5975 'name ' => 'title ' ,
60- 'label ' => trans ('webfactor::documents.title ' )
76+ 'label ' => trans ('webfactor::documents.title ' ),
6177 ],
6278 [
6379 'name ' => 'body ' ,
64- 'label ' => trans ('webfactor::documents.body ' )
65- ]
80+ 'label ' => trans ('webfactor::documents.body ' ),
81+ ],
6682 ]);
6783
6884 // ------ CRUD BUTTONS
@@ -95,19 +111,24 @@ public function getTypeOptions()
95111 $ types = collect (config ('webfactor.documents.types ' ));
96112
97113 return $ types ->mapWithKeys (function ($ type ) {
98- return [$ type => trans ('webfactor::documents.types. ' . $ type )];
114+ return [$ type => trans ('webfactor::documents.types. ' . $ type )];
99115 });
100116 }
101117
102118 public function bodyFieldType ()
103119 {
104- $ types = [
105- 'plaintext ' => 'textarea ' ,
106- 'html ' => 'summernote ' ,
107- 'md ' => 'simplemde '
108- ];
120+ return $ this ->types [config ('webfactor.documents.body_type ' , 'plaintext ' )]['field ' ];
121+ }
122+
123+ public function bodyFieldAttributesLabel ()
124+ {
125+ return $ this ->types [config ('webfactor.documents.body_type ' , 'plaintext ' )]['attrLabel ' ];
126+ }
109127
110- return $ types [config ('webfactor.documents.body_type ' , 'plaintext ' )];
128+ public function bodyFieldAttributes ()
129+ {
130+ $ type = config ('webfactor.documents.body_type ' , 'plaintext ' );
131+ return config ('webfactor.documents.field_editor_attributes. ' .$ type , []);
111132 }
112133
113134 public function store (StoreRequest $ request )
0 commit comments