Skip to content

Commit

Permalink
Merge pull request #121 from pimcore/optimized-perspective-creation
Browse files Browse the repository at this point in the history
Optimized `perspective` and `view` creation
  • Loading branch information
lukmzig committed Mar 20, 2023
2 parents 45485eb + 6ae4d56 commit 1697905
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Resources/public/js/pimcore/perspective/perspective.js
Expand Up @@ -104,6 +104,8 @@ pimcore.bundle.perspectiveeditor.PerspectiveEditor = class {
disabled: !pimcore.settings['perspectives-writeable'],
handler: function(){
Ext.MessageBox.prompt(t('plugin_pimcore_perspectiveeditor_new_perspective'), t('plugin_pimcore_perspectiveeditor_new_perspective'), function (button, value) {
value = this.sanitizeName(value);

if (button === 'ok' && value.length > 0) {
//check for configs with same name
let match = this.perspectiveTreeStore.findExact("name", value);
Expand Down Expand Up @@ -824,4 +826,8 @@ pimcore.bundle.perspectiveeditor.PerspectiveEditor = class {
}
}
}

sanitizeName (name) {
return name.replace(/[^a-z0-9_\-.+]/gi,'');
}
}
6 changes: 6 additions & 0 deletions src/Resources/public/js/pimcore/perspective/view.js
Expand Up @@ -86,6 +86,8 @@ pimcore.bundle.perspectiveeditor.ViewEditor = class {
disabled: !pimcore.settings['custom-views-writeable'],
handler: function () {
Ext.MessageBox.prompt(t('plugin_pimcore_perspectiveeditor_new_view'), t('plugin_pimcore_perspectiveeditor_new_view'), function (button, value) {
value = this.sanitizeName(value);

if (button === 'ok' && value.length > 0) {
const record = this.viewTreeStore.getRoot().appendChild({
id: pimcore.bundle.perspectiveeditor.PerspectiveViewHelper.generateUuid(),
Expand Down Expand Up @@ -567,4 +569,8 @@ pimcore.bundle.perspectiveeditor.ViewEditor = class {
}
}
}

sanitizeName (name) {
return name.replace(/[^a-z0-9_\-.+]/gi,'');
}
}
2 changes: 1 addition & 1 deletion src/Services/PerspectiveAccessor.php
Expand Up @@ -24,7 +24,7 @@ protected function convertTreeStoreToConfiguration($treeStore)
$configuration = [];

foreach ($treeStore['children'] as $child) {
$name = $child['name'];
$name = htmlspecialchars($child['name']);
$configuration[$name] = [];
$configuration[$name]['elementTree'] = [];
foreach ($child['children'] as $index => $element) {
Expand Down
4 changes: 4 additions & 0 deletions src/Services/ViewAccessor.php
Expand Up @@ -39,6 +39,10 @@ protected function convertTreeStoreToConfiguration($treeStore)

if (isset($treeStore['children'])) {
foreach ($treeStore['children'] as $child) {
if (array_key_exists('name', $child['config'])) {
$child['config']['name'] = htmlspecialchars($child['config']['name']);
}

if (!empty($child['config']['treeContextMenu'])) {
foreach (array_keys($child['config']['treeContextMenu']) as $contextMenuEntry) {
if (substr($child['config']['treetype'], 0, strlen($contextMenuEntry)) != $contextMenuEntry) {
Expand Down

0 comments on commit 1697905

Please sign in to comment.