Skip to content

Commit

Permalink
Merge pull request #2204 from omeka/theme-provided-resource-page-bloc…
Browse files Browse the repository at this point in the history
…k-layouts

Theme provided resource page block layouts
  • Loading branch information
zerocrates committed Jul 2, 2024
2 parents 8a920c8 + fcacc9a commit 51b00b5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
18 changes: 18 additions & 0 deletions application/src/Mvc/MvcListeners.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
namespace Omeka\Site\ResourcePageBlockLayout;

use Omeka\Api\Representation\AbstractResourceEntityRepresentation;
use Laminas\View\Renderer\PhpRenderer;

class ThemeProvidedResourcePageBlockLayout implements ResourcePageBlockLayoutInterface
{
protected $label;
protected $compatibleResourceNames;
protected $partial;

public function __construct($label, $compatibleResourceNames, $partial)
{
$this->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]);
}
}

0 comments on commit 51b00b5

Please sign in to comment.