Added Extensibility to ReportWidgets

This commit is contained in:
Oscar Arzola 2017-05-30 16:49:35 -05:00
parent 4d1bec860d
commit 0bd12cf0e6
2 changed files with 52 additions and 1 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,17 @@ class WidgetManager
{
$this->reportWidgetCallbacks[] = $definitions;
}
}
/**
* Removes a single report widget item
*/
public function removeReportWidgetItem($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->removeReportWidgetItem('Acme\Fake\ReportWidget\ByeWorld');
$widgets = $manager->listReportWidgets();
$this->assertCount(1, $widgets);
}
}