Skip to content

Commit 3bbe61f

Browse files
committed
Better fix for #17091
Calling self::serializeValue() was breaking other field types, like relation fields https://github.com/craftcms/cms/actions/runs/14476047922/job/40601978956
1 parent 859bfff commit 3bbe61f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/base/Field.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,7 @@ public function serializeValueForDb(mixed $value, ElementInterface $element): mi
659659
return Db::prepareDateForDb($value);
660660
}
661661

662-
// specifically calling `self::…` here rather than `$this->…`
663-
// see https://github.com/craftcms/cms/pull/17091
664-
return self::serializeValue($value, $element);
662+
return $this->serializeValue($value, $element);
665663
}
666664

667665
/**

src/fields/Table.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use craft\gql\types\TableRow;
1717
use craft\helpers\Cp;
1818
use craft\helpers\DateTimeHelper;
19+
use craft\helpers\Db;
1920
use craft\helpers\Json;
2021
use craft\helpers\StringHelper;
2122
use craft\validators\ColorValidator;
@@ -557,7 +558,13 @@ public function serializeValueForDb(mixed $value, ElementInterface $element): mi
557558
$value = StringHelper::emojiToShortcodes(StringHelper::escapeShortcodes($value));
558559
}
559560

560-
$serializedRow[$colId] = parent::serializeValueForDb($value ?? null, $element);
561+
// can't call parent::serializeValueForDb() here because that calls $this->serializeValue()
562+
// see https://github.com/craftcms/cms/pull/17091
563+
if ($value instanceof DateTime || DateTimeHelper::isIso8601($value)) {
564+
$serializedRow[$colId] = Db::prepareDateForDb($value);
565+
} else {
566+
$serializedRow[$colId] = parent::serializeValue($value, $element);
567+
}
561568
}
562569
$serialized[] = $serializedRow;
563570
}

0 commit comments

Comments
 (0)