Skip to content

Commit

Permalink
secure field type date
Browse files Browse the repository at this point in the history
  • Loading branch information
PrestaSafe committed Jun 25, 2024
1 parent 70bb81e commit 59f5d84
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions classes/prettyblocks/core/FieldCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class FieldCore
public $allow_html = false;
public $id_lang = 0;
public $id_shop = 0;
public $options = [];

/**
* __construct
Expand Down Expand Up @@ -144,6 +145,9 @@ public function compile()
if ($this->force_default_value) {
$data['force_default_value'] = $this->force_default_value;
}
if($this->options) {
$data['options'] = $this->options;
}

$data['value'] = $this->format();

Expand Down Expand Up @@ -196,7 +200,6 @@ public function getFormattedValue()
public function format()
{
$method = 'formatField' . ucwords(str_replace('_', '', $this->type));

if (method_exists($this, $method)) {
return $this->{$method}();
}
Expand Down Expand Up @@ -234,17 +237,23 @@ public function formatForFront()
*/
public function formatFieldDatepicker()
{
$format = 'Y-m-d';
// if(isset($this->options['dateFormat'])) {
// $format = $this->options['dateFormat'];
// }
// if value exists in DB and new_value is empty
if (!is_null($this->value) && is_null($this->new_value)) {
return \DateTime::createFromFormat('Y-m-d', $this->value)->format('Y-m-d');
$date = \DateTime::createFromFormat($format, $this->value);
return $date ? $date->format($format) : date($format);
}
// if value doesn't exists in DB and new value is set
if ($this->force_default_value && is_null($this->new_value)) {
return \DateTime::createFromFormat('Y-m-d', $this->default)->format('Y-m-d');
$date = \DateTime::createFromFormat($format, $this->default);
return $date ? $date->format($format) : date($format);
}

// dump($this->new_value);
return \DateTime::createFromFormat('Y-m-d\TH:i:s.u\Z', $this->new_value)->format('Y-m-d');
// default format from vuedatepicker
$date = \DateTime::createFromFormat('Y-m-d\TH:i:s.u\Z', $this->new_value);
return $date ? $date->format($format) : date($format);
}

/**
Expand Down

0 comments on commit 59f5d84

Please sign in to comment.