Skip to content

Commit

Permalink
Make postDate and expiryDate delta namespaces
Browse files Browse the repository at this point in the history
Fixes bug where the first time an unpublished draft was saved, the placeholder post date would get emptied out (#11272 (comment)).
  • Loading branch information
brandonkelly committed May 24, 2022
1 parent 454bc7e commit 55a6460
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/elements/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -1612,12 +1612,13 @@ protected function tableAttributeHtml(string $attribute): string
public function metaFieldsHtml(bool $static): string
{
$fields = [];
$view = Craft::$app->getView();
$section = $this->getSection();
$user = Craft::$app->getUser()->getIdentity();

if ($section->type !== Section::TYPE_SINGLE) {
// Type
$fields[] = (function() use ($static) {
$fields[] = (function() use ($static, $view) {
$entryTypes = $this->getAvailableEntryTypes();
if (count($entryTypes) <= 1) {
return null;
Expand All @@ -1635,7 +1636,6 @@ public function metaFieldsHtml(bool $static): string
}

if (!$static) {
$view = Craft::$app->getView();
$typeInputId = $view->namespaceInputId('entryType');
$js = <<<EOD
(() => {
Expand Down Expand Up @@ -1702,7 +1702,7 @@ public function metaFieldsHtml(bool $static): string
if ($section->type !== Section::TYPE_SINGLE) {
// Author
if (Craft::$app->getEdition() === Craft::Pro && $user->can("viewPeerEntries:$section->uid")) {
$fields[] = (function() use ($static, $section) {
$fields[] = (function() use ($static, $view, $section) {
$author = $this->getAuthor();
return Cp::elementSelectFieldHtml([
'label' => Craft::t('app', 'Author'),
Expand All @@ -1720,6 +1720,12 @@ public function metaFieldsHtml(bool $static): string
})();
}

$isDeltaRegistrationActive = $view->getIsDeltaRegistrationActive();
$view->setIsDeltaRegistrationActive(true);
$view->registerDeltaName('postDate');
$view->registerDeltaName('expiryDate');
$view->setIsDeltaRegistrationActive($isDeltaRegistrationActive);

// Post Date
$fields[] = Cp::dateTimeFieldHtml([
'label' => Craft::t('app', 'Post Date'),
Expand Down

0 comments on commit 55a6460

Please sign in to comment.