Skip to content

Commit

Permalink
Merge branch '4.6' of https://github.com/craftcms/cms into 5.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	src/web/assets/cp/dist/cp.js
#	src/web/assets/cp/dist/cp.js.map
  • Loading branch information
brandonkelly committed Jan 9, 2024
2 parents e5d6cd8 + 3cbca7f commit 42475f2
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/fields/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,6 @@ protected function inputTemplateVariables(array|ElementQueryInterface $value = n
$variables['defaultSourcePath'] = array_map(function(VolumeFolder $folder) {
return $folder->getSourcePathInfo();
}, $folders);
$variables['preferStoredSource'] = true;
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/fields/BaseRelationField.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ public function isValueEmpty(mixed $value, ElementInterface $element): bool
*/
public function normalizeValue(mixed $value, ?ElementInterface $element): mixed
{
if ($value instanceof ElementQueryInterface) {
if ($value instanceof ElementQueryInterface || $value instanceof ElementCollection) {
return $value;
}

Expand Down Expand Up @@ -1301,7 +1301,12 @@ public function getInputSelectionCriteria(): array
public function getSelectionCondition(): ?ElementConditionInterface
{
if ($this->_selectionCondition !== null && !$this->_selectionCondition instanceof ConditionInterface) {
$this->_selectionCondition = Craft::$app->getConditions()->createCondition($this->_selectionCondition);
$condition = Craft::$app->getConditions()->createCondition($this->_selectionCondition);
if (!empty($condition->getConditionRules())) {
$this->_selectionCondition = $condition;
} else {
$this->_selectionCondition = null;
}
}

return $this->_selectionCondition;
Expand Down
18 changes: 17 additions & 1 deletion src/gql/base/ElementMutationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\WrappingType;
use yii\web\ServerErrorHttpException;

/**
* Class MutationResolver
Expand Down Expand Up @@ -160,7 +161,22 @@ protected function saveElement(ElementInterface $element): ElementInterface
$element->setScenario(Element::SCENARIO_LIVE);
}

Craft::$app->getElements()->saveElement($element);
$isNotNew = $element->id;
if ($isNotNew) {
$lockKey = "element:$element->id";
$mutex = Craft::$app->getMutex();
if (!$mutex->acquire($lockKey, 15)) {
throw new ServerErrorHttpException('Could not acquire a lock to save the element.');
}
}

try {
Craft::$app->getElements()->saveElement($element);
} finally {
if ($isNotNew) {
$mutex->release($lockKey);
}
}

if ($element->hasErrors()) {
$validationErrors = [];
Expand Down
10 changes: 4 additions & 6 deletions src/helpers/FileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -900,13 +900,11 @@ public static function getExtensionByMimeType($mimeType, $preferShort = false, $
*/
public static function deleteFileAfterRequest(string $filename): void
{
self::$_filesToBeDeleted[] = $filename;

if (count(self::$_filesToBeDeleted) === 1) {
Craft::$app->onAfterRequest(function() {
static::deleteQueuedFiles();
});
if (empty(self::$_filesToBeDeleted)) {
register_shutdown_function([static::class, 'deleteQueuedFiles']);
}

self::$_filesToBeDeleted[] = $filename;
}

/**
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.

18 changes: 13 additions & 5 deletions src/web/assets/cp/src/js/BaseElementIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,12 @@ Craft.BaseElementIndex = Garnish.Base.extend(

// Grab the localStorage step key up front, so we don's lose track of it when the default source's default
// source path is selected
const stepKey = this.getSelectedSourceState('sourcePathStep');
let stepKey;
if (this.settings.context === 'index') {
stepKey = this.getSelectedSourceState('sourcePathStep');
} else {
stepKey = this.instanceState.sourcePathStep || null;
}

this.selectDefaultSource();

Expand Down Expand Up @@ -1041,14 +1046,17 @@ Craft.BaseElementIndex = Garnish.Base.extend(
}

// Store the source path
this.setSelecetedSourceState(
'sourcePathStep',
const sourcePathStep =
(this.sourcePaths[this.sourceKey]
? this.sourcePaths[this.sourceKey][
this.sourcePaths[this.sourceKey].length - 1
].key
: null) || null
);
: null) || null;
if (this.settings.context === 'index') {
this.setSelecetedSourceState('sourcePathStep', sourcePathStep);
} else {
this.setInstanceState('sourcePathStep', sourcePathStep);
}

this.onSourcePathChange();
},
Expand Down
12 changes: 11 additions & 1 deletion src/web/assets/cp/src/js/BaseElementSelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Craft.BaseElementSelectInput = Garnish.Base.extend(
elementSort: null,
modal: null,
elementEditor: null,
modalFirstOpen: true,

$container: null,
$form: null,
Expand Down Expand Up @@ -638,6 +639,7 @@ Craft.BaseElementSelectInput = Garnish.Base.extend(

if (!this.modal) {
this.modal = this.createModal();
this.modalFirstOpen = false;
} else {
this.modal.show();
}
Expand All @@ -651,7 +653,7 @@ Craft.BaseElementSelectInput = Garnish.Base.extend(
},

getModalSettings: function () {
return $.extend(
const settings = $.extend(
{
closeOtherModals: false,
storageKey: this.modalStorageKey,
Expand All @@ -671,6 +673,14 @@ Craft.BaseElementSelectInput = Garnish.Base.extend(
},
this.settings.modalSettings
);

// make sure the previously-selected source is retained each time the
// modal is re-opened
if (!this.modalFirstOpen) {
settings.preferStoredSource = true;
}

return settings;
},

getSelectedElementIds: function () {
Expand Down

0 comments on commit 42475f2

Please sign in to comment.