@@ -112,8 +112,12 @@ public function getBlock(Tree $tree, int $block_id, string $context, array $conf
112112 $ title = $ module ->chartTitle ($ individual );
113113 $ chart_url = $ module ->chartUrl ($ individual , [
114114 'ajax ' => true ,
115- 'generations ' => 3 ,
116- 'layout ' => PedigreeChartModule::STYLE_RIGHT ,
115+ 'generations ' => $ this ->getBlockSetting ($ block_id , 'pedigree_generations ' , '3 ' ),
116+ 'layout ' => $ this ->getBlockSetting ($ block_id , 'pedigree_style ' ,
117+ PedigreeChartModule::DEFAULT_STYLE ),
118+ 'style ' => $ this ->getBlockSetting ($ block_id , 'pedigree_style ' ,
119+ PedigreeChartModule::DEFAULT_STYLE ),
120+ // Note: some modules use 'layout', others 'style'
117121 ]);
118122 $ content = view ('modules/charts/chart ' , [
119123 'block_id ' => $ block_id ,
@@ -132,7 +136,7 @@ public function getBlock(Tree $tree, int $block_id, string $context, array $conf
132136 $ title = $ module ->chartTitle ($ individual );
133137 $ chart_url = $ module ->chartUrl ($ individual , [
134138 'ajax ' => true ,
135- 'generations ' => 2 ,
139+ 'generations ' => $ this -> getBlockSetting ( $ block_id , ' descendants_generations ' , ' 2 ' ) ,
136140 'chart_style ' => DescendancyChartModule::CHART_STYLE_TREE ,
137141 ]);
138142 $ content = view ('modules/charts/chart ' , [
@@ -153,7 +157,7 @@ public function getBlock(Tree $tree, int $block_id, string $context, array $conf
153157 $ title = $ module ->chartTitle ($ individual );
154158 $ chart_url = $ module ->chartUrl ($ individual , [
155159 'ajax ' => true ,
156- 'generations ' => 2 ,
160+ 'generations ' => $ this -> getBlockSetting ( $ block_id , ' hourglass_generations ' , ' 2 ' ) ,
157161 ]);
158162 $ content = view ('modules/charts/chart ' , [
159163 'block_id ' => $ block_id ,
@@ -231,9 +235,17 @@ public function saveBlockConfiguration(ServerRequestInterface $request, int $blo
231235 {
232236 $ type = Validator::parsedBody ($ request )->string ('type ' );
233237 $ xref = Validator::parsedBody ($ request )->isXref ()->string ('xref ' );
238+ $ pedigree_generations = Validator::parsedBody ($ request )->integer ('pedigree_generations ' );
239+ $ pedigree_style = Validator::parsedBody ($ request )->string ('pedigree_style ' );
240+ $ descendants_generations = Validator::parsedBody ($ request )->integer ('descendants_generations ' );
241+ $ hourglass_generations = Validator::parsedBody ($ request )->integer ('hourglass_generations ' );
234242
235243 $ this ->setBlockSetting ($ block_id , 'type ' , $ type );
236244 $ this ->setBlockSetting ($ block_id , 'pid ' , $ xref );
245+ $ this ->setBlockSetting ($ block_id , 'pedigree_generations ' , (string ) $ pedigree_generations );
246+ $ this ->setBlockSetting ($ block_id , 'pedigree_style ' , $ pedigree_style );
247+ $ this ->setBlockSetting ($ block_id , 'descendants_generations ' , (string ) $ descendants_generations );
248+ $ this ->setBlockSetting ($ block_id , 'hourglass_generations ' , (string ) $ hourglass_generations );
237249 }
238250
239251 /**
@@ -253,21 +265,56 @@ public function editBlockConfiguration(Tree $tree, int $block_id): string
253265 $ type = $ this ->getBlockSetting ($ block_id , 'type ' , 'pedigree ' );
254266 $ xref = $ this ->getBlockSetting ($ block_id , 'pid ' , $ default_xref );
255267
256- $ charts = [
257- 'pedigree ' => I18N ::translate ('Pedigree ' ),
258- 'descendants ' => I18N ::translate ('Descendants ' ),
259- 'hourglass ' => I18N ::translate ('Hourglass chart ' ),
260- 'treenav ' => I18N ::translate ('Interactive tree ' ),
261- ];
268+ $ charts = [];
269+ // Only add charts that are available
270+ $ pedigreeModule = $ this ->module_service ->findByInterface (PedigreeChartModule::class)->first ();
271+ if ($ pedigreeModule instanceof PedigreeChartModule) {
272+ $ charts ['pedigree ' ] = I18N ::translate ('Pedigree ' );
273+ $ pedigree_max_generations = $ pedigreeModule ::MAXIMUM_GENERATIONS ;
274+ $ pedigree_min_generations = $ pedigreeModule ::MINIMUM_GENERATIONS ;
275+ $ pedigree_styles = $ pedigreeModule ->styles (I18N ::direction ());
276+ }
277+ $ descendantsModule = $ this ->module_service ->findByInterface (DescendancyChartModule::class)->first ();
278+ if ($ descendantsModule instanceof DescendancyChartModule) {
279+ $ charts ['descendants ' ] = I18N ::translate ('Descendants ' );
280+ $ descendants_max_generations = $ descendantsModule ::MAXIMUM_GENERATIONS ;
281+ $ descendants_min_generations = $ descendantsModule ::MINIMUM_GENERATIONS ;
282+ }
283+ $ hourglassModule = $ this ->module_service ->findByInterface (HourglassChartModule::class)->first ();
284+ if ($ hourglassModule instanceof HourglassChartModule) {
285+ $ charts ['hourglass ' ] = I18N ::translate ('Hourglass chart ' );
286+ $ hourglass_max_generations = $ hourglassModule ::MAXIMUM_GENERATIONS ;
287+ $ hourglass_min_generations = $ hourglassModule ::MINIMUM_GENERATIONS ;
288+ }
289+ $ treeModule = $ this ->module_service ->findByInterface (InteractiveTreeModule::class)->first ();
290+ if ($ treeModule instanceof InteractiveTreeModule) {
291+ $ charts ['treenav ' ] = I18N ::translate ('Interactive tree ' );
292+ }
262293 uasort ($ charts , I18N ::comparator ());
263294
295+ $ pedigree_generations = $ this ->getBlockSetting ($ block_id , 'pedigree_generations ' , '3 ' );
296+ $ pedigree_style = $ this ->getBlockSetting ($ block_id , 'pedigree_style ' , $ pedigreeModule ::DEFAULT_STYLE );
297+ $ descendants_generations = $ this ->getBlockSetting ($ block_id , 'descendants_generations ' , '2 ' );
298+ $ hourglass_generations = $ this ->getBlockSetting ($ block_id , 'hourglass_generations ' , '2 ' );
299+
264300 $ individual = Registry::individualFactory ()->make ($ xref , $ tree );
265301
266302 return view ('modules/charts/config ' , [
267- 'charts ' => $ charts ,
268- 'individual ' => $ individual ,
269- 'tree ' => $ tree ,
270- 'type ' => $ type ,
303+ 'charts ' => $ charts ,
304+ 'individual ' => $ individual ,
305+ 'tree ' => $ tree ,
306+ 'type ' => $ type ,
307+ 'pedigree_generations ' => $ pedigree_generations ?? null ,
308+ 'pedigree_max_generations ' => $ pedigree_max_generations ?? null ,
309+ 'pedigree_min_generations ' => $ pedigree_min_generations ?? null ,
310+ 'pedigree_style ' => $ pedigree_style ?? null ,
311+ 'pedigree_styles ' => $ pedigree_styles ?? null ,
312+ 'descendants_generations ' => $ descendants_generations ?? null ,
313+ 'descendants_max_generations ' => $ descendants_max_generations ?? null ,
314+ 'descendants_min_generations ' => $ descendants_min_generations ?? null ,
315+ 'hourglass_generations ' => $ hourglass_generations ?? null ,
316+ 'hourglass_max_generations ' => $ hourglass_max_generations ?? null ,
317+ 'hourglass_min_generations ' => $ hourglass_min_generations ?? null ,
271318 ]);
272319 }
273320}
0 commit comments