-
Notifications
You must be signed in to change notification settings - Fork 98
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 (#291)
* Manage Select options Vis interface * Move the event CLASS_SELECTOPTIONS_UPDATE_CONFIGURATION to admin-bundle * Moved src/OptionsProvider/SelectOptionsOptionsProvider.php to the Core * Renamed the option 'Class/Service' to 'Options Provider' * Update namespace of options provider * Fix PHP Stan * Small refactoring * Use ::class for SelectOptionsOptionsProvider --------- Co-authored-by: K J Kooistra <[email protected]>
- Loading branch information
1 parent
e414e6b
commit e9ad0da
Showing
16 changed files
with
1,186 additions
and
20 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
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 | ||
); | ||
} | ||
}; |
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.settings.select_options_provider_class); | ||
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.