formElementManager = $formElementManager; $this->defaultSettings = $defaultSettings; } public function getLabel() { return 'Vimeo video'; } 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][renderSourceLink]' => $data['renderSourceLink'], ]); $form->prepare(); $html = ''; $html .= $view->blockAttachmentsForm($block); $html .= '

'; $html .= $view->translate('Options'). '

'; $html .= '
'; $html .= $view->formCollection($form); $html .= '
'; return $html; } public function render(PhpRenderer $view, SitePageBlockRepresentation $block) { $attachments = $block->attachments(); if (!$attachments) { return ''; } $media = $attachments[0]->item()->media()[0]; $ratio = $media->mediaData()['width'] / $media->mediaData()['height']; // creates an iframe injecting our width and calculated ratio $attribs= 'ratio="'.$ratio.'"'.PHP_EOL; $doc = new DOMDocument(); $doc->loadHTML($media->mediaData()['html']); $html_element= $doc->getElementsByTagName('iframe')->item(0); if ($html_element->hasAttributes()) { foreach ($html_element->attributes as $attr) { $name = $attr->nodeName; $value = $attr->nodeValue; if ($name == 'height') { // we will calculate height with jQuery continue; } if ($name == 'width') { $attrib = 'width="'.$block->dataValue('width').'%"'; $attribs .= $attrib.PHP_EOL; continue; } $attrib = $name.'="'.$value.'"'; $attribs .= $attrib.PHP_EOL; } } $iframe = ""; return $view->partial('common/block-layout/vimeo', [ 'title' => $block->dataValue('title'), 'renderSourceLink' => $block->dataValue('renderSourceLink'), 'item_url' => $attachments[0]->item()->url(), 'vimeo_iframe' => $iframe ]); } }