diff --git a/README.md b/README.md index 4732c0fb36c..36041ba4d70 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,7 @@ Most important changes will be listed here, all other changes since `19.4.0` can - bug fixes and PHP 7.x, 8.0, 8.1 and 8.2 compatibility - added config cache for system.xml ([#1916](https://github.com/OpenMage/magento-lts/pull/1916)) - added frontend_type color ([#2945](https://github.com/OpenMage/magento-lts/pull/2945)) +- added `label`, `date` and `datetime` picker field types to system.xml [#2739](https://github.com/OpenMage/magento-lts/pull/2739) - search for "NULL" in backend grids ([#1203](https://github.com/OpenMage/magento-lts/pull/1203)) - removed `lib/flex` containing unused ActionScript "file uploader" files ([#2271](https://github.com/OpenMage/magento-lts/pull/2271)) - Mage_Catalog_Model_Resource_Abstract::getAttributeRawValue() now returns `'0'` instead of `false` if the value stored in the database is `0` ([#572](https://github.com/OpenMage/magento-lts/pull/572)) diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/AbstractDate.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/AbstractDate.php new file mode 100644 index 00000000000..975314320c4 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/AbstractDate.php @@ -0,0 +1,89 @@ +getFieldConfig(); + + $type = $element->getType(); + if ($type !== 'date' && $type !== 'datetime' && $type !== 'text') { + Mage::throwException( + Mage::helper('adminhtml')->__( + 'Invalid frontend type for field "%s". Onyl "text", "date" and "datetime" are allowed.', + $field->descend('label') + ) + ); + } + + $format = Mage_Core_Helper_Date::getDateFormatFromString($field->format->__toString()); + $format = $this->getDateFormat($format); + + if (empty($field->editable)) { + return $this->getLocale() + ->date((int)$element->getValue()) + ->toString($format); + } + + $date = $this->getDateClass(); + $date->setData([ + 'name' => $element->getName(), + 'html_id' => $element->getId(), + 'image' => $this->getSkinUrl('images/grid-cal.gif'), + 'time' => $this->isShowTime() + ]); + $date->setFormat($format); + $date->setValue($element->getValue()); + $date->setForm($element->getForm()); + + return $date->getElementHtml(); + } + + /** + * @return Mage_Core_Model_Locale + */ + public function getLocale() + { + return Mage::app()->getLocale(); + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Date.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Date.php new file mode 100644 index 00000000000..2e3f1cf56e9 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Date.php @@ -0,0 +1,50 @@ +getLocale()->getDateFormat($format); + } + + /** + * @return false + */ + protected function isShowTime(): bool + { + return false; + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Datetime.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Datetime.php index ea6415eecd2..dda43b46393 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Datetime.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Datetime.php @@ -19,11 +19,30 @@ * @category Mage * @package Mage_Adminhtml */ -class Mage_Adminhtml_Block_System_Config_Form_Field_Datetime extends Mage_Adminhtml_Block_System_Config_Form_Field +class Mage_Adminhtml_Block_System_Config_Form_Field_Datetime extends Mage_Adminhtml_Block_System_Config_Form_Field_AbstractDate { - protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) + /** + * @return Varien_Data_Form_Element_Datetime + */ + protected function getDateClass(): Varien_Data_Form_Element_Datetime { - $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM); - return Mage::app()->getLocale()->date((int) $element->getValue())->toString($format); + return new Varien_Data_Form_Element_Datetime(); + } + + /** + * @param string $format + * @return string + */ + protected function getDateFormat(string $format): string + { + return $this->getLocale()->getDateTimeFormat($format); + } + + /** + * @return true + */ + protected function isShowTime(): bool + { + return true; } } diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Label.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Label.php new file mode 100644 index 00000000000..538a20d3127 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Label.php @@ -0,0 +1,51 @@ + + */ +class Mage_Adminhtml_Block_System_Config_Form_Field_Label extends Mage_Adminhtml_Block_System_Config_Form_Field +{ + /** + * @param Varien_Data_Form_Element_Abstract $element + * @return string + */ + protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) + { + $field = $element->getFieldConfig(); + + $type = $element->getType(); + if ($type !== 'label' && $type !== 'text') { + Mage::throwException( + Mage::helper('adminhtml')->__( + 'Invalid frontend type for field "%s". Onyl "text" and "label" are allowed.', + $field->descend('label') + ) + ); + } + + $label = new Varien_Data_Form_Element_Label(); + $label->setValue($field->descend('value')); + $label->setBold(!empty($field->descend('bold'))); + + return $label->getElementHtml(); + } +} diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/AbstractDate.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/AbstractDate.php new file mode 100644 index 00000000000..b7341e963d2 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/AbstractDate.php @@ -0,0 +1,85 @@ +getValue(); + if ($value !== '') { + $this->setValue($this->getLocale()->date($value)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + } + + return $this; + } + + /** + * @return $this + */ + protected function _beforeSave() + { + $value = (string)$this->getValue(); + if ($value !== '') { + $this->setValue($this->filterDateTime($value)); + } + + return $this; + } + + /** + * @param string $date + * @return string + */ + protected function filterDateTime(string $date): string + { + /** @var Mage_Core_Model_Config_Element $field */ + $field = $this->getFieldConfig(); + + $format = Mage_Core_Helper_Date::getDateFormatFromString($field->format->__toString()); + $format = $this->getDateFormat($format); + + $filterInput = new Zend_Filter_LocalizedToNormalized([ + 'date_format' => $format + ]); + + $date = $filterInput->filter($date); + + // convert to utc + return $this->getLocale()->utcDate(null, $date, true)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + } + + /** + * @return Mage_Core_Model_Locale + */ + public function getLocale() + { + return Mage::app()->getLocale(); + } +} diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Date.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Date.php new file mode 100644 index 00000000000..b3a4f607739 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Date.php @@ -0,0 +1,34 @@ +getLocale()->getDateFormat($format); + } +} diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Datetime.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Datetime.php new file mode 100644 index 00000000000..1f5df282686 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Datetime.php @@ -0,0 +1,34 @@ +getLocale()->getDateTimeFormat($format); + } +} diff --git a/app/code/core/Mage/Core/Helper/Date.php b/app/code/core/Mage/Core/Helper/Date.php new file mode 100644 index 00000000000..5dedaec6eed --- /dev/null +++ b/app/code/core/Mage/Core/Helper/Date.php @@ -0,0 +1,37 @@ +addClass('input-text'); $html = sprintf( - '' + '' . ' ', $this->getName(), $this->getHtmlId(),