]> _ Git - cubist_cms-back.git/commitdiff
Added getHrefByID function to Menu Items so we can avoid exceptions when menu item...
authorStephen Cameron <stephen@cubedesigners.com>
Mon, 15 Jul 2019 13:13:12 +0000 (15:13 +0200)
committerStephen Cameron <stephen@cubedesigners.com>
Mon, 15 Jul 2019 13:13:12 +0000 (15:13 +0200)
src/app/Magic/Menu/Item.php
src/app/Magic/PageData.php

index de32d594ff7e79d8ff9debe1968607ca86abdf8d..1b78c220a67f54797005f5fa8d77d307bd14ebf4 100644 (file)
@@ -264,6 +264,23 @@ class Item
     }
 
 
+    /**
+     * @param $id
+     * @param null $default
+     * @return string|null
+     */
+    public function getHrefByID($id, $default = null)
+    {
+        $item = $this->findOneById($id);
+
+        if ($item) {
+            return $item->getHref();
+        }
+
+        return $default;
+    }
+
+
     /**
      * @param string $href
      */
index 802b8bde1ac29428e49985706a7eaa21e098502c..f00d4b6474cc201a1eacf17d9c21b6de54111e7a 100644 (file)
@@ -231,6 +231,31 @@ class PageData implements \ArrayAccess
         return $default;
     }
 
+    /**
+     * @param string $collectionID Name of the collection
+     * @param string $conversionName
+     * @param mixed $default
+     * @return string|null
+     */
+    public function getImageURLbyCollection($collectionID, $conversionName = '', $default = null)
+    {
+        $media = $this->getEntity()->getMedia($collectionID);
+        if (!$media) {
+            return $default;
+        }
+
+        foreach ($media as $m) {
+            /** @var Media $m */
+            $res = $m->getUrl($conversionName);
+            if (!$res) {
+                continue;
+            }
+            return $res;
+        }
+
+        return $default;
+    }
+
     public function getImageURLAt($offset, $at = 0, $conversionName = '', $default = null)
     {
         $media = $this->getMedia($offset);