Skip to content

Commit

Permalink
[Improvement] - Dynamic Option Provider (#361)
Browse files Browse the repository at this point in the history
* add context for Blocks/bricks/fieldcollection for select and multiselect option provider

* Use let instead of var as suggested

* Improve: remove if

---------

Co-authored-by: mattamon <[email protected]>
Co-authored-by: robertSt7 <[email protected]>
  • Loading branch information
3 people authored Nov 21, 2024
1 parent c97ec8c commit ecb4d67
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
17 changes: 17 additions & 0 deletions public/js/pimcore/object/tags/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,23 @@ pimcore.object.tags.block = Class.create(pimcore.object.tags.abstract, {

this.dataFields = {};
this.currentData = {};

this.updateBlockIndices();
},

updateBlockIndices: function() {
for (let itemIndex = 0; itemIndex < this.component.items.items.length; itemIndex++) {
let item = this.component.items.items[itemIndex];

for (let j = 0; j < this.currentElements.length; j++) {
if (item !== this.currentElements[j].container) continue;

const fields = this.currentElements[j].fields;
for (const fieldName in fields) {
fields[fieldName].context.index = itemIndex;
}
}
}
},

getDataForField: function (fieldConfig) {
Expand Down
3 changes: 2 additions & 1 deletion public/js/pimcore/object/tags/multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ pimcore.object.tags.multiselect = Class.create(pimcore.object.tags.abstract, {
params: {
objectId: this.object.id,
changedData: this.object.getSaveData().data,
fieldDefinition: JSON.stringify(this.fieldConfig)
fieldDefinition: JSON.stringify(this.fieldConfig),
context: JSON.stringify(this.context)
},
success: function (response) {
response = Ext.decode(response.responseText);
Expand Down
3 changes: 2 additions & 1 deletion public/js/pimcore/object/tags/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ pimcore.object.tags.select = Class.create(pimcore.object.tags.abstract, {
params: {
objectId: this.object.id,
changedData: this.object.getSaveData().data,
fieldDefinition: JSON.stringify(this.fieldConfig)
fieldDefinition: JSON.stringify(this.fieldConfig),
context: JSON.stringify(this.context)
},
success: function (response) {
response = Ext.decode(response.responseText);
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/Admin/DataObject/DataObjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,13 @@ public function getSelectOptions(Request $request): JsonResponse
: OptionsProviderResolver::MODE_SELECT
);

$context = json_decode($request->get('context'), true) ?? [];
$options = $optionsProvider->getOptions(
[
'object' => $object,
'fieldname' => $fieldDefinition->getName(),
'class' => $object->getClass(),
'context' => $context
],
$fieldDefinition
);
Expand Down

0 comments on commit ecb4d67

Please sign in to comment.