Merge pull request #2898 from arzola/master

Added Extensibility to ReportWidgets
This commit is contained in:
Samuel Georges 2017-06-03 00:56:35 +10:00 committed by GitHub
commit ef94decb1a
2 changed files with 53 additions and 0 deletions

View File

@ -2,6 +2,7 @@
use Str;
use System\Classes\PluginManager;
use Event;
/**
* Widget manager
@ -188,6 +189,11 @@ class WidgetManager
}
}
/*
* Extensibility
*/
Event::fire('system.reportwidgets.extendItems', [$this]);
return $this->reportWidgets;
}
@ -215,4 +221,19 @@ class WidgetManager
{
$this->reportWidgetCallbacks[] = $definitions;
}
/**
* Remove a registered ReportWidget.
* @param string $className Widget class name.
* @return void
*/
public function removeReportWidget($className)
{
if (!$this->reportWidgets) {
throw new SystemException('Unable to remove a widget before widgets are loaded.');
}
unset($this->reportWidgets[$className]);
}
}

View File

@ -13,4 +13,36 @@ class WidgetManagerTest extends TestCase
$this->assertArrayHasKey('TestVendor\Test\FormWidgets\Sample', $widgets);
$this->assertArrayHasKey('October\Tester\FormWidgets\Preview', $widgets);
}
public function testIfWidgetsCanBeExtended()
{
$manager = WidgetManager::instance();
$manager->registerReportWidget('Acme\Fake\ReportWidget\HelloWorld', [
'name' => 'Hello World Test',
'context' => 'dashboard'
]);
$widgets = $manager->listReportWidgets();
$this->assertArrayHasKey('Acme\Fake\ReportWidget\HelloWorld', $widgets);
}
public function testIfWidgetsCanBeRemoved()
{
$manager = WidgetManager::instance();
$manager->registerReportWidget('Acme\Fake\ReportWidget\HelloWorld', [
'name' => 'Hello World Test',
'context' => 'dashboard'
]);
$manager->registerReportWidget('Acme\Fake\ReportWidget\ByeWorld', [
'name' => 'Hello World Bye',
'context' => 'dashboard'
]);
$manager->removeReportWidget('Acme\Fake\ReportWidget\ByeWorld');
$widgets = $manager->listReportWidgets();
$this->assertCount(1, $widgets);
}
}