first commit

This commit is contained in:
buttle 2021-05-17 21:58:27 +02:00
commit e999f52e86
10 changed files with 257 additions and 0 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Neo-Inspiration
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

16
Module.php Normal file
View File

@ -0,0 +1,16 @@
<?php
namespace HeaderImage;
use Omeka\Module\AbstractModule;
use Laminas\EventManager\SharedEventManagerInterface;
use Laminas\Mvc\MvcEvent;
class Module extends AbstractModule
{
const NAMESPACE = __NAMESPACE__;
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}

21
README.md Normal file
View File

@ -0,0 +1,21 @@
# HeaderImage media for Omeka S
[HeaderImage] is a module for [Omeka S] arcHIVE theme that adds
an image to the page above the main menu.
## Install
```
cd ./modules
https://git.hangar.org/arcHIVE-tech/HeaderImage-omeka-module/archive/main.zip
unzip main.zip
mv headerimage/ HeaderImage
rm main.zip
```
## LISENCE
The module is released under the [MIT] License.
[arc-hive]: https://arc-hive.zone/
[Omeka S]: https://omeka.org/s
[MIT]: http://opensource.org/licenses/MIT

30
config/module.config.php Normal file
View File

@ -0,0 +1,30 @@
<?php
namespace HeaderImage;
return [
'view_manager' => [
'template_path_stack' => [
dirname(__DIR__) . '/view',
]
],
'view_helpers' => [
'factories' => [
'headerImage' => Service\ViewHelper\HeaderImageViewHelperFactory::class,
],
],
'block_layouts' => [
'factories' => [
'headerImage' => Service\BlockLayout\HeaderImageFactory::class,
],
],
'form_elements' => [
'invokables' => [
Form\HeaderImageBlockForm::class => Form\HeaderImageBlockForm::class,
],
],
'DefaultSettings' => [
'HeaderImageBlockForm' => [
'wrapStyle' => 'overflow-y: hidden;display: flex;flex-direction: column;justify-content: center;',
]
]
];

12
config/module.ini Normal file
View File

@ -0,0 +1,12 @@
[info]
name = "arcHIVE theme header image"
description = "Each page displays this image above the main menu"
tags = ""
license = "MIT"
author = "Hangar.org"
author_link = "https://git.hangar.org/chris"
module_link = "https://git.hangar.org/arcHIVE-tech/HeaderImage"
support_link = "https://git.hangar.org/arcHIVE-tech/HeaderImage/issues"
configurable = false
version = "1.0.0"
omeka_version_constraint = "^3.0.1"

View File

@ -0,0 +1,14 @@
<?php
namespace HeaderImage\Form;
use HeaderImage\Module;
use Laminas\Form\Element;
use Laminas\Form\Form;
class HeaderImageBlockForm extends Form
{
public function init()
{
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace HeaderImage\Service\BlockLayout;
use Interop\Container\ContainerInterface;
use HeaderImage\Site\BlockLayout\HeaderImage;
use Laminas\ServiceManager\Factory\FactoryInterface;
class HeaderImageFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $services, $requestedName, array $options = null)
{
return new HeaderImage(
$services->get('FormElementManager'),
$services->get('Config')['DefaultSettings']['HeaderImageBlockForm']
);
}
}
?>

View File

@ -0,0 +1,17 @@
<?php
namespace HeaderImage\Service\ViewHelper;
use HeaderImage\View\Helper;
use Zend\ServiceManager\Factory\FactoryInterface;
use Interop\Container\ContainerInterface;
use HeaderImage\View\Helper\HeaderImageViewHelper;
class HeaderImageViewHelperFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $services, $requestedName, array $options = null)
{
$config = $services->get('Config');
return new HeaderImageViewHelper($services->get('Omeka\Settings'));
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace HeaderImage\Site\BlockLayout;
use Omeka\Api\Representation\SiteRepresentation;
use Omeka\Api\Representation\SitePageRepresentation;
use Omeka\Api\Representation\SitePageBlockRepresentation;
use Omeka\Site\BlockLayout\AbstractBlockLayout;
use Laminas\View\Renderer\PhpRenderer;
use Laminas\Form\FormElementManager;
use HeaderImage\Form\HeaderImageBlockForm;
class HeaderImage extends AbstractBlockLayout
{
/**
* @var FormElementManager
*/
protected $formElementManager;
/**
* @var array
*/
protected $defaultSettings = [];
/**
* @param FormElementManager $formElementManager
* @param array $defaultSettings
*/
public function __construct(FormElementManager $formElementManager, array $defaultSettings)
{
$this->formElementManager = $formElementManager;
$this->defaultSettings = $defaultSettings;
}
public function getLabel() {
return 'Header image';
}
public function form(PhpRenderer $view,
SiteRepresentation $site,
SitePageRepresentation $page = null,
SitePageBlockRepresentation $block = null
) {
$form = $this->formElementManager->get(HeaderImageBlockForm::class);
$form->prepare();
$html = '';
$html .= $view->blockAttachmentsForm($block);
//$html .= '<a href="#" class="collapse" aria-label="collapse"><h4>';
//$html .= $view->translate('Options'). '</h4></a>';
//$html .= '<div class="collapsible" style="padding-top:6px;">';
//$html .= $view->formCollection($form);
//$html .= '</div>';
return $html;
}
public function render(PhpRenderer $view, SitePageBlockRepresentation $block)
{
return "";
}
}

View File

@ -0,0 +1,46 @@
<?php declare(strict_types=1);
namespace HeaderImage\View\Helper;
use Laminas\View\Helper\AbstractHelper;
/**
* View helper to get metadata for all pages of the specified type.
*/
class HeaderImageViewHelper extends AbstractHelper
{
public function __construct($omekaSettings) #, $siteSettings)
{
$this->omekaSettings = $omekaSettings;
}
/**
* Get the page's meta image url.
*
* @param SitePageRepresentation
* @return string media url
*/
public function getImage($page)
{
foreach ($page->blocks() as $block) {
if ($block->layout() === 'headerImage') {
$attachments = $block->attachments();
$media = $attachments[0]->item()->media()[0];
return $media->primaryMedia()->thumbnailUrl('large');
}
}
$site = $this->currentSite();
return $this->getView()->getHelperPluginManager()->get('archiveSiteMeta')->getSiteImage($site);
}
/**
* @return \Omeka\Api\Representation\SiteRepresentation
*/
protected function currentSite()
{
$view = $this->getView();
return isset($view->site)
? $view->site
: $view->getHelperPluginManager()->get('Laminas\View\Helper\ViewModel')->getRoot()->getVariable('site');
}
}