Example #1
0
 /**
  * @return \KodiCMS\Widgets\Contracts\Widget|null
  * @throws WidgetException
  */
 public function toWidget()
 {
     if (!is_null($this->widget)) {
         return $this->widget;
     }
     if (array_key_exists($this->id, static::$cachedWidgets)) {
         $this->widget = static::$cachedWidgets[$this->id];
         return $this->widget;
     }
     if (!is_null($this->widget = $this->manager->makeWidget($this->type, $this->name, $this->description, $this->settings))) {
         $this->widget->setId($this->id);
         if ($this->isRenderable()) {
             $this->widget->setFrontendTemplate($this->template);
         }
         $this->widget->setRalatedWidgets($this->related);
     } else {
         $this->widget = new TempWidget($this->manager, $this->name, $this->description);
     }
     static::$cachedWidgets[$this->id] = $this->widget;
     return $this->widget;
 }