public function onHydrate(SitePageBlock $block, ErrorStore $errorStore) { $htmlPurifier = $this->getServiceLocator()->get('Omeka\\htmlPurifier'); $data = $block->getData(); $data['text'] = $htmlPurifier->purify($this->getData($data, 'text')); $block->setData($data); }
public function attachments() { $attachments = []; foreach ($this->block->getAttachments() as $attachment) { $attachments[] = new SiteBlockAttachmentRepresentation($attachment, $this->getServiceLocator()); } return $attachments; }
/** * Hydrate attachment data for a block * * @param array $attachmentData * @param SitePageBlock $block * @param ErrorStore $errorStore * @return bool true on success, false on error */ private function hydrateAttachments(array $attachmentData, SitePageBlock $block, ErrorStore $errorStore) { $itemAdapter = $this->getAdapter('items'); $attachments = $block->getAttachments(); $existingAttachments = $attachments->toArray(); $newAttachments = []; $position = 1; foreach ($attachmentData as $inputAttachment) { if (!is_array($inputAttachment)) { continue; } $attachment = current($existingAttachments); if ($attachment === false) { $attachment = new SiteBlockAttachment(); $attachment->setBlock($block); $newAttachments[] = $attachment; } else { // Null out values as we re-use them $existingAttachments[key($existingAttachments)] = null; next($existingAttachments); } try { $item = $itemAdapter->findEntity($inputAttachment['o:item']['o:id']); } catch (NotFoundException $e) { $item = null; } if ($item && isset($inputAttachment['o:media']['o:id'])) { $itemMedia = $item->getMedia(); $media = $itemMedia->get($inputAttachment['o:media']['o:id']); } else { $media = null; } $caption = isset($inputAttachment['o:caption']) ? $inputAttachment['o:caption'] : ''; $purifier = $this->getServiceLocator()->get('Omeka\\HtmlPurifier'); $caption = $purifier->purify($caption); $attachment->setItem($item); $attachment->setMedia($media); $attachment->setCaption($caption); $attachment->setPosition($position++); } // Remove any blocks that weren't reused foreach ($existingAttachments as $key => $existingAttachment) { if ($existingAttachment !== null) { $attachments->remove($key); } } // Add any new blocks that had to be created foreach ($newAttachments as $newAttachment) { $attachments->add($newAttachment); } return true; }
/** * {@inheritDoc} */ public function getResourceId() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getResourceId', array()); return parent::getResourceId(); }