diff --git a/application/src/Mvc/MvcListeners.php b/application/src/Mvc/MvcListeners.php index 785cb56e1..5c95eddd8 100644 --- a/application/src/Mvc/MvcListeners.php +++ b/application/src/Mvc/MvcListeners.php @@ -3,6 +3,7 @@ use Omeka\Service\Delegator\SitePaginatorDelegatorFactory; use Omeka\Session\SaveHandler\Db; +use Omeka\Site\ResourcePageBlockLayout\ThemeProvidedResourcePageBlockLayout; use Omeka\Site\Theme\Manager; use Omeka\Site\Theme\Theme; use Laminas\EventManager\EventManagerInterface; @@ -428,6 +429,23 @@ protected function prepareSite(MvcEvent $event) '%s.mo' ); } + + // Set theme-provided resource page block layouts. + $configSpec = $currentTheme->getConfigSpec(); + $layouts = $configSpec['resource_page_block_layouts'] ?? []; + $layouts = is_array($layouts) ? $layouts : []; + $layouts = array_filter($layouts, function ($layout) { + return isset($layout['label']) && is_string($layout['label']) + && isset($layout['compatible_resource_names']) && is_array($layout['compatible_resource_names']) + && isset($layout['partial']) && is_string($layout['partial']); + }); + foreach ($layouts as $layoutName => $layoutSpec) { + $factory = function ($services) use ($currentTheme, $layoutSpec) { + return new ThemeProvidedResourcePageBlockLayout($layoutSpec['label'], $layoutSpec['compatible_resource_names'], $layoutSpec['partial']); + }; + $services->get('Omeka\ResourcePageBlockLayoutManager')->setFactory($layoutName, $factory); + } + return $site; } diff --git a/application/src/Site/ResourcePageBlockLayout/ThemeProvidedResourcePageBlockLayout.php b/application/src/Site/ResourcePageBlockLayout/ThemeProvidedResourcePageBlockLayout.php new file mode 100644 index 000000000..0aeaf7c64 --- /dev/null +++ b/application/src/Site/ResourcePageBlockLayout/ThemeProvidedResourcePageBlockLayout.php @@ -0,0 +1,34 @@ +label = $label; + $this->compatibleResourceNames = $compatibleResourceNames; + $this->partial = $partial; + } + + public function getLabel() : string + { + return $this->label; + } + + public function getCompatibleResourceNames() : array + { + return $this->compatibleResourceNames; + } + + public function render(PhpRenderer $view, AbstractResourceEntityRepresentation $resource) : string + { + return $view->partial(sprintf('common/resource-page-block-layout/%s', $this->partial), ['resource' => $resource]); + } +}