From c1158189e3820f520c83d63ffcdf60ae70f2ae8a Mon Sep 17 00:00:00 2001 From: Cliff Parnitzky Date: Thu, 10 Mar 2016 23:34:10 +0100 Subject: [PATCH] Remove checking attributes `disable` and `readonly`. Is not useful, is not supported by DCA and causes side effect problems (e.g. with `terminal42/contao-conditionalformfields`) --- .../forms/FormCalendarField.php | 143 +++++++++--------- 1 file changed, 70 insertions(+), 73 deletions(-) diff --git a/CT_ROOT/system/modules/hofff_calendarfield/forms/FormCalendarField.php b/CT_ROOT/system/modules/hofff_calendarfield/forms/FormCalendarField.php index 2c9cf3f..8f34c6e 100644 --- a/CT_ROOT/system/modules/hofff_calendarfield/forms/FormCalendarField.php +++ b/CT_ROOT/system/modules/hofff_calendarfield/forms/FormCalendarField.php @@ -73,78 +73,76 @@ public function parse($arrAttributes=null) $this->varValue = \Date::parse($dateFormat, strtotime($this->varValue)); } - if (!$this->readonly && !$this->disabled) { - - // Initialize the default config - $arrConfig = array( - 'showAnim' => "'fadeIn'", - 'showOtherMonths' => "true", - 'selectOtherMonths' => "true", - 'changeMonth' => "true", - 'changeYear' => "true" - ); - - switch ($this->dateDirection) { - case 'ltToday': - $time = strtotime('-1 day'); - $arrConfig['maxDate'] = 'new Date(' . date('Y', $time) . ', ' . (date('n', $time)-1) . ', ' . date('j', $time) . ')'; - break; - - case 'leToday': - $arrConfig['maxDate'] = 'new Date(' . date('Y') . ', ' . (date('n')-1) . ', ' . date('j') . ')'; - break; - - case 'geToday': - $arrConfig['minDate'] = 'new Date(' . date('Y') . ', ' . (date('n')-1) . ', ' . date('j') . ')'; - break; - - case 'gtToday': - $time = strtotime('+1 day'); - $arrConfig['minDate'] = 'new Date(' . date('Y', $time) . ', ' . (date('n', $time)-1) . ', ' . date('j', $time) . ')'; - break; - } - - if ($this->dateImage) { - // icon - $strIcon = 'assets/mootools/datepicker/'.DATEPICKER.'/icon.gif'; - - if (\Validator::isUuid($this->dateImageSRC)) { - $objFile = \FilesModel::findByPk($this->dateImageSRC); - - if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) { - $strIcon = $objFile->path; - } - } - - $arrSize = @getimagesize(TL_ROOT . '/' . $strIcon); - - $arrConfig['showOn'] = "'both'"; - $arrConfig['buttonImage'] = "'" . $strIcon . "'"; - $arrConfig['buttonImageOnly'] = "true"; - $arrConfig['buttonText'] = "'" . $GLOBALS['TL_LANG']['MSC']['calendarfield_tooltip'] . "'"; - } - - // correctly style the date format - $arrConfig['format'] = "'" . $this->dateformat_PHP_to_jQueryUI($dateFormat) . "'"; - - if (is_array($this->dateConfig)) { - $arrConfig = array_replace($arrConfig, $this->dateConfig); - } - - // HOOK: allow to customize the date picker - if (isset($GLOBALS['TL_HOOKS']['formCalendarField']) && is_array($GLOBALS['TL_HOOKS']['formCalendarField'])) { - foreach ($GLOBALS['TL_HOOKS']['formCalendarField'] as $callback) { - $objCallback = (method_exists($callback[0], 'getInstance') ? call_user_func(array($callback[0], 'getInstance')) : new $callback[0]()); - $arrConfig = $objCallback->$callback[1]($arrConfig, $this); - } - } - - $arrCompiledConfig = array(); - foreach ($arrConfig as $k => $v) { - $arrCompiledConfig[] = " '" . $k . "': " . $v; - } - - $this->calendarfieldScript .= " + // Initialize the default config + $arrConfig = array( + 'showAnim' => "'fadeIn'", + 'showOtherMonths' => "true", + 'selectOtherMonths' => "true", + 'changeMonth' => "true", + 'changeYear' => "true" + ); + + switch ($this->dateDirection) { + case 'ltToday': + $time = strtotime('-1 day'); + $arrConfig['maxDate'] = 'new Date(' . date('Y', $time) . ', ' . (date('n', $time)-1) . ', ' . date('j', $time) . ')'; + break; + + case 'leToday': + $arrConfig['maxDate'] = 'new Date(' . date('Y') . ', ' . (date('n')-1) . ', ' . date('j') . ')'; + break; + + case 'geToday': + $arrConfig['minDate'] = 'new Date(' . date('Y') . ', ' . (date('n')-1) . ', ' . date('j') . ')'; + break; + + case 'gtToday': + $time = strtotime('+1 day'); + $arrConfig['minDate'] = 'new Date(' . date('Y', $time) . ', ' . (date('n', $time)-1) . ', ' . date('j', $time) . ')'; + break; + } + + if ($this->dateImage) { + // icon + $strIcon = 'assets/mootools/datepicker/'.DATEPICKER.'/icon.gif'; + + if (\Validator::isUuid($this->dateImageSRC)) { + $objFile = \FilesModel::findByPk($this->dateImageSRC); + + if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) { + $strIcon = $objFile->path; + } + } + + $arrSize = @getimagesize(TL_ROOT . '/' . $strIcon); + + $arrConfig['showOn'] = "'both'"; + $arrConfig['buttonImage'] = "'" . $strIcon . "'"; + $arrConfig['buttonImageOnly'] = "true"; + $arrConfig['buttonText'] = "'" . $GLOBALS['TL_LANG']['MSC']['calendarfield_tooltip'] . "'"; + } + + // correctly style the date format + $arrConfig['format'] = "'" . $this->dateformat_PHP_to_jQueryUI($dateFormat) . "'"; + + if (is_array($this->dateConfig)) { + $arrConfig = array_replace($arrConfig, $this->dateConfig); + } + + // HOOK: allow to customize the date picker + if (isset($GLOBALS['TL_HOOKS']['formCalendarField']) && is_array($GLOBALS['TL_HOOKS']['formCalendarField'])) { + foreach ($GLOBALS['TL_HOOKS']['formCalendarField'] as $callback) { + $objCallback = (method_exists($callback[0], 'getInstance') ? call_user_func(array($callback[0], 'getInstance')) : new $callback[0]()); + $arrConfig = $objCallback->$callback[1]($arrConfig, $this); + } + } + + $arrCompiledConfig = array(); + foreach ($arrConfig as $k => $v) { + $arrCompiledConfig[] = " '" . $k . "': " . $v; + } + + $this->calendarfieldScript .= " "; - } return parent::parse($arrAttributes); }