FEATURE: move template into own repository
This commit is contained in:
Executable
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Templates\Base\OnePage\Widgets\OnePageMenu;
|
||||
|
||||
use App\CMS\Contracts\Widgets\PublicWidget;
|
||||
use App\CMS\Contracts\Widgets\WidgetRenderer;
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class OnePageMenu implements PublicWidget
|
||||
{
|
||||
/**
|
||||
* Name getter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'template::widget/menu.name';
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return 'template::widget/menu.description';
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for presenter/renderer of this widget
|
||||
*
|
||||
* @return WidgetRenderer
|
||||
*/
|
||||
public static function getPresenter()
|
||||
{
|
||||
return Presenter::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function save(Request $data)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Executable
+65
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace Templates\Base\OnePage\Widgets\OnePageMenu;
|
||||
|
||||
use App\Models\Widgets\Widget;
|
||||
use App\Models\Widgets\WidgetType;
|
||||
use App\CMS\Contracts\Widgets\WidgetRenderer;
|
||||
use Templates\Base\OnePage\Handlers\OnePage;
|
||||
|
||||
class Presenter implements WidgetRenderer
|
||||
{
|
||||
/**
|
||||
* @var string path to template
|
||||
*/
|
||||
public static $template;
|
||||
|
||||
/**
|
||||
* Method used for displaying widget.
|
||||
*
|
||||
* This method renders some HTML code for displaying.
|
||||
*
|
||||
* @param Widget $widget
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \ErrorException
|
||||
*/
|
||||
public static function render(Widget $widget)
|
||||
{
|
||||
if (!self::$template) {
|
||||
throw new \ErrorException('Cannot render menu without template! Please, set Presenter::$template variable before rendering.');
|
||||
}
|
||||
|
||||
$pages = OnePage::getPagesOnHomepage();
|
||||
|
||||
return view(self::$template, ['pages' => $pages, 'widget' => $widget])->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display form for creating new instance of widget
|
||||
*
|
||||
* @param WidgetType $type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function renderAddForm(WidgetType $type)
|
||||
{
|
||||
return view('template::admin.widgets.onePageMenu.new', [
|
||||
'type' => $type,
|
||||
'widget' => new Widget(),
|
||||
'settings' => new \stdClass()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display form for editing already existing widget
|
||||
*
|
||||
* @param Widget $widget
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function renderEditForm(Widget $widget)
|
||||
{
|
||||
$settings = $widget->settings;
|
||||
return view('template::admin.widgets.onePageMenu.edit', ['widget' => $widget, 'settings' => $settings]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user