Skip to content

Commit

Permalink
Merge branch '5.x' into 5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jan 4, 2025
2 parents 5548f20 + 22d6cd1 commit f72c989
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes for Craft CMS 5

## Unreleased

- Fixed a JavaScript error that could occur if there was a problem applying changes to field layout elements. ([#16380](https://github.com/craftcms/cms/issues/16380))
- Fixed a bug where field layout designers were validating field names, handles, and instructions, even if they weren’t overridden within the field instance. ([#16380](https://github.com/craftcms/cms/issues/16380))

## 5.5.8 - 2025-01-02

- Fixed a bug where custom fields were getting included in rendered field layout forms, even if their `getInputHtml()` method returned an empty string.
Expand Down
22 changes: 16 additions & 6 deletions src/controllers/FieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,14 +478,22 @@ public function actionApplyLayoutTabSettings(): Response
public function actionApplyLayoutElementSettings(): Response
{
/** @var FieldLayoutElement $element */
$element = $this->_fldComponent();
$element = $this->_fldComponent($settings);

if (!empty($settings)) {
$validateAttributes = array_intersect(
array_keys(array_filter($settings)),
['name', 'handle', 'instructions'],
);
}

if ($element instanceof CustomField) {
if (!empty($validateAttributes) && $element instanceof CustomField) {
$field = $element->getField();
if ($field instanceof Field) {
$field->validateHandleUniqueness = false;
}
if (!$field->validate(['name', 'handle', 'instructions'])) {

if (!$field->validate($validateAttributes)) {
if ($field->hasErrors('name')) {
$field->addErrors(['label' => $field->getErrors('name')]);
$field->clearErrors('name');
Expand Down Expand Up @@ -574,9 +582,10 @@ public function actionRenderCardPreview()
/**
* Returns the field layout component being edited, populated with the posted config/settings.
*
* @param array|null $settings The `settings` array that might have been posted
* @return FieldLayoutComponent
*/
private function _fldComponent(): FieldLayoutComponent
private function _fldComponent(?array &$settings = null): FieldLayoutComponent
{
$uid = $this->request->getRequiredBodyParam('uid');
$elementType = $this->request->getRequiredBodyParam('elementType');
Expand All @@ -593,9 +602,10 @@ private function _fldComponent(): FieldLayoutComponent
$settingsStr = $this->request->getBodyParam('settings');

if ($settingsStr !== null) {
parse_str($settingsStr, $settings);
parse_str($settingsStr, $postedSettings);
$settingsNamespace = $this->request->getRequiredBodyParam('settingsNamespace');
$componentConfig = array_merge($componentConfig, ArrayHelper::getValue($settings, $settingsNamespace, []));
$settings = ArrayHelper::getValue($postedSettings, $settingsNamespace, []);
$componentConfig = array_merge($componentConfig, $settings);
}

$isTab = false;
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/m230617_070415_entrify_matrix_blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function safeUp(): bool
'showSlugField' => false,
]);

$fieldLayoutUid = ArrayHelper::firstKey($blockTypeConfig['fieldLayouts'] ?? []);
$fieldLayoutUid = array_key_first($blockTypeConfig['fieldLayouts'] ?? []);
$fieldLayout = $fieldLayoutUid ? $fieldsService->getLayoutByUid($fieldLayoutUid) : new FieldLayout();
$fieldLayout->type = Entry::class;
$entryType->setFieldLayout($fieldLayout);
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.

25 changes: 13 additions & 12 deletions src/web/assets/cp/src/js/FieldLayoutDesigner.js
Original file line number Diff line number Diff line change
Expand Up @@ -1232,18 +1232,19 @@ Craft.FieldLayoutDesigner.Element = Garnish.Base.extend({
);
data = response.data;
} catch (e) {
let errors = e?.response?.data?.errors;

if (errors) {
Object.entries(errors).forEach(([name, fieldErrors]) => {
const $field = this.slideout.$container.find(
`[data-error-key="${name}"]`
);
if ($field) {
Craft.ui.addErrorsToField($field, fieldErrors);
this.fieldsWithErrors.push($field);
}
});
if (withSettings) {
let errors = e?.response?.data?.errors;
if (errors) {
Object.entries(errors).forEach(([name, fieldErrors]) => {
const $field = this.slideout.$container.find(
`[data-error-key="${name}"]`
);
if ($field) {
Craft.ui.addErrorsToField($field, fieldErrors);
this.fieldsWithErrors.push($field);
}
});
}
}

Craft.cp.displayError(e?.response?.data?.message);
Expand Down

0 comments on commit f72c989

Please sign in to comment.