forked from pimcore/pimcore
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature]: Manage select options via interface
Add Select Options management interface via Settings > Data Objects submenu. Add selectoptions permission to allow access to management interface. Add options source selection to select fields definition to switch between direct configuration, select options or class / service configuration. Generate configuration file and enum to store select options. Introduce OptionsProviderInterface to detect field definitions using provider. Introduce OptionsProviderTrait to share properties between select types. Update classes rebuild command to also rebuild select options. Add PHP and JavaScript reserved words helper classes. Add and update documentation. Relates to pimcore#3409
- Loading branch information
1 parent
aaded2c
commit 7448186
Showing
61 changed files
with
2,855 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
bundles/AdminBundle/public/js/pimcore/object/helpers/reservedWords.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
pimcore.registerNS('pimcore.object.helpers.reservedWords'); | ||
|
||
pimcore.object.helpers.reservedWords = { | ||
// https://www.php.net/manual/en/reserved.keywords.php | ||
phpReservedKeywords: [ | ||
'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', | ||
'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', | ||
'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'finally', 'fn', 'for', 'foreach', | ||
'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', | ||
'interface', 'isset', 'list', 'match', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', | ||
'readonly', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', | ||
'var', 'while', 'xor', 'yield', 'yield_from' | ||
], | ||
|
||
// https://www.php.net/manual/en/reserved.classes.php | ||
phpReservedClasses: [ | ||
'self', 'static', 'parent' | ||
], | ||
|
||
// https://www.php.net/manual/en/reserved.other-reserved-words.php | ||
phpOtherReservedWords: [ | ||
'int', 'float', 'bool', 'string', 'true', 'false', 'null', 'void', 'iterable', 'object', 'mixed', 'never', | ||
'enum', 'resource', 'numeric' | ||
], | ||
|
||
pimcore: [ | ||
// Pimcore | ||
'data', 'folder', 'permissions', 'dao', 'concrete', 'items' | ||
], | ||
|
||
isReservedWord: function (word) { | ||
return in_arrayi(word, this.getAllReservedWords()); | ||
}, | ||
|
||
getAllReservedWords: function () { | ||
return this.phpReservedKeywords.concat( | ||
this.phpReservedClasses, | ||
this.phpOtherReservedWords, | ||
this.pimcore | ||
); | ||
} | ||
}; |
163 changes: 163 additions & 0 deletions
163
bundles/AdminBundle/public/js/pimcore/object/helpers/selectField.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
pimcore.registerNS('pimcore.object.helpers.selectField'); | ||
|
||
/** | ||
* @private | ||
*/ | ||
pimcore.object.helpers.selectField = { | ||
OPTIONS_PROVIDER_TYPE_CONFIGURE: 'configure', | ||
OPTIONS_PROVIDER_TYPE_SELECT_OPTIONS: 'select_options', | ||
OPTIONS_PROVIDER_TYPE_CLASS: 'class', | ||
|
||
selectOptionsStore: null, | ||
|
||
/** | ||
* @param {Object} datax | ||
* @param {Ext.grid.Panel} valueGrid | ||
* @returns {[ | ||
* Ext.form.field.ComboBox, | ||
* Ext.form.field.Text, | ||
* Ext.form.field.Text, | ||
* Ext.form.field.ComboBox | ||
* ]} | ||
*/ | ||
getOptionsProviderFields: function (datax, valueGrid) { | ||
var selectOptionsSelector = Ext.create('Ext.form.field.ComboBox', { | ||
fieldLabel: t('selectoptions'), | ||
emptyText: '', | ||
value: datax.optionsProviderData, | ||
hidden: true, | ||
valueField: 'id', | ||
displayField: 'text', | ||
editable: false, | ||
forceSelection: true, | ||
queryMode: 'local', | ||
store: this.getSelectOptionsStore(), | ||
listeners: { | ||
change: function (comboBox, newValue) { | ||
optionsProviderClass.setValue('\\Pimcore\\Bundle\\AdminBundle\\OptionsProvider\\SelectOptionsOptionsProvider'); | ||
optionsProviderData.setValue(newValue); | ||
} | ||
} | ||
}); | ||
|
||
var optionsProviderClass = Ext.create('Ext.form.field.Text', { | ||
fieldLabel: t('options_provider_class'), | ||
width: 600, | ||
name: 'optionsProviderClass', | ||
hidden: true, | ||
value: datax.optionsProviderClass | ||
}); | ||
|
||
var optionsProviderData = Ext.create('Ext.form.field.Text', { | ||
fieldLabel: t('options_provider_data'), | ||
width: 600, | ||
value: datax.optionsProviderData, | ||
hidden: true, | ||
name: 'optionsProviderData' | ||
}); | ||
|
||
var toggleFields = function (optionsProviderType) { | ||
switch (optionsProviderType) { | ||
case this.OPTIONS_PROVIDER_TYPE_SELECT_OPTIONS: | ||
optionsProviderClass.hide(); | ||
optionsProviderData.hide(); | ||
selectOptionsSelector.show(); | ||
valueGrid.hide(); | ||
break; | ||
case this.OPTIONS_PROVIDER_TYPE_CLASS: | ||
optionsProviderClass.show(); | ||
optionsProviderData.show(); | ||
selectOptionsSelector.hide(); | ||
valueGrid.hide(); | ||
break; | ||
// Configure | ||
default: | ||
optionsProviderClass.hide(); | ||
optionsProviderData.hide(); | ||
selectOptionsSelector.hide(); | ||
valueGrid.show(); | ||
} | ||
}.bind(this) | ||
|
||
var typeValue = this.OPTIONS_PROVIDER_TYPE_CONFIGURE; | ||
if (datax.optionsProviderType) { | ||
typeValue = datax.optionsProviderType; | ||
// Legacy fallback in case no type is set and a class/service is configured | ||
} else if (datax.optionsProviderClass) { | ||
typeValue = this.OPTIONS_PROVIDER_TYPE_CLASS; | ||
} | ||
|
||
toggleFields(typeValue); | ||
|
||
var optionsProviderType = Ext.create('Ext.form.field.ComboBox', { | ||
name: 'optionsProviderType', | ||
fieldLabel: t('options_provider_type'), | ||
value: typeValue, | ||
valueField: 'value', | ||
displayField: 'label', | ||
editable: false, | ||
forceSelection: true, | ||
queryMode: 'local', | ||
store: Ext.create('Ext.data.Store', { | ||
fields: ['value', 'label'], | ||
data: [ | ||
{value: this.OPTIONS_PROVIDER_TYPE_CONFIGURE, label: t('options_provider_type_configure')}, | ||
{value: this.OPTIONS_PROVIDER_TYPE_SELECT_OPTIONS, label: t('options_provider_type_select_options')}, | ||
{value: this.OPTIONS_PROVIDER_TYPE_CLASS, label: t('options_provider_type_class')} | ||
] | ||
}), | ||
listeners: { | ||
change: function (comboBox, newValue) { | ||
toggleFields(newValue); | ||
} | ||
} | ||
}); | ||
|
||
return [ | ||
optionsProviderType, | ||
optionsProviderClass, | ||
optionsProviderData, | ||
selectOptionsSelector | ||
]; | ||
}, | ||
|
||
/** | ||
* @returns {Ext.data.JsonStore} | ||
*/ | ||
getSelectOptionsStore: function () { | ||
if (this.selectOptionsStore === null) { | ||
this.selectOptionsStore = Ext.create('Ext.data.JsonStore', { | ||
fields: [ | ||
{name: 'id'}, | ||
{name: 'text'} | ||
], | ||
autoLoad: true, | ||
proxy: { | ||
type: 'ajax', | ||
url: Routing.generate('pimcore_admin_dataobject_class_selectoptionstree'), | ||
reader: { | ||
type: 'json' | ||
}, | ||
extraParams: { | ||
grouped: 0 | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
return this.selectOptionsStore; | ||
} | ||
}; |
Oops, something went wrong.