/** * Pass through the updated Page object and save it in the DB * * @param Page $page Page object to be update * * @return Page|false Updated Page object */ public function save(Page $page) { $page->authorship->update(new DateTimeImmutable(), $this->_currentUser->id); $this->_transaction->run('UPDATE page SET page.title = :title?s, page.type = :type?s, page.publish_at = :publishAt?dn, page.unpublish_at = :unpublishAt?dn, page.updated_at = :updatedAt?dn, page.updated_by = :updatedBy?i, page.meta_title = :metaTitle?s, page.meta_description = :metaDescription?s, page.meta_image = :metaImage?in, page.meta_html_head = :metaHtmlHead?s, page.meta_html_foot = :metaHtmlFoot?s, page.visibility_search = :visibilitySearch?i, page.visibility_menu = :visibilityMenu?i, page.visibility_aggregator = :visibilityAggregator?i, page.password = :password?s, page.access = :access?s WHERE page.page_id = :pageID?i', array('pageID' => $page->id, 'title' => $page->title, 'type' => $page->type->getName(), 'publishAt' => $page->publishDateRange->getStart(), 'unpublishAt' => $page->publishDateRange->getEnd(), 'updatedAt' => $page->authorship->updatedAt(), 'updatedBy' => $page->authorship->updatedBy(), 'slug' => $page->slug->getLastSegment(), 'metaTitle' => $page->metaTitle, 'metaDescription' => $page->metaDescription, 'metaImage' => $page->getMetaImage() ? $page->getMetaImage()->id : null, 'metaHtmlHead' => $page->metaHtmlHead, 'metaHtmlFoot' => $page->metaHtmlFoot, 'visibilitySearch' => $page->visibilitySearch, 'visibilityMenu' => $page->visibilityMenu, 'visibilityAggregator' => $page->visibilityAggregator, 'password' => $page->password, 'access' => $page->access)); // Update the user groups for this page in the DB $this->_updateAccessGroups($page); $this->_updateTags($page); $event = new Event\Event($page); // Dispatch the edit event $this->_eventDispatcher->dispatch($event::EDIT, $event); if (!$this->_transOverride) { $this->_transaction->commit(); } return $event->getPage(); }
/** * {@inheritDoc} */ public function getMetaImage() { if (!$this->_isLoaded('metaImage')) { $image = $this->_loaders->get('image')->load($this); $this->setMetaImage($image); $this->_loaded[] = 'metaImage'; } return parent::getMetaImage(); }
/** * Get form for metadata section of edit page * * @param Page $page * @param Content $content * * @return \Message\Cog\Form\Handler */ protected function _getMetadataForm(Page $page) { $form = $this->get('form')->setName('content-edit-metadata')->setAction($this->generateUrl('ms.cp.cms.edit.metadata.action', array('pageID' => $page->id)))->setMethod('post')->setDefaultValues(array('metaTitle' => $page->metaTitle, 'metaDescription' => $page->metaDescription, 'metaImage' => $page->getMetaImage() ? $page->getMetaImage()->id : null)); $form->add('metaTitle', 'text', $this->trans('ms.cms.metadata.title.label'), array('attr' => array('data-help-key' => 'ms.cms.metadata.title.help')))->val()->optional()->maxLength(255); $form->add('metaDescription', 'textarea', $this->trans('ms.cms.metadata.description.label'), array('attr' => array('data-help-key' => 'ms.cms.metadata.description.help')))->val()->optional(); $form->add('metaImage', 'file', $this->trans('ms.cms.metadata.image.label'), ['attr' => ['data-help-key' => 'ms.cms.metadata.image.help']])->val()->optional(); $files = (array) $this->get('file_manager.file.loader')->getAll(); // Get the available files $choices = array(); $allowedTypes = array(File\Type::IMAGE); foreach ($files as $file) { if ($allowedTypes) { if (!in_array($file->typeID, $allowedTypes)) { continue; } } $choices[$file->id] = $file->name; } uasort($choices, function ($a, $b) { return strcmp($a, $b); }); $form->add('metaImage', 'ms_file', $this->trans('ms.commerce.product.image.file.label'), ['choices' => $choices, 'empty_value' => 'Please select…', 'attr' => array('data-help-key' => 'ms.commerce.product.image.file.help')]); return $form; }