73 lines
2.3 KiB
PHP
73 lines
2.3 KiB
PHP
<?php
|
|
namespace CustomLicenseTypes\DataType;
|
|
|
|
use Omeka\Api\Adapter\AbstractEntityAdapter;
|
|
use Omeka\Api\Representation\ValueRepresentation;
|
|
use Omeka\DataType\Uri;
|
|
use Omeka\Entity\Value;
|
|
use Zend\Form\Element\Select;
|
|
use Zend\View\Renderer\PhpRenderer;
|
|
|
|
class LicenseType extends Uri
|
|
{
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $statements = [
|
|
'https://creativecommons.org/licenses/by/4.0/' => 'Creative Commons CC-BY 4.0',
|
|
'https://creativecommons.org/licenses/by-sa/4.0/' => 'Creative Commons CC-BY-SA 4.0',
|
|
'https://creativecommons.org/licenses/by-nc/4.0/' => 'Creative Commons CC-BY-NC 4.0',
|
|
'https://creativecommons.org/licenses/by-nc-sa/4.0/' => 'Creative Commons CC-BY-NC-SA 4.0',
|
|
'https://creativecommons.org/licenses/by-nd/4.0/' => 'Creative Commons CC-BY-ND 4.0',
|
|
'https://creativecommons.org/licenses/by-nc-nd/4.0/' => 'Creative Commons CC-BY-NC-ND 4.0',
|
|
'https://en.wikipedia.org/wiki/Public_domain' => 'Public domain',
|
|
];
|
|
|
|
public function getName()
|
|
{
|
|
return 'license_type';
|
|
}
|
|
|
|
public function getLabel()
|
|
{
|
|
return 'Custom License Types';
|
|
}
|
|
|
|
public function form(PhpRenderer $view)
|
|
{
|
|
$select = new Select('license-type');
|
|
$select
|
|
->setAttribute('data-value-key', '@id')
|
|
->setEmptyOption('Select Below')
|
|
->setValueOptions($this->statements);
|
|
return $view->formSelect($select);
|
|
|
|
}
|
|
|
|
public function isValid(array $valueObject)
|
|
{
|
|
return parent::isValid($valueObject) && isset($this->statements[$valueObject['@id']]);
|
|
}
|
|
|
|
public function hydrate(array $valueObject, Value $value, AbstractEntityAdapter $adapter)
|
|
{
|
|
$uri = $valueObject['@id'];
|
|
if (isset($this->statements[$uri])) {
|
|
$valueObject['o:label'] = $this->statements[$uri];
|
|
}
|
|
parent::hydrate($valueObject, $value, $adapter);
|
|
}
|
|
|
|
public function render(PhpRenderer $view, ValueRepresentation $value)
|
|
{
|
|
$hyperlink = $view->plugin('hyperlink');
|
|
$escape = $view->plugin('escapeHtml');
|
|
|
|
$uri = $value->uri();
|
|
$uriLabel = $value->value();
|
|
$content = $escape($uriLabel);
|
|
|
|
return $hyperlink->raw($content, $uri, ['class' => 'license-type-link']);
|
|
}
|
|
}
|