]> _ Git - cubist_cms-back.git/commitdiff
fix #2967 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 30 Aug 2019 14:45:07 +0000 (16:45 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 30 Aug 2019 14:45:07 +0000 (16:45 +0200)
src/app/Magic/Fields/Files.php
src/app/Magic/Menu/Item.php
src/app/Magic/Menu/PageItem.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/app/Magic/Models/CubistMagicPageModel.php

index 0b2f5211a2834025d035bac4dfc77d65f53aa41b..4f5dcd74b064ea29ef324edeee87d403ab5c47a3 100644 (file)
@@ -24,7 +24,16 @@ class Files extends Field
             '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()
index 53db67ca657df572d76b60ca1313b1a7d3840a0e..1f845d29d13a8eb78fdd44ae643224f48d6a0579 100644 (file)
@@ -224,7 +224,7 @@ class Item
                 return $item;
             }
             /** @var $item PageItem */
-            if (stristr($item->getPage()->template, 'redirection')) {
+            if (stristr($item->getTemplate(), 'redirection')) {
                 continue;
             }
             return $item;
index c909e4f1af740e243f398bb654828d79a3929f4f..7fe67d3a71fc6445bf2d31e53f6acb278e27d66d 100644 (file)
@@ -9,10 +9,16 @@ use Cubist\Backpack\app\Magic\Models\CubistMagicPageModel;
 
 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;
 
 
     /**
@@ -22,6 +28,7 @@ class PageItem extends Item
     public function initFromPage($page, $all)
     {
         $this->initFromEntity($page);
+        $this->setPage($page);
         $this->setChildrenFromData($all, $this->getId());
         $this->setChildrenFromTemplate();
     }
@@ -31,7 +38,7 @@ class PageItem extends Item
      */
     public function initFromEntity($entity)
     {
-        $this->setPage($entity);
+
         $this->setId($entity->id);
         $this->setName($entity->name ?? get_class($entity) . '_' . $entity->id);
         $this->setSlug($entity->slug);
@@ -40,7 +47,7 @@ class PageItem extends Item
         if (is_array($dbaliases)) {
             $aliases = [];
             foreach ($dbaliases as $dbalias) {
-                $aliases[] = ltrim($dbalias['url'],'/');
+                $aliases[] = ltrim($dbalias['url'], '/');
             }
             $this->setURLAliases(array_unique(array_values($aliases)));
         }
@@ -56,19 +63,28 @@ class PageItem extends Item
 
     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;
         }
 
@@ -81,10 +97,14 @@ class PageItem extends Item
 
     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()
@@ -116,6 +136,7 @@ class PageItem extends Item
      */
     public function setPage(CubistMagicPageModel $page): void
     {
+        $this->_isVirtual = $this->_template = null;
         $this->_page = $page;
     }
 
index 3f1722d77b5fcd27dc87b21d4844f6998dd97346..779d8658ba6919ff631f9ccbbec2a9cec2c705bc 100644 (file)
@@ -43,6 +43,11 @@ class CubistMagicAbstractModel extends Model implements HasMedia
     public $timestamps = true;
     public $clonable = true;
 
+    /**
+     * @var array
+     */
+    protected $_fieldsToAppend = [];
+
     /**
      * @var array
      */
@@ -116,6 +121,10 @@ class CubistMagicAbstractModel extends Model implements HasMedia
 
     public function postSetFields()
     {
+        foreach ($this->_fieldsToAppend as $item) {
+            $this->addField($item);
+        }
+
         if (!isset($this->_fields['slug'])) {
             $this->addField(['name' => 'slug',
                 'type' => 'Hidden',
@@ -175,6 +184,11 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         return $default;
     }
 
+    public function addFieldAtEnd($attributes)
+    {
+        return $this->_fieldsToAppend[] = $attributes;
+    }
+
     /**
      * @param $attributes array
      * @return Field
index 53ffadc468e21f83632fe4d1e2fcbbee0036b0a1..e19ae7f74adbb1164303beb8f3113e863e605100 100644 (file)
@@ -13,12 +13,13 @@ class CubistMagicPageModel extends CubistMagicModel
         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,
@@ -27,7 +28,7 @@ class CubistMagicPageModel extends CubistMagicModel
             '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',
@@ -41,13 +42,13 @@ class CubistMagicPageModel extends CubistMagicModel
     {
         $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',
@@ -57,7 +58,7 @@ class CubistMagicPageModel extends CubistMagicModel
             'store_in' => 'seo',
         ]);
 
-        $this->addField([
+        $this->addFieldAtEnd([
             'name' => 'meta_description',
             'label' => trans('backpack::pagemanager.meta_description'),
             'type' => 'Textarea',
@@ -67,7 +68,7 @@ class CubistMagicPageModel extends CubistMagicModel
             'store_in' => 'seo',
         ]);
 
-        $this->addField([
+        $this->addFieldAtEnd([
             'name' => 'robots',
             'label' => __('Allow page index by search engines'),
             'type' => 'Checkbox',
@@ -77,7 +78,7 @@ class CubistMagicPageModel extends CubistMagicModel
             'store_in' => 'seo',
         ]);
 
-        $this->addField(['name' => 'url_alias',
+        $this->addFieldAtEnd(['name' => 'url_alias',
             'label' => 'Autres URLS',
             'type' => 'Table',
             'columns' => ['url' => 'URL'],
@@ -86,4 +87,32 @@ class CubistMagicPageModel extends CubistMagicModel
             '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']);
+    }
 }