55use Kirby \Toolkit \Str ;
66use Kirby \Data \Yaml ;
77
8- function createModuleRegistry () {
8+ function createModuleRegistry ()
9+ {
910
1011 $ registry = ['blueprints ' => [], 'templates ' => [], 'pageModels ' => []];
1112
@@ -18,8 +19,8 @@ function createModuleRegistry() {
1819 // ----------------------------------------------------------------------
1920
2021 foreach (Dir::dirs ($ modulesFolder ) as $ folder ) {
21- $ blueprintPath = $ modulesFolder . "/ " . $ folder . "/ " . $ folder . ".yml " ;
22- $ templatePath = $ modulesFolder . "/ " . $ folder . "/ " . $ folder . ".php " ;
22+ $ blueprintPath = $ modulesFolder . "/ " . $ folder . "/ " . $ folder . ".yml " ;
23+ $ templatePath = $ modulesFolder . "/ " . $ folder . "/ " . $ folder . ".php " ;
2324 $ registry = addToModulesRegistry ($ registry , $ folder , $ blueprintPath , $ templatePath );
2425 }
2526
@@ -41,14 +42,14 @@ function createModuleRegistry() {
4142 // Legacy registry (deprecated)
4243 // ----------------------------------------------------------------------
4344
44- $ moduleBlueprints = array_filter (kirby ()->blueprints (), function ($ blueprint ) {
45+ $ moduleBlueprints = array_filter (kirby ()->blueprints (), function ($ blueprint ) {
4546 return Str::startsWith ($ blueprint , 'module. ' );
4647 });
4748
4849 // Check if there are any module blueprints and throw a deprecation warning
49- if (count ($ moduleBlueprints )) {
50+ if (count ($ moduleBlueprints )) {
5051 deprecated ('This folder structure is deprecated. Please move your module blueprints to site/blueprints/modules/ and your module templates to site/snippets/modules/. ' );
51- foreach ($ moduleBlueprints as $ moduleBlueprint ) {
52+ foreach ($ moduleBlueprints as $ moduleBlueprint ) {
5253 $ blueprintPath = $ blueprintsFolder . "/pages/ " . $ moduleBlueprint . ".yml " ;
5354 $ templatePath = $ snippetsFolder . "/modules/ " . $ moduleBlueprint . ".php " ;
5455 $ registry = addToModulesRegistry ($ registry , $ moduleBlueprint , $ blueprintPath , $ templatePath );
@@ -60,16 +61,17 @@ function createModuleRegistry() {
6061 // ----------------------------------------------------------------------
6162
6263 $ blueprintNames = array_keys ($ registry ['blueprints ' ]);
63- $ blueprintNames = array_map (function ($ blueprintName ) {
64+ $ blueprintNames = array_map (function ($ blueprintName ) {
6465 return Str::replace ($ blueprintName , 'pages/ ' , '' );
6566 }, $ blueprintNames );
6667
67- foreach ($ registry ['blueprints ' ] as &$ blueprint ) {
68- if (
68+ foreach ($ registry ['blueprints ' ] as &$ blueprint ) {
69+ if (
6970 !isset ($ blueprint ['options ' ]) ||
7071 (
71- is_array ($ blueprint ['options ' ]) && !isset ($ blueprint ['options ' ]['changeTemplate ' ]
72- ))
72+ is_array ($ blueprint ['options ' ]) && !isset (
73+ $ blueprint ['options ' ]['changeTemplate ' ]
74+ ))
7375 ) {
7476 $ blueprint ['options ' ]['changeTemplate ' ] = $ blueprintNames ;
7577 }
@@ -78,7 +80,7 @@ function createModuleRegistry() {
7880 // ----------------------------------------------------------------------
7981 // Add modules container blueprint with pages section and redirect field
8082 // ----------------------------------------------------------------------
81-
83+
8284 $ registry ['blueprints ' ]['pages/modules ' ] = [
8385 'title ' => 'Modules ' ,
8486 'options ' => [
@@ -97,34 +99,34 @@ function createModuleRegistry() {
9799 ]
98100 ],
99101 ];
100-
102+
101103 // ----------------------------------------------------------------------
102104 // Add modules container model
103105 // ----------------------------------------------------------------------
104106
105107 $ registry ['pageModels ' ]['modules ' ] = 'ModulesPage ' ;
106108
107109 return $ registry ;
108-
109110}
110111
111- function addToModulesRegistry (array $ registry , string $ name , string $ blueprintPath , string $ templatePath ) {
112+ function addToModulesRegistry (array $ registry , string $ name , string $ blueprintPath , string $ templatePath )
113+ {
112114
113115 // Check if blueprint already exists in registry
114- if (array_key_exists ('pages/module. ' . $ name , $ registry ['blueprints ' ])) {
116+ if (array_key_exists ('pages/module. ' . $ name , $ registry ['blueprints ' ])) {
115117 return ;
116118 }
117119
118120 // Check if blueprint exists
119- if (!F::exists ($ blueprintPath )) {
121+ if (!F::exists ($ blueprintPath )) {
120122 return ;
121123 }
122124
123125 // Turn the blueprint into an array
124126 $ blueprintArray = Yaml::read ($ blueprintPath );
125127
126128 // Set up default values for status and navigation
127- if (!array_key_exists ('status ' , $ blueprintArray )) {
129+ if (!array_key_exists ('status ' , $ blueprintArray )) {
128130 $ blueprintArray ['status ' ] = [
129131 'draft ' => [
130132 'text ' => false
@@ -134,34 +136,36 @@ function addToModulesRegistry(array $registry, string $name, string $blueprintPa
134136 ]
135137 ];
136138 }
137- if (!array_key_exists ('navigation ' , $ blueprintArray )) {
139+ if (!array_key_exists ('navigation ' , $ blueprintArray )) {
138140 $ blueprintArray ['navigation ' ] = ['status ' => 'all ' , 'template ' => 'all ' ];
139141 }
142+ if (!array_key_exists ('icon ' , $ blueprintArray )) {
143+ $ blueprintArray ['icon ' ] = "box " ;
144+ }
140145
141146 // Adjust the create blueprint option if it doesn't exist
142- if (!array_key_exists ('create ' , $ blueprintArray )) {
147+ if (!array_key_exists ('create ' , $ blueprintArray )) {
143148
144149 $ blueprintArray ['create ' ] = [];
145150
146151 // Add slug field if autoslug is enabled
147- if (option ('medienbaecker.modules.autoslug ' ) === true ) {
152+ if (option ('medienbaecker.modules.autoslug ' ) === true ) {
148153 $ blueprintArray ['create ' ]['slug ' ] = '{{ page.uniqueModuleSlug }} ' ;
149154 }
150155
151156 // Set status to listed if autopublish is enabled
152- if (option ('medienbaecker.modules.autopublish ' ) === true ) {
157+ if (option ('medienbaecker.modules.autopublish ' ) === true ) {
153158 $ blueprintArray ['create ' ]['status ' ] = 'listed ' ;
154159 }
155160
156161 // Disable redirect if the redirect option is not explicitely set to true
157- if (option ('medienbaecker.modules.redirect ' ) !== true ) {
162+ if (option ('medienbaecker.modules.redirect ' ) !== true ) {
158163 $ blueprintArray ['create ' ]['redirect ' ] = false ;
159164 }
160-
161165 }
162166
163167 // Add module prefix to blueprint name
164- if (Str::startsWith ($ name , 'module. ' ) === false ) {
168+ if (Str::startsWith ($ name , 'module. ' ) === false ) {
165169 $ name = 'module. ' . $ name ;
166170 }
167171
@@ -171,5 +175,4 @@ function addToModulesRegistry(array $registry, string $name, string $blueprintPa
171175 $ registry ['pageModels ' ][$ name ] = option ('medienbaecker.modules.model ' , 'ModulePage ' );
172176
173177 return $ registry ;
174-
175- }
178+ }
0 commit comments