@@ -83,53 +83,60 @@ public static function fromString($str, $localeGroup = 'generic', array $languag
8383 // OR
8484 // name:a;html-type:select;options:first|second|third|fourth
8585 $ fields = [];
86- $ fieldNames = array_unique (Helpers::convertStringToArray ($ str ));
86+ $ fieldNames = array_unique (Helpers::convertStringToArray ($ str, ' , ' ));
8787
8888 foreach ($ fieldNames as $ fieldName ) {
8989 $ field = [];
9090
91- if (str_contains ($ fieldName , ': ' )) {
92- // Handle the following format
93- // name:a;html-type:select;options:first|second|third|fourth
94- if (!str_is ('*name*:* ' , $ fieldName )) {
95- throw new Exception ('The "name" property was not provided and is required! ' );
96- }
97-
98- $ parts = Helpers::convertStringToArray ($ fieldName , '; ' );
91+ if (!str_contains ($ fieldName , ': ' )) {
92+
93+ $ field ['name ' ] = $ fieldName ;
94+
95+ continue ;
96+ }
97+
98+ // Handle the following format
99+ // name:a;html-type:select;options:first|second|third|fourth
100+ if (!str_is ('*name*:* ' , $ fieldName )) {
101+ throw new Exception ('The "name" property was not provided and is required! ' );
102+ }
103+
104+ $ parts = Helpers::convertStringToArray ($ fieldName , '; ' );
105+
106+ foreach ($ parts as $ part ) {
107+
108+ if (!str_is ('*:* ' , $ part ) || count ($ properties = Helpers::convertStringToArray ($ part , ': ' , 2 )) != 2 ) {
109+ throw new Exception ('Each provided property should use the following format "key:value" ' );
110+ }
111+ list ($ key , $ value ) = $ properties ;
112+
113+ // The renations uses # as a delimiter
114+ $ selfParts = Helpers::convertStringToArray ($ value , '# ' );
115+
116+ if (LaravelStr::startsWith ($ key , 'is- ' )){
117+ $ field [$ key ] = Helpers::stringToBool ($ value );
118+ } else {
119+ $ field [$ key ] = count ($ selfParts ) > 1 ? $ selfParts : $ value ;
120+ }
121+
122+
123+ if ($ key == 'options ' ) {
124+ $ options = Helpers::convertStringToArray ($ value , '| ' );
99125
100- foreach ($ parts as $ part ) {
101- if (!str_is ('*:* ' , $ part ) || count ($ properties = Helpers::convertStringToArray ($ part , ': ' )) < 2 ) {
102- throw new Exception ('Each provided property should use the following format "key:value" ' );
103- }
104- list ($ key , $ value ) = $ properties ;
105-
106- if (LaravelStr::startsWith ($ key , 'is- ' )){
107- $ field [$ key ] = Helpers::stringToBool ($ value );
108- } else {
109- $ field [$ key ] = $ value ;
126+ if (count ($ options ) == 0 ) {
127+ throw new Exception ('You must provide at least one option where each option is seperated by "|". ' );
110128 }
111-
112-
113- if ($ key == 'options ' ) {
114- $ options = Helpers::convertStringToArray ($ value , '| ' );
115129
116- if (count ($ options ) == 0 ) {
117- throw new Exception ('You must provide at least one option where each option is seperated by "|". ' );
118- }
119-
120- $ field ['options ' ] = [];
121- foreach ($ options as $ option ) {
122- $ field ['options ' ][$ option ] = $ option ;
123- }
124- }
125- }
126- } else {
127- $ field ['name ' ] = $ fieldName ;
128- }
130+ $ field ['options ' ] = [];
131+ foreach ($ options as $ option ) {
132+ $ field ['options ' ][$ option ] = $ option ;
133+ }
134+ }
135+ }
129136
130137 $ fields [] = $ field ;
131138 }
132-
139+
133140 return self ::fromArray ($ fields , $ localeGroup , $ languages , $ isReadOnly );
134141 }
135142
@@ -170,7 +177,7 @@ protected function __construct(array $properties, $localeGroup, array $languages
170177 $ this ->localeGroup = $ localeGroup ;
171178 $ this ->languages = array_unique ($ languages );
172179 $ this ->isReadOnly = $ isReadOnly ;
173- }
180+ }
174181
175182 /**
176183 * It get the fields collection
@@ -209,7 +216,7 @@ protected function transfer()
209216 }
210217
211218 $ field = Field::fromArray ($ properties , $ this ->localeGroup , $ this ->languages );
212-
219+
213220 $ mappers [] = new FieldMapper ($ field , (array ) $ rawField );
214221 }
215222
@@ -275,7 +282,7 @@ protected function setOptions(&$properties)
275282 public function presetProperties (array &$ properties )
276283 {
277284 $ definitions = Config::getCommonDefinitions ();
278-
285+
279286 foreach ($ definitions as $ definition ) {
280287 $ patterns = $ this ->getArrayByKey ($ definition , 'match ' );
281288
0 commit comments