Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enabled & implemented date property for all entities #24

Open
wants to merge 2 commits into
base: 10.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* Pimcore
*
Expand Down Expand Up @@ -75,7 +74,8 @@ pimcore.element.properties = Class.create({
["document", "Document"],
["asset", "Asset"],
["object", "Object"],
["bool", "Checkbox"]
["bool", "Checkbox"],
["date", "Date"]
]
});

Expand Down Expand Up @@ -174,7 +174,9 @@ pimcore.element.properties = Class.create({
}

}

if (rec.data.type == 'date' && rec.data.data !== '') {
return new Date(v);
}
return v;
}
},
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
},
Expand Down Expand Up @@ -658,6 +674,9 @@ pimcore.element.properties = Class.create({
if (type == "text") {
value = "";
}
if (type == "date") {
value = "";
}
value = "";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

})
},
Expand Down
35 changes: 35 additions & 0 deletions bundles/CoreBundle/Migrations/Version20240108140115.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Pimcore\Bundle\CoreBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240108140115 extends AbstractMigration
{
public function getDescription(): string
{
return 'add date to enum for properties';
}

public function up(Schema $schema): void
{
if ($schema->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')");
}
}
7 changes: 4 additions & 3 deletions models/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -160,7 +161,7 @@ public function getName()
}

/**
* enum('text','document','asset','object','bool','select')
* enum('text','document','asset','object','bool','select','date')
*
* @return string
*/
Expand Down Expand Up @@ -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
*
Expand Down
Loading