'collection' => $collection,
'thumb_collection' => $this->_thumbCollection,
'default' => $collection,
- 'options' => ['thumbnailHeight' => 120, 'thumbnailWidth' => 120, 'maxFilesize' => 1024, 'addRemoveLinks' => true, 'createImageThumbnails' => true, 'maxFiles' => $this->_maxFiles]]);
+ 'options' =>
+ [
+ 'thumbnailHeight' => 120,
+ 'thumbnailWidth' => 120,
+ 'maxFilesize' => 1024,
+ 'addRemoveLinks' => true,
+ 'createImageThumbnails' => true,
+ 'maxFiles' => $this->_maxFiles
+ ]
+ ]);
}
protected function _getAttributesAliases()
return $item;
}
/** @var $item PageItem */
- if (stristr($item->getPage()->template, 'redirection')) {
+ if (stristr($item->getTemplate(), 'redirection')) {
continue;
}
return $item;
class PageItem extends Item
{
+ /** @var null|bool */
+ protected $_isVirtual = null;
+
+ /** @var null|string|false */
+ protected $_template = null;
+
/**
- * @var CubistMagicPageModel
+ * @var CubistMagicPageModel|null
*/
- protected $_page;
+ protected $_page = null;
/**
public function initFromPage($page, $all)
{
$this->initFromEntity($page);
+ $this->setPage($page);
$this->setChildrenFromData($all, $this->getId());
$this->setChildrenFromTemplate();
}
*/
public function initFromEntity($entity)
{
- $this->setPage($entity);
+
$this->setId($entity->id);
$this->setName($entity->name ?? get_class($entity) . '_' . $entity->id);
$this->setSlug($entity->slug);
if (is_array($dbaliases)) {
$aliases = [];
foreach ($dbaliases as $dbalias) {
- $aliases[] = ltrim($dbalias['url'],'/');
+ $aliases[] = ltrim($dbalias['url'], '/');
}
$this->setURLAliases(array_unique(array_values($aliases)));
}
public function getTemplate()
{
- if ($this->getPage() instanceof CMSPage) {
- return $this->getPage()->template;
+ if (null === $this->_template) {
+ if ($this->getPage() instanceof CMSPage) {
+ $this->_template = $this->getPage()->template;
+ } else {
+ $this->_template = false;
+ }
}
- return false;
+ return $this->_template;
}
public function getHref()
{
- if ($this->getTemplate() == 'first_redirection' && $this->hasChildren()) {
+ $template = $this->getTemplate();
+ if (!$template) {
+ return parent::getHref();
+ }
+
+ if ($template == 'first_redirection' && $this->hasChildren()) {
return $this->getChildren()[0]->getHref();
- } else if ($this->getTemplate() == 'internal_redirection') {
+ } else if ($template == 'internal_redirection') {
- } else if ($this->getTemplate() == 'redirection') {
+ } else if ($template == 'redirection') {
return $this->navigation;
}
public function isVirtual()
{
- if ($this->getPage() instanceof CMSPage) {
- return $this->getPage()->getUsedTemplate()->isVirtual();
+ if (null === $this->_isVirtual) {
+ if ($this->getPage() instanceof CMSPage) {
+ $this->_isVirtual = $this->getPage()->getUsedTemplate()->isVirtual();
+ } else {
+ $this->_isVirtual = false;
+ }
}
- return false;
+ return $this->_isVirtual;
}
public function getBreadcrumbHref()
*/
public function setPage(CubistMagicPageModel $page): void
{
+ $this->_isVirtual = $this->_template = null;
$this->_page = $page;
}
public $timestamps = true;
public $clonable = true;
+ /**
+ * @var array
+ */
+ protected $_fieldsToAppend = [];
+
/**
* @var array
*/
public function postSetFields()
{
+ foreach ($this->_fieldsToAppend as $item) {
+ $this->addField($item);
+ }
+
if (!isset($this->_fields['slug'])) {
$this->addField(['name' => 'slug',
'type' => 'Hidden',
return $default;
}
+ public function addFieldAtEnd($attributes)
+ {
+ return $this->_fieldsToAppend[] = $attributes;
+ }
+
/**
* @param $attributes array
* @return Field
if (config('cubist.internal_search', false)) {
$this->_internalSearch();
}
+ $this->_social();
}
protected function _internalSearch()
{
$tab = 'Recherche';
- $this->addField(['name' => 'search_internal_enabled',
+ $this->addFieldAtEnd(['name' => 'search_internal_enabled',
'type' => 'Checkbox',
'label' => 'Activer',
'default' => true,
'fake' => true,
'store_in' => 'search_internal']);
- $this->addField(['name' => 'search_internal_keywords',
+ $this->addFieldAtEnd(['name' => 'search_internal_keywords',
'type' => 'Tags',
'label' => 'Mots clés',
'hint' => 'Mots supplémentaires à utiliser par le moteur de recherche',
{
$tab = 'SEO // Meta';
- $this->addField(['name' => 'slug',
+ $this->addFieldAtEnd(['name' => 'slug',
'type' => 'Slug',
'label' => 'Slug (URL)',
'tab' => $tab,
]);
- $this->addField([
+ $this->addFieldAtEnd([
'name' => 'meta_title',
'label' => trans('backpack::pagemanager.meta_title'),
'type' => 'Text',
'store_in' => 'seo',
]);
- $this->addField([
+ $this->addFieldAtEnd([
'name' => 'meta_description',
'label' => trans('backpack::pagemanager.meta_description'),
'type' => 'Textarea',
'store_in' => 'seo',
]);
- $this->addField([
+ $this->addFieldAtEnd([
'name' => 'robots',
'label' => __('Allow page index by search engines'),
'type' => 'Checkbox',
'store_in' => 'seo',
]);
- $this->addField(['name' => 'url_alias',
+ $this->addFieldAtEnd(['name' => 'url_alias',
'label' => 'Autres URLS',
'type' => 'Table',
'columns' => ['url' => 'URL'],
'fake' => true,
'store_in' => 'seo']);
}
+
+ protected function _social()
+ {
+ $tab = 'Réseaux sociaux';
+ $this->addFieldAtEnd(['name' => 'social_title',
+ 'label' => 'Titre affiché sur les réseaux sociaux',
+ 'type' => 'Text',
+ 'hint' => 'Si laissé vide, le titre long est utilisé',
+ 'tab' => $tab,
+ 'fake' => true,
+ 'store_in' => 'seo']);
+
+ $this->addFieldAtEnd(['name' => 'social_description',
+ 'label' => 'Description affichée sur les réseaux sociaux',
+ 'type' => 'Textarea',
+ 'hint' => 'Si laissé vide, la description est utilisée',
+ 'tab' => $tab,
+ 'fake' => true,
+ 'store_in' => 'seo']);
+
+ $this->addFieldAtEnd(['name' => 'social_image',
+ 'label' => 'Images affichées sur les réseaux sociaux',
+ 'type' => 'Images',
+ 'hint' => 'Si laissée vide, le réseau social utilisera une image de la page',
+ 'tab' => $tab,
+ 'fake' => true,
+ 'store_in' => 'seo']);
+ }
}