diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/element/properties.js b/bundles/AdminBundle/Resources/public/js/pimcore/element/properties.js index d1ac62ff93a..b8f08c97d79 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/element/properties.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/element/properties.js @@ -1,4 +1,3 @@ - /** * Pimcore * @@ -75,7 +74,8 @@ pimcore.element.properties = Class.create({ ["document", "Document"], ["asset", "Asset"], ["object", "Object"], - ["bool", "Checkbox"] + ["bool", "Checkbox"], + ["date", "Date"] ] }); @@ -174,7 +174,9 @@ pimcore.element.properties = Class.create({ } } - + if (rec.data.type == 'date' && rec.data.data !== '') { + return new Date(v); + } return v; } }, @@ -466,6 +468,14 @@ pimcore.element.properties = Class.create({ } } else if (type == 'text') { return Ext.util.Format.htmlEncode(value); + } else if (type == 'date') { + if (value) { + if (!(value instanceof Date)) { + value = new Date(value); + } + return Ext.Date.format(value, "Y-m-d"); + } + return Ext.util.Format.htmlEncode(value); } return value; @@ -507,6 +517,12 @@ pimcore.element.properties = Class.create({ store: config.split(",") }); } + else if (type == "date") { + property = Ext.create('Ext.form.field.Date', { + format: "Y-m-d", + value: data.data ?? null + }); + } return property; }, @@ -658,6 +674,9 @@ pimcore.element.properties = Class.create({ if (type == "text") { value = ""; } + if (type == "date") { + value = ""; + } value = ""; } diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/settings/properties/predefined.js b/bundles/AdminBundle/Resources/public/js/pimcore/settings/properties/predefined.js index e7bc0f14338..b856259c15e 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/settings/properties/predefined.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/settings/properties/predefined.js @@ -142,7 +142,7 @@ pimcore.settings.properties.predefined = Class.create({ editor: new Ext.form.ComboBox({ triggerAction: 'all', editable: false, - store: ["text","document","asset","object","bool","select"] + store: ["text","document","asset","object","bool","select","date"] }) }, diff --git a/bundles/CoreBundle/Migrations/Version20240108140115.php b/bundles/CoreBundle/Migrations/Version20240108140115.php new file mode 100644 index 00000000000..f5f4cbdf52b --- /dev/null +++ b/bundles/CoreBundle/Migrations/Version20240108140115.php @@ -0,0 +1,35 @@ +hasTable('properties')) { + // Make sure the 'type' enum does not contain 'date' + $this->addSql("ALTER TABLE properties MODIFY COLUMN type ENUM('text','document','asset','object','bool','select')"); + // Add 'date' to the 'type' enum + $this->addSql("ALTER TABLE properties MODIFY COLUMN type ENUM('text','document','asset','object','bool','select','date')"); + } + } + + public function down(Schema $schema): void + { + // Remove 'date' from the 'type' enum + $this->addSql("ALTER TABLE properties MODIFY COLUMN type ENUM('text','document','asset','object','bool','select')"); + } +} diff --git a/models/Property.php b/models/Property.php index 21845bf1a8f..bdf16250d22 100644 --- a/models/Property.php +++ b/models/Property.php @@ -106,7 +106,8 @@ public function setDataFromResource($data) // IMPORTANT: if you use this method be sure that the type of the property is already set // do not set data for object, asset and document here, this is loaded dynamically when calling $this->getData(); if ($this->type == 'date') { - $this->data = \Pimcore\Tool\Serialize::unserialize($data); + $this->data = $data; +// $this->data = \Pimcore\Tool\Serialize::unserialize($data); } elseif ($this->type == 'bool') { $this->data = false; if (!empty($data)) { @@ -160,7 +161,7 @@ public function getName() } /** - * enum('text','document','asset','object','bool','select') + * enum('text','document','asset','object','bool','select','date') * * @return string */ @@ -225,7 +226,7 @@ public function setName($name) } /** - * enum('text','document','asset','object','bool','select') + * enum('text','document','asset','object','bool','select','date') * * @param string $type *