@@ -49,13 +49,13 @@ class FieldTransformer
49
49
'html-type ' => 'htmlType ' ,
50
50
'html-value ' => 'htmlValue ' ,
51
51
'value ' => [
52
- 'dataValue ' ,
53
- 'htmlValue '
52
+ 'dataValue ' ,
53
+ 'htmlValue '
54
54
],
55
55
'is-on-views ' => [
56
- 'isOnIndexView ' ,
57
- 'isOnFormView ' ,
58
- 'isOnShowView '
56
+ 'isOnIndexView ' ,
57
+ 'isOnFormView ' ,
58
+ 'isOnShowView '
59
59
],
60
60
'is-on-index ' => 'isOnIndexView ' ,
61
61
'is-on-form ' => 'isOnFormView ' ,
@@ -268,18 +268,19 @@ protected function getProperties(array $properties)
268
268
unset($ properties ['html-type ' ]);
269
269
}
270
270
271
- $ definitions = ( array ) config ( ' codegenerator.common_definitions ' , [] );
271
+ $ definitions = Config:: getCommonDefinitions ( );
272
272
273
273
foreach ($ definitions as $ definition ) {
274
274
$ patterns = $ this ->isKeyExists ($ definition , 'match ' ) ? (array ) $ definition ['match ' ] : [];
275
- $ config = $ this ->isKeyExists ($ definition , 'set ' ) ? (array ) $ definition ['set ' ] : [];
275
+ $ configs = $ this ->isKeyExists ($ definition , 'set ' ) ? (array ) $ definition ['set ' ] : [];
276
276
277
- if (count ($ config ) > 0 && Helpers::strIs ($ patterns , $ properties ['name ' ])) {
278
- if (isset ($ config ['name ' ])) {
279
- unset($ config ['name ' ]);
277
+ if (Helpers::strIs ($ patterns , $ properties ['name ' ])) {
278
+ //auto add any config from the master config
279
+ foreach ($ configs as $ key => $ config ) {
280
+ if (!$ this ->isKeyExists ($ properties , $ key )) {
281
+ $ properties [$ key ] = $ config ;
282
+ }
280
283
}
281
-
282
- $ properties = array_merge ($ properties , $ config );
283
284
}
284
285
}
285
286
@@ -386,7 +387,7 @@ protected function setRange(Field & $field, array $properties)
386
387
$ field ->range = explode (': ' , substr ($ properties ['html-type ' ], 12 ));
387
388
}
388
389
389
- if ($ this ->isKeyExists ($ properties , 'range ' ) && is_array ($ properties ['range ' ])) {
390
+ if ($ this ->isKeyExists ($ properties , 'range ' ) && is_array ($ properties ['range ' ])) {
390
391
$ field ->range = $ properties ['range ' ];
391
392
}
392
393
@@ -585,7 +586,8 @@ protected function getForeignConstraint(array $properties)
585
586
$ onUpdate = $ this ->isKeyExists ($ constraint , 'on-update ' ) ? $ constraint ['on-update ' ] : null ;
586
587
$ onDelete = $ this ->isKeyExists ($ constraint , 'on-delete ' ) ? $ constraint ['on-delete ' ] : null ;
587
588
$ modelPath = $ this ->getModelsPath ();
588
- $ model = $ this ->isKeyExists ($ constraint , 'references-model ' ) ? $ constraint ['references-model ' ] : self ::guessModelFullName ($ name , $ modelPath );
589
+ $ model = $ this ->isKeyExists ($ constraint , 'references-model ' ) ? $ constraint ['references-model ' ] :
590
+ self ::guessModelFullName ($ properties ['name ' ], $ modelPath );
589
591
590
592
return new ForeignConstraint ($ constraint ['field ' ], $ constraint ['references ' ], $ constraint ['on ' ], $ onDelete , $ onUpdate , $ model );
591
593
}
@@ -762,7 +764,7 @@ protected function setValidationProperty(Field & $field, array $properties)
762
764
$ field ->validationRules [] = 'array ' ;
763
765
}
764
766
765
- if (in_array ($ field ->dataType , ['char ' ,'string ' ]) && in_array ($ field ->htmlType , ['text ' ,'textarea ' ]) ) {
767
+ if (in_array ($ field ->dataType , ['char ' ,'string ' ]) && in_array ($ field ->htmlType , ['text ' ,'textarea ' ])) {
766
768
if (!in_array ('string ' , $ field ->validationRules )) {
767
769
$ field ->validationRules [] = 'string ' ;
768
770
}
@@ -771,7 +773,7 @@ protected function setValidationProperty(Field & $field, array $properties)
771
773
$ field ->validationRules [] = sprintf ('min:%s ' , $ field ->getMinLength ());
772
774
}
773
775
774
- if (!$ this ->inArraySearch ($ field ->validationRules , 'max ' ) && !is_null ($ field ->getMaxLength ()) ) {
776
+ if (!$ this ->inArraySearch ($ field ->validationRules , 'max ' ) && !is_null ($ field ->getMaxLength ())) {
775
777
$ field ->validationRules [] = sprintf ('max:%s ' , $ field ->getMaxLength ());
776
778
}
777
779
}
@@ -782,19 +784,18 @@ protected function setValidationProperty(Field & $field, array $properties)
782
784
$ params = $ this ->getDataTypeParams ($ field ->dataType , (array ) $ properties ['data-type-params ' ]);
783
785
}
784
786
785
- if ( $ field ->htmlType == 'number ' || (in_array ($ field ->dataType , ['decimal ' ,'double ' ,'float ' ])
786
- && isset ($ params [0 ]) && ($ length = intval ($ params [0 ])) > 0
787
- && isset ($ params [1 ]) && ($ decimal = intval ($ params [1 ])) > 0 ) )
788
- {
787
+ if ($ field ->htmlType == 'number ' || (in_array ($ field ->dataType , ['decimal ' ,'double ' ,'float ' ])
788
+ && isset ($ params [0 ]) && ($ length = intval ($ params [0 ])) > 0
789
+ && isset ($ params [1 ]) && ($ decimal = intval ($ params [1 ])) > 0 )) {
789
790
if (!in_array ('numeric ' , $ field ->validationRules )) {
790
791
$ field ->validationRules [] = 'numeric ' ;
791
792
}
792
793
793
- if (!$ this ->inArraySearch ($ field ->validationRules , 'min ' ) && !is_null ($ minValue = $ field ->getMinValue ()) ) {
794
+ if (!$ this ->inArraySearch ($ field ->validationRules , 'min ' ) && !is_null ($ minValue = $ field ->getMinValue ())) {
794
795
$ field ->validationRules [] = sprintf ('min:%s ' , $ minValue );
795
796
}
796
797
797
- if (!$ this ->inArraySearch ($ field ->validationRules , 'max ' ) && !is_null ($ maxValue = $ field ->getMaxValue ()) ) {
798
+ if (!$ this ->inArraySearch ($ field ->validationRules , 'max ' ) && !is_null ($ maxValue = $ field ->getMaxValue ())) {
798
799
$ field ->validationRules [] = sprintf ('max:%s ' , $ maxValue );
799
800
}
800
801
}
@@ -1000,7 +1001,6 @@ protected function getLabelsFromArray(array $items)
1000
1001
protected function getPlaceholder (Field $ field , array $ properties )
1001
1002
{
1002
1003
if (isset ($ properties ['placeholder ' ]) && !empty ($ properties ['placeholder ' ])) {
1003
-
1004
1004
if (is_array ($ properties ['placeholder ' ])) {
1005
1005
//At this point we know this the label
1006
1006
return $ this ->getLabelsFromArray ($ properties ['placeholder ' ]);
@@ -1013,23 +1013,22 @@ protected function getPlaceholder(Field $field, array $properties)
1013
1013
1014
1014
$ labels = [];
1015
1015
1016
- if (!isset ($ properties ['placeholder ' ])) {
1016
+ if (!isset ($ properties ['placeholder ' ])) {
1017
1017
$ templates = Config::getPlaceholderByHtmlType ();
1018
1018
1019
- foreach ($ templates as $ type => $ title ) {
1020
- if ($ field ->htmlType == $ type ) {
1021
-
1019
+ foreach ($ templates as $ type => $ title ) {
1020
+ if ($ field ->htmlType == $ type ) {
1022
1021
$ fieldName = $ field ->hasForeignRelation () ? $ field ->getForeignRelation ()->name : $ field ->name ;
1023
1022
$ this ->replaceFieldNamePatterns ($ title , $ fieldName );
1024
1023
$ langs = $ field ->getAvailableLanguages ();
1025
1024
1026
- if (count ($ langs ) == 0 ) {
1025
+ if (count ($ langs ) == 0 ) {
1027
1026
return [
1028
1027
new Label ($ title , $ this ->localeGroup , true , $ this ->defaultLang )
1029
1028
];
1030
1029
}
1031
1030
1032
- foreach ($ langs as $ lang ) {
1031
+ foreach ($ langs as $ lang ) {
1033
1032
$ labels [] = new Label ($ title , $ this ->localeGroup , false , $ lang );
1034
1033
}
1035
1034
}
@@ -1219,7 +1218,7 @@ protected function replaceFieldNamePatterns(&$stub, $name)
1219
1218
$ plural = str_plural ($ englishSingle );
1220
1219
1221
1220
$ stub = $ this ->strReplace ('field_name ' , $ englishSingle , $ stub );
1222
- $ stub = $ this ->strReplace ('field_name_flat ' , strtolower ($ name ), $ stub );
1221
+ $ stub = $ this ->strReplace ('field_name_flat ' , strtolower ($ name ), $ stub );
1223
1222
$ stub = $ this ->strReplace ('field_name_sentence ' , ucfirst ($ englishSingle ), $ stub );
1224
1223
$ stub = $ this ->strReplace ('field_name_plural ' , $ plural , $ stub );
1225
1224
$ stub = $ this ->strReplace ('field_name_plural_title ' , title_case ($ plural ), $ stub );
@@ -1230,7 +1229,7 @@ protected function replaceFieldNamePatterns(&$stub, $name)
1230
1229
$ stub = $ this ->strReplace ('field_name_title ' , Helpers::titleCase ($ englishSingle ), $ stub );
1231
1230
$ stub = $ this ->strReplace ('field_name_title_lower ' , strtolower ($ englishSingle ), $ stub );
1232
1231
$ stub = $ this ->strReplace ('field_name_title_upper ' , strtoupper ($ englishSingle ), $ stub );
1233
- $ stub = $ this ->strReplace ('field_name_class ' , $ name , $ stub );
1232
+ $ stub = $ this ->strReplace ('field_name_class ' , $ name , $ stub );
1234
1233
$ stub = $ this ->strReplace ('field_name_plural_variable ' , $ this ->getPluralVariable ($ name ), $ stub );
1235
1234
$ stub = $ this ->strReplace ('field_name_singular_variable ' , $ this ->getSingularVariable ($ name ), $ stub );
1236
1235
0 commit comments