<?php
/**
* Base Page Model
*
* @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl>
*/
namespace VisualMedia\PageBundle\Model;
use Doctrine\ORM\Event\LifecycleEventArgs;
use VisualMedia\LisaBundle\Controller\BaseController;
use VisualMedia\PageBundle\Entity\BasePage;
use VisualMedia\TranslationBundle\Entity\BaseChannel;
use VisualMedia\TranslationBundle\Entity\BaseLocale;
use VisualMedia\TranslationBundle\Traits\ContentTrait;
/**
* Base Page Content Model
*/
abstract class BasePageContentModel
{
use ContentTrait;
/**
* @param BasePage $page
* @param BaseLocale $locale
* @param BaseChannel|null $channel
*/
public function __construct(BasePage $page = null, BaseLocale $locale = null, ?BaseChannel $channel = null)
{
$this->page = $page;
$this->locale = $locale;
$this->channel = $channel;
}
/**
* Function that delegates the url to the page for url nesting.
* @return string
*/
public function getUrl(): string
{
// When saving a contents entity, the contents holder still has the old non-saved slug.
// Call the postLoad event on the page to make sure the right slug is loaded from the contents.
$manager = BaseController::getDoctrineObject()->getManager();
$manager->getEventManager()->dispatchEvent('postLoad', new LifecycleEventArgs($this->page, $manager));
return $this->page->getUrl();
}
/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @return string|null
*/
public function getBrowserTitle(): ?string
{
return $this->browserTitle;
}
/**
* @return string|null
*/
public function getMetaDescription(): ?string
{
return $this->metaDescription;
}
/**
* @return string|null
*/
public function getSlug(): ?string
{
return $this->slug;
}
/**
* @return string|null
*/
public function getHtmlContent(): ?string
{
return $this->htmlContent;
}
}