Skip to content

Commit

Permalink
Drop the fieldId stuff, and fix provisional draft deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Oct 17, 2024
1 parent cdb7c87 commit 7f6cf6d
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 39 deletions.
1 change: 0 additions & 1 deletion src/base/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -3632,7 +3632,6 @@ protected function safeActionMenuItems(): array
'draftId' => $this->isProvisionalDraft ? null : $this->draftId,
'revisionId' => $this->revisionId,
'siteId' => $this->siteId,
'fieldId' => $this instanceof NestedElementInterface ? $this->getField()?->id : null,
'ownerId' => $this instanceof NestedElementInterface ? $this->getOwnerId() : null,
],
]);
Expand Down
5 changes: 1 addition & 4 deletions src/controllers/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,6 @@ public function actionRenderElements(): Response
/** @var string|ElementInterface $elementType */
$elementType = $criterion['type'];
$id = $criterion['id'];
$fieldId = $criterion['fieldId'] ?? null;
$ownerId = $criterion['ownerId'] ?? null;
$siteId = $criterion['siteId'];
$instances = $criterion['instances'];
Expand All @@ -780,9 +779,7 @@ public function actionRenderElements(): Response
->status(null);

if ($query instanceof NestedElementQueryInterface) {
$query
->fieldId($fieldId)
->ownerId($ownerId);
$query->ownerId($ownerId);
}

$elements = $query->all();
Expand Down
17 changes: 1 addition & 16 deletions src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class ElementsController extends Controller
private ?string $_elementUid = null;
private ?int $_draftId = null;
private ?int $_revisionId = null;
private ?int $_fieldId = null;
private ?int $_ownerId = null;
private ?int $_siteId = null;

Expand Down Expand Up @@ -117,7 +116,6 @@ public function beforeAction($action): bool
$this->_elementUid = $this->_param('elementUid');
$this->_draftId = $this->_param('draftId');
$this->_revisionId = $this->_param('revisionId');
$this->_fieldId = $this->_param('fieldId');
$this->_ownerId = $this->_param('ownerId');
$this->_siteId = $this->_param('siteId');
$this->_enabled = $this->_param('enabled', $this->_param('setEnabled', true) ? true : null);
Expand Down Expand Up @@ -433,7 +431,6 @@ public function actionEdit(?ElementInterface $element, ?int $elementId = null):
'previewToken' => $previewTargets ? $security->generateRandomString() : null,
'previewParamValue' => $previewTargets ? $security->hashData(StringHelper::randomString(10)) : null,
'revisionId' => $element->revisionId,
'fieldId' => $element instanceof NestedElementInterface ? $element->getField()?->id : null,
'ownerId' => $element instanceof NestedElementInterface ? $element->getOwnerId() : null,
'siteId' => $element->siteId,
'siteStatuses' => $siteStatuses,
Expand Down Expand Up @@ -2221,9 +2218,7 @@ private function _elementQuery(string $elementType): ElementQueryInterface
/** @var string|ElementInterface $elementType */
$query = $elementType::find();
if ($query instanceof NestedElementQueryInterface) {
$query
->fieldId($this->_fieldId)
->ownerId($this->_ownerId);
$query->ownerId($this->_ownerId);
}
return $query;
}
Expand All @@ -2249,16 +2244,6 @@ private function _createElement(): ElementInterface
}
$element->setAttributesFromRequest($this->_attributes);

// if ($element instanceof NestedElementInterface) {
// if (isset($this->_ownerId)) {
// $element->setOwnerId($this->_ownerId);
// }
// // todo: add NestedElementInterface::setField() / setFieldId()
// if (isset($this->_fieldId) && property_exists($element, 'fieldId')) {
// $element->fieldId = $this->_fieldId;
// }
// }

if (!Craft::$app->getElements()->canSave($element)) {
throw new ForbiddenHttpException('User not authorized to create this element.');
}
Expand Down
1 change: 0 additions & 1 deletion src/helpers/Cp.php
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,6 @@ private static function baseElementAttributes(ElementInterface $element, array $
'id' => $element->isProvisionalDraft ? $element->getCanonicalId() : $element->id,
'draft-id' => $element->isProvisionalDraft ? null : $element->draftId,
'revision-id' => $element->revisionId,
'field-id' => $element instanceof NestedElementInterface ? $element->getField()?->id : null,
'owner-id' => $element instanceof NestedElementInterface ? $element->getOwnerId() : null,
'site-id' => $element->siteId,
'status' => $element->getStatus(),
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: 0 additions & 1 deletion src/web/assets/cp/src/js/Craft.js
Original file line number Diff line number Diff line change
Expand Up @@ -2453,7 +2453,6 @@ $.extend(Craft, {
key: i,
type: $element.data('type'),
id: elementId,
fieldId: $element.data('field-id'),
ownerId: $element.data('owner-id'),
siteId,
instances: [],
Expand Down
9 changes: 2 additions & 7 deletions src/web/assets/cp/src/js/ElementEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ Craft.ElementEditor = Garnish.Base.extend(
redirect: this.settings.hashedCpEditUrl,
params: {
draftId: this.settings.draftId,
ownerId: this.settings.ownerId,
provisional: 1,
},
});
Expand All @@ -433,6 +434,7 @@ Craft.ElementEditor = Garnish.Base.extend(
data: {
elementId: this.settings.canonicalId,
draftId: this.settings.draftId,
ownerId: this.settings.ownerId,
siteId: this.settings.siteId,
provisional: 1,
},
Expand Down Expand Up @@ -1649,12 +1651,6 @@ Craft.ElementEditor = Garnish.Base.extend(
);
}

if (this.settings.fieldId !== null) {
params.push(
`${this.namespaceInputName('fieldId')}=${this.settings.fieldId}`
);
}

if (this.settings.ownerId !== null) {
params.push(
`${this.namespaceInputName('ownerId')}=${this.settings.ownerId}`
Expand Down Expand Up @@ -2311,7 +2307,6 @@ Craft.ElementEditor = Garnish.Base.extend(
previewToken: null,
previewParamValue: null,
revisionId: null,
fieldId: null,
ownerId: null,
siteId: null,
siteStatuses: [],
Expand Down
7 changes: 0 additions & 7 deletions src/web/assets/cp/src/js/ElementEditorSlideout.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ Craft.ElementEditorSlideout = Craft.CpScreenSlideout.extend(
params.revisionId = this.$element.data('revision-id');
}

if (this.settings.fieldId) {
params.fieldId = this.settings.fieldId;
} else if (this.$element?.data('field-id')) {
params.fieldId = this.$element.data('field-id');
}

if (this.settings.ownerId) {
params.ownerId = this.settings.ownerId;
} else if (this.$element?.data('owner-id')) {
Expand Down Expand Up @@ -185,7 +179,6 @@ Craft.ElementEditorSlideout = Craft.CpScreenSlideout.extend(
elementId: null,
draftId: null,
revisionId: null,
fieldId: null,
ownerId: null,
elementType: null,
siteId: null,
Expand Down

0 comments on commit 7f6cf6d

Please sign in to comment.