summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Roach <greg@subaqua.co.uk>2021-01-04 09:08:49 +0000
committerGreg Roach <greg@subaqua.co.uk>2021-01-04 09:08:49 +0000
commit406008aabe7f8cac73fbad8023ca83aa579c0c99 (patch)
treebeb7e44805318c0283fa14e2aefe18bb2ea54432
parent2e84ab20039c9d1e59e1b3c391771ea6d1d60554 (diff)
downloadwebtrees-406008aabe7f8cac73fbad8023ca83aa579c0c99.tar.gz
webtrees-406008aabe7f8cac73fbad8023ca83aa579c0c99.tar.bz2
webtrees-406008aabe7f8cac73fbad8023ca83aa579c0c99.zip
Fix: #3650 - charts block errors when chart is disabled
-rw-r--r--app/Module/ChartsBlockModule.php113
1 files changed, 70 insertions, 43 deletions
diff --git a/app/Module/ChartsBlockModule.php b/app/Module/ChartsBlockModule.php
index 3f9072f83a..4c3997955e 100644
--- a/app/Module/ChartsBlockModule.php
+++ b/app/Module/ChartsBlockModule.php
@@ -20,16 +20,22 @@ declare(strict_types=1);
namespace Fisharebest\Webtrees\Module;
use Fisharebest\Webtrees\Auth;
-use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Module\InteractiveTree\TreeView;
+use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Services\ModuleService;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\User;
use Illuminate\Support\Str;
use Psr\Http\Message\ServerRequestInterface;
+use function extract;
+use function uasort;
+use function view;
+
+use const EXTR_OVERWRITE;
+
/**
* Class ChartsBlockModule
*/
@@ -103,59 +109,80 @@ class ChartsBlockModule extends AbstractModule implements ModuleBlockInterface
switch ($type) {
default:
case 'pedigree':
- /** @var PedigreeChartModule $module */
- $module = $this->module_service->findByInterface(PedigreeChartModule::class)->first();
- $title = $module->chartTitle($individual);
- $chart_url = $module->chartUrl($individual, [
- 'ajax' => true,
- 'generations' => 3,
- 'layout' => PedigreeChartModule::STYLE_RIGHT,
- ]);
- $content = view('modules/charts/chart', [
- 'block_id' => $block_id,
- 'chart_url' => $chart_url,
- 'class' => 'wt-chart-pedigree',
- ]);
+ $module = $this->module_service->findByInterface(PedigreeChartModule::class)->first();
+ if ($module instanceof PedigreeChartModule) {
+ $title = $module->chartTitle($individual);
+ $chart_url = $module->chartUrl($individual, [
+ 'ajax' => true,
+ 'generations' => 3,
+ 'layout' => PedigreeChartModule::STYLE_RIGHT,
+ ]);
+ $content = view('modules/charts/chart', [
+ 'block_id' => $block_id,
+ 'chart_url' => $chart_url,
+ 'class' => 'wt-chart-pedigree',
+ ]);
+ } else {
+ $title = I18N::translate('Pedigree');
+ $content = I18N::translate('The module “%s” has been disabled.', $title);
+ }
break;
case 'descendants':
- /** @var DescendancyChartModule $module */
- $module = $this->module_service->findByInterface(DescendancyChartModule::class)->first();
- $title = $module->chartTitle($individual);
- $chart_url = $module->chartUrl($individual, [
- 'ajax' => true,
- 'generations' => 2,
- 'chart_style' => DescendancyChartModule::CHART_STYLE_TREE,
- ]);
- $content = view('modules/charts/chart', [
- 'block_id' => $block_id,
- 'chart_url' => $chart_url,
- 'class' => 'wt-chart-descendants',
- ]);
+ $module = $this->module_service->findByInterface(DescendancyChartModule::class)->first();
+
+ if ($module instanceof DescendancyChartModule) {
+ $title = $module->chartTitle($individual);
+ $chart_url = $module->chartUrl($individual, [
+ 'ajax' => true,
+ 'generations' => 2,
+ 'chart_style' => DescendancyChartModule::CHART_STYLE_TREE,
+ ]);
+ $content = view('modules/charts/chart', [
+ 'block_id' => $block_id,
+ 'chart_url' => $chart_url,
+ 'class' => 'wt-chart-descendants',
+ ]);
+ } else {
+ $title = I18N::translate('Descendants');
+ $content = I18N::translate('The module “%s” has been disabled.', $title);
+ }
+
break;
case 'hourglass':
- /** @var HourglassChartModule $module */
$module = $this->module_service->findByInterface(HourglassChartModule::class)->first();
- $title = $module->chartTitle($individual);
- $chart_url = $module->chartUrl($individual, [
- 'ajax' => true,
- 'generations' => 2,
- ]);
- $content = view('modules/charts/chart', [
- 'block_id' => $block_id,
- 'chart_url' => $chart_url,
- 'class' => 'wt-chart-hourglass',
- ]);
+
+ if ($module instanceof HourglassChartModule) {
+ $title = $module->chartTitle($individual);
+ $chart_url = $module->chartUrl($individual, [
+ 'ajax' => true,
+ 'generations' => 2,
+ ]);
+ $content = view('modules/charts/chart', [
+ 'block_id' => $block_id,
+ 'chart_url' => $chart_url,
+ 'class' => 'wt-chart-hourglass',
+ ]);
+ } else {
+ $title = I18N::translate('Hourglass chart');
+ $content = I18N::translate('The module “%s” has been disabled.', $title);
+ }
break;
case 'treenav':
- /** @var InteractiveTreeModule $module */
$module = $this->module_service->findByInterface(InteractiveTreeModule::class)->first();
- $title = I18N::translate('Interactive tree of %s', $individual->fullName());
- $tv = new TreeView();
- [$html, $js] = $tv->drawViewport($individual, 2);
- $content = $html . '<script>' . $js . '</script>';
+
+ if ($module instanceof InteractiveTreeModule) {
+ $title = I18N::translate('Interactive tree of %s', $individual->fullName());
+ $tv = new TreeView();
+ [$html, $js] = $tv->drawViewport($individual, 2);
+ $content = $html . '<script>' . $js . '</script>';
+ } else {
+ $title = I18N::translate('Interactive tree');
+ $content = I18N::translate('The module “%s” has been disabled.', $title);
+ }
+
break;
}
} else {