91 lines
2.6 KiB
PHP
91 lines
2.6 KiB
PHP
|
<?php
|
||
|
namespace Vimeo\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 Vimeo\Form\VimeoBlockForm;
|
||
|
|
||
|
class Vimeo 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 'Vimeo model';
|
||
|
}
|
||
|
|
||
|
public function form(PhpRenderer $view,
|
||
|
SiteRepresentation $site,
|
||
|
SitePageRepresentation $page = null,
|
||
|
SitePageBlockRepresentation $block = null
|
||
|
) {
|
||
|
$form = $this->formElementManager->get(VimeoBlockForm::class);
|
||
|
$data = $block
|
||
|
? $block->data() + $this->defaultSettings
|
||
|
: $this->defaultSettings;
|
||
|
$form->setData([
|
||
|
'o:block[__blockIndex__][o:data][title]' => $data['title'],
|
||
|
'o:block[__blockIndex__][o:data][width]' => $data['width'],
|
||
|
'o:block[__blockIndex__][o:data][ratio]' => $data['ratio'],
|
||
|
'o:block[__blockIndex__][o:data][renderSourceLink]' => $data['renderSourceLink'],
|
||
|
]);
|
||
|
$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)
|
||
|
{
|
||
|
$attachments = $block->attachments();
|
||
|
if (!$attachments) {
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
$thumbnails = [];
|
||
|
static $id = 0;
|
||
|
|
||
|
$media = $attachments[0]->item()->media()[0];
|
||
|
$width = 900;
|
||
|
//$height = $width / $block->dataValue('ratio');
|
||
|
$height = $width / 1.333;
|
||
|
return $view->partial('common/block-layout/vimeo', [
|
||
|
'title' => $block->dataValue('title'),
|
||
|
'renderSourceLink' => $block->dataValue('renderSourceLink'),
|
||
|
'item_url' => $attachments[0]->item()->url(),
|
||
|
'width' => $width,
|
||
|
'height' => $height,
|
||
|
'vimeo_iframe' => $media->mediaData()['html'],
|
||
|
]);
|
||
|
}
|
||
|
}
|