FormWidget registrations use a "code" not an "alias", it is confusing with defaultAlias property in widgetbase

This commit is contained in:
Sam Georges 2014-10-18 10:47:36 +11:00
parent d74a15b297
commit fff64a30a7
2 changed files with 27 additions and 37 deletions

View File

@ -27,35 +27,35 @@ class ServiceProvider extends ModuleServiceProvider
WidgetManager::instance()->registerFormWidgets(function($manager){
$manager->registerFormWidget('Backend\FormWidgets\CodeEditor', [
'label' => 'Code editor',
'alias' => 'codeeditor'
'code' => 'codeeditor'
]);
$manager->registerFormWidget('Backend\FormWidgets\RichEditor', [
'label' => 'Rich editor',
'alias' => 'richeditor'
'code' => 'richeditor'
]);
$manager->registerFormWidget('Backend\FormWidgets\FileUpload', [
'label' => 'File uploader',
'alias' => 'fileupload'
'code' => 'fileupload'
]);
$manager->registerFormWidget('Backend\FormWidgets\Relation', [
'label' => 'Relationship',
'alias' => 'relation'
'code' => 'relation'
]);
$manager->registerFormWidget('Backend\FormWidgets\DatePicker', [
'label' => 'Date picker',
'alias' => 'datepicker'
'code' => 'datepicker'
]);
$manager->registerFormWidget('Backend\FormWidgets\ColorPicker', [
'label' => 'Color picker',
'alias' => 'colorpicker'
'code' => 'colorpicker'
]);
$manager->registerFormWidget('Backend\FormWidgets\DataGrid', [
'label' => 'Data Grid',
'alias' => 'datagrid'
'code' => 'datagrid'
]);
$manager->registerFormWidget('Backend\FormWidgets\RecordFinder', [
'label' => 'Record Finder',
'alias' => 'recordfinder'
'code' => 'recordfinder'
]);
});

View File

@ -32,7 +32,7 @@ class WidgetManager
/**
* @var array An array of report widgets.
*/
protected $formWidgetAliases;
protected $formWidgetHints;
/**
* @var array An array of report widgets.
@ -44,21 +44,6 @@ class WidgetManager
*/
protected $reportWidgetCallbacks = [];
/**
* @var array An array where keys are aliases and values are class names.
*/
protected $aliasMap;
/**
* @var array An array where keys are class names and values are aliases.
*/
protected $classMap;
/**
* @var array A cached array of widget details.
*/
protected $detailsCache;
/**
* @var System\Classes\PluginManager
*/
@ -139,17 +124,20 @@ class WidgetManager
/**
* Registers a single form form widget.
* @param string $className Widget class name.
* @param array $widgetInfo Registration information, can contain an 'alias' key.
* @param array $widgetInfo Registration information, can contain an 'code' key.
* @return void
*/
public function registerFormWidget($className, $widgetInfo = null)
{
$widgetAlias = isset($widgetInfo['alias']) ? $widgetInfo['alias'] : null;
if (!$widgetAlias)
$widgetAlias = Str::getClassId($className);
$widgetCode = isset($widgetInfo['code']) ? $widgetInfo['code'] : null;
/* @todo Remove line if year >= 2015 */ if (!$widgetCode) $widgetCode = isset($widgetInfo['alias']) ? $widgetInfo['alias'] : null;
if (!$widgetCode)
$widgetCode = Str::getClassId($className);
$this->formWidgets[$className] = $widgetInfo;
$this->formWidgetAliases[$widgetAlias] = $className;
$this->formWidgetHints[$widgetCode] = $className;
}
/**
@ -157,8 +145,10 @@ class WidgetManager
* Usage:
* <pre>
* WidgetManager::registerFormWidgets(function($manager){
* $manager->registerFormWidget('Backend\FormWidgets\CodeEditor', 'codeeditor');
* $manager->registerFormWidget('Backend\FormWidgets\RichEditor', 'richeditor');
* $manager->registerFormWidget('Backend\FormWidgets\CodeEditor', [
* 'name' => 'Code editor',
* 'code' => 'codeeditor'
* ]);
* });
* </pre>
*/
@ -168,9 +158,9 @@ class WidgetManager
}
/**
* Returns a class name from a form widget alias
* Normalizes a class name or converts an alias to it's class name.
* @param string $name Class name or form widget alias.
* Returns a class name from a form widget code
* Normalizes a class name or converts an code to it's class name.
* @param string $name Class name or form widget code.
* @return string The class name resolved, or the original name.
*/
public function resolveFormWidget($name)
@ -178,10 +168,10 @@ class WidgetManager
if ($this->formWidgets === null)
$this->listFormWidgets();
$aliases = $this->formWidgetAliases;
$hints = $this->formWidgetHints;
if (isset($aliases[$name]))
return $aliases[$name];
if (isset($hints[$name]))
return $hints[$name];
$_name = Str::normalizeClassName($name);
if (isset($this->formWidgets[$_name]))