Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme provided resource page block layouts #2204

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 18 additions & 0 deletions application/src/ServiceManager/AbstractPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ public function __construct($configOrContainerInterface = null, array $v3config
}
}

/**
* Register service names that were set via setFactory().
*/
public function setFactory($name, $factory)
{
parent::setFactory($name, $factory);
$this->registeredNames[$name] = $name;
}

/**
* Register service names that were set via setInvokableClass().
*/
public function setInvokableClass($name, $class = null)
{
parent::setInvokableClass($name, $factory);
$this->registeredNames[$name] = $name;
}

/**
* Set the registered names.
*
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]);
}
}
Loading