Skip to content

Commit

Permalink
Pass field layouts up to element-indexes/filter-hud
Browse files Browse the repository at this point in the history
Resolves #16289
  • Loading branch information
brandonkelly committed Dec 10, 2024
1 parent 7d1c189 commit cf5c8b2
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@
- Craft now keeps track of which site users registered from. When sending an email from the control panel, the current site is now set to the user’s affiliated site, if known. ([#16174](https://github.com/craftcms/cms/pull/16174))
- Database rows with foreign keys referencing nonexistent rows are now deleted via garbage collection.
- Updated Twig to 3.15. ([#16207](https://github.com/craftcms/cms/discussions/16207))
- Fixed a bug where embedded element index filter HUDs were including condition rules for fields that weren’t applicable to the nested elements. ([#16289](https://github.com/craftcms/cms/discussions/16289))
6 changes: 6 additions & 0 deletions src/controllers/ElementIndexesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use craft\helpers\ElementHelper;
use craft\helpers\Html;
use craft\helpers\StringHelper;
use craft\models\FieldLayout;
use craft\services\ElementSources;
use Throwable;
use yii\base\InvalidValueException;
Expand Down Expand Up @@ -427,6 +428,7 @@ public function actionFilterHud(): Response
$id = $this->request->getRequiredBodyParam('id');
$conditionConfig = $this->request->getBodyParam('conditionConfig');
$serialized = $this->request->getBodyParam('serialized');
$fieldLayouts = $this->request->getBodyParam('fieldLayouts');

$conditionsService = Craft::$app->getConditions();

Expand All @@ -443,6 +445,10 @@ public function actionFilterHud(): Response
$condition = $this->elementType()::createCondition();
}

if (!empty($fieldLayouts)) {
$condition->setFieldLayouts(array_map(fn(array $config) => FieldLayout::createFromConfig($config), $fieldLayouts));
}

$condition->mainTag = 'div';
$condition->id = $id;
$condition->addRuleLabel = Craft::t('app', 'Add a filter');
Expand Down
1 change: 1 addition & 0 deletions src/helpers/Cp.php
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,7 @@ public static function elementIndexHtml(string $elementType, array $config = [])
'hasThumbs' => $elementType::hasThumbs(),
'defaultSort' => $config['defaultSort'],
'defaultViewMode' => $config['defaultViewMode'],
'fieldLayouts' => $config['fieldLayouts'],
],
];

Expand Down
1 change: 1 addition & 0 deletions src/templates/_elements/sources.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'default-filter': source.defaultFilter ?? false,
'default-view-mode': source.defaultViewMode ?? false,
'view-modes': viewModes ?? [],
'field-layouts': source.fieldLayouts is defined ? source.fieldLayouts|map(layout => layout.getConfig()) : false,
}|merge(source.data ?? {}),
html: _self.sourceInnerHtml(source)
}) }}
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/web/assets/cp/src/js/BaseElementIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -4612,6 +4612,7 @@ const FilterHud = Garnish.HUD.extend({
condition: this.elementIndex.settings.condition,
conditionConfig: this.conditionConfig,
serialized: this.serialized,
fieldLayouts: this.elementIndex.$source.data('field-layouts'),
id: `${this.id}-filters`,
},
})
Expand Down

0 comments on commit cf5c8b2

Please sign in to comment.