FEATURE #1422: prepare application for registering widgets
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace App\Widgets\Contracts;
|
||||
|
||||
interface AdminDashboardWidget extends PublicWidget
|
||||
{
|
||||
/**
|
||||
* Getter for list of all roles which are allowed to display the widget
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function renderForRoles();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace App\Widgets\Contracts;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Widget;
|
||||
|
||||
interface PublicWidget
|
||||
{
|
||||
/**
|
||||
* Name getter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getName();
|
||||
|
||||
/**
|
||||
* Getter for description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getDescription();
|
||||
|
||||
/**
|
||||
* Getter for presenter/renderer of this widget
|
||||
*
|
||||
* @return WidgetRenderer
|
||||
*/
|
||||
public static function getPresenter();
|
||||
|
||||
/**
|
||||
* @param Widget $widget
|
||||
* @param Request $request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function save(Widget $widget, Request $request);
|
||||
|
||||
/**
|
||||
* Function for installing given widget
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function install();
|
||||
|
||||
/**
|
||||
* Function for uninstalling widget
|
||||
*/
|
||||
public static function uninstall();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace App\Widgets\Contracts;
|
||||
|
||||
use App\Models\Widget;
|
||||
use App\Models\WidgetType;
|
||||
|
||||
interface WidgetRenderer
|
||||
{
|
||||
/**
|
||||
* Method used for displaying widget.
|
||||
*
|
||||
* This method renders some HTML code for displaying.
|
||||
*
|
||||
* @param object $settings
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function render($settings);
|
||||
|
||||
/**
|
||||
* Display form for creating new instance of widget
|
||||
*
|
||||
* @param WidgetType $type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function renderAddForm(WidgetType $type);
|
||||
|
||||
/**
|
||||
* Display form for editing already existing widget
|
||||
*
|
||||
* @param Widget $widget
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function renderEditForm(Widget $widget);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace App\Widgets\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class MissingParameterException extends \Exception
|
||||
{
|
||||
public function __construct($message = "", $code = 0, Exception $previous = null)
|
||||
{
|
||||
$message = trans('admin/widgets.missingValue', ['field' => $message]);
|
||||
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace App\Widgets;
|
||||
|
||||
abstract class NonInstallableWidget extends Widget
|
||||
{
|
||||
public static function install()
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public static function uninstall()
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace App\Widgets;
|
||||
|
||||
use App\Widgets\Contracts\PublicWidget;
|
||||
|
||||
abstract class Widget implements PublicWidget {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user