Skip to content

Commit e70fd09

Browse files
committed
Fixed a couple address provisional draft bugs
1 parent b20ba73 commit e70fd09

11 files changed

Lines changed: 35 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Fixed a styling bug.
66
- Fixed a bug `craft\services\Categories::saveGroup()` and `craft\services\Tags::saveTagGroup()` weren’t respecting predefined UUID values on new models.
77
- Fixed an error that could occur when editing a nested Matrix entry in a slideout or full-page editor, if it was initially edited while the Matrix field was in inline-editable blocks mode.
8+
- Fixed an error that could occur when editing an address that had provisional changes.
9+
- Fixed a bug where address cards weren’t showing provisional changes.
810

911
## 5.4.9 - 2024-10-22
1012

src/base/Element.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2893,7 +2893,9 @@ public function getCanonical(bool $anySite = false): ElementInterface
28932893
->ignorePlaceholders();
28942894

28952895
if ($this instanceof NestedElementInterface && $query instanceof NestedElementQueryInterface) {
2896-
$query->ownerId($this->getOwnerId());
2896+
$query
2897+
->fieldId($this->getField()?->id)
2898+
->ownerId($this->getOwnerId());
28972899
}
28982900

28992901
$this->$prop = $query->one();

src/controllers/AppController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ public function actionRenderElements(): Response
762762
/** @var string|ElementInterface $elementType */
763763
$elementType = $criterion['type'];
764764
$id = $criterion['id'];
765+
$fieldId = $criterion['fieldId'] ?? null;
765766
$ownerId = $criterion['ownerId'] ?? null;
766767
$siteId = $criterion['siteId'];
767768
$instances = $criterion['instances'];
@@ -779,7 +780,9 @@ public function actionRenderElements(): Response
779780
->status(null);
780781

781782
if ($query instanceof NestedElementQueryInterface) {
782-
$query->ownerId($ownerId);
783+
$query
784+
->fieldId($fieldId)
785+
->ownerId($ownerId);
783786
}
784787

785788
$elements = $query->all();

src/controllers/ElementsController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class ElementsController extends Controller
7474
private ?string $_elementUid = null;
7575
private ?int $_draftId = null;
7676
private ?int $_revisionId = null;
77+
private ?int $_fieldId = null;
7778
private ?int $_ownerId = null;
7879
private ?int $_siteId = null;
7980

@@ -116,6 +117,7 @@ public function beforeAction($action): bool
116117
$this->_elementUid = $this->_param('elementUid');
117118
$this->_draftId = $this->_param('draftId');
118119
$this->_revisionId = $this->_param('revisionId');
120+
$this->_fieldId = $this->_param('fieldId') ?: null;
119121
$this->_ownerId = $this->_param('ownerId') ?: null;
120122
$this->_siteId = $this->_param('siteId');
121123
$this->_enabled = $this->_param('enabled', $this->_param('setEnabled', true) ? true : null);
@@ -431,6 +433,7 @@ public function actionEdit(?ElementInterface $element, ?int $elementId = null):
431433
'previewToken' => $previewTargets ? $security->generateRandomString() : null,
432434
'previewParamValue' => $previewTargets ? $security->hashData(StringHelper::randomString(10)) : null,
433435
'revisionId' => $element->revisionId,
436+
'fieldId' => $element instanceof NestedElementInterface ? $element->getField()?->id : null,
434437
'ownerId' => $element instanceof NestedElementInterface ? $element->getOwnerId() : null,
435438
'siteId' => $element->siteId,
436439
'siteStatuses' => $siteStatuses,
@@ -2227,7 +2230,9 @@ private function _elementQuery(string $elementType): ElementQueryInterface
22272230
/** @var string|ElementInterface $elementType */
22282231
$query = $elementType::find();
22292232
if ($query instanceof NestedElementQueryInterface) {
2230-
$query->ownerId($this->_ownerId);
2233+
$query
2234+
->fieldId($this->_fieldId)
2235+
->ownerId($this->_ownerId);
22312236
}
22322237
return $query;
22332238
}

src/helpers/Cp.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ private static function baseElementAttributes(ElementInterface $element, array $
872872
'id' => $element->isProvisionalDraft ? $element->getCanonicalId() : $element->id,
873873
'draft-id' => $element->isProvisionalDraft ? null : $element->draftId,
874874
'revision-id' => $element->revisionId,
875+
'field-id' => $element instanceof NestedElementInterface ? $element->getField()?->id : null,
875876
'owner-id' => $element instanceof NestedElementInterface ? $element->getOwnerId() : null,
876877
'site-id' => $element->siteId,
877878
'status' => $element->getStatus(),

src/helpers/ElementHelper.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,10 +1003,6 @@ public static function swapInProvisionalDrafts(array &$elements): void
10031003

10041004
$first = reset($canonicalElements);
10051005

1006-
if (!$first::hasDrafts()) {
1007-
return;
1008-
}
1009-
10101006
$drafts = $first::find()
10111007
->draftOf($canonicalElements)
10121008
->draftCreator($user)

src/web/assets/cp/dist/cp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/cp/dist/cp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/cp/src/js/Craft.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,6 +2453,7 @@ $.extend(Craft, {
24532453
key: i,
24542454
type: $element.data('type'),
24552455
id: elementId,
2456+
fieldId: $element.data('field-id'),
24562457
ownerId: $element.data('owner-id'),
24572458
siteId,
24582459
instances: [],

src/web/assets/cp/src/js/ElementEditor.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ Craft.ElementEditor = Garnish.Base.extend(
425425
redirect: this.settings.hashedCpEditUrl,
426426
params: {
427427
draftId: this.settings.draftId,
428+
fieldId: this.settings.fieldId,
428429
ownerId: this.settings.ownerId,
429430
provisional: 1,
430431
},
@@ -434,6 +435,7 @@ Craft.ElementEditor = Garnish.Base.extend(
434435
data: {
435436
elementId: this.settings.canonicalId,
436437
draftId: this.settings.draftId,
438+
fieldId: this.settings.fieldId,
437439
ownerId: this.settings.ownerId,
438440
siteId: this.settings.siteId,
439441
provisional: 1,
@@ -1651,6 +1653,12 @@ Craft.ElementEditor = Garnish.Base.extend(
16511653
);
16521654
}
16531655

1656+
if (this.settings.fieldId !== null) {
1657+
params.push(
1658+
`${this.namespaceInputName('fieldId')}=${this.settings.fieldId}`
1659+
);
1660+
}
1661+
16541662
if (this.settings.ownerId !== null) {
16551663
params.push(
16561664
`${this.namespaceInputName('ownerId')}=${this.settings.ownerId}`
@@ -2313,6 +2321,7 @@ Craft.ElementEditor = Garnish.Base.extend(
23132321
previewToken: null,
23142322
previewParamValue: null,
23152323
revisionId: null,
2324+
fieldId: null,
23162325
ownerId: null,
23172326
siteId: null,
23182327
siteStatuses: [],

0 commit comments

Comments
 (0)