Skip to content

Commit

Permalink
Fix Contao 5 errors (see #57 )
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffparnitzky committed Jun 20, 2023
1 parent 0f5f1cc commit 4924fd5
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/Resources/contao/forms/FormCalendarField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
*/
namespace Hofff\Contao\Calendarfield;

class FormCalendarField extends \FormTextField
use Contao\CoreBundle\Exception\InternalServerErrorException;
use Contao\Date;
use Contao\FilesModel;
use Contao\FormTextField;
use Contao\StringUtil;
use Contao\System;
use Contao\Validator;

class FormCalendarField extends FormTextField
{
const DATE_FORMAT_PHP = "d-m-Y";

Expand Down Expand Up @@ -59,7 +67,7 @@ public function parse($arrAttributes=null)
$dateFormat = $this->dateFormat ? $this->dateFormat : $objPage->dateFormat;
if ($this->dateParseValue && $this->varValue != '')
{
$this->varValue = \Date::parse($dateFormat, strtotime($this->varValue));
$this->varValue = Date::parse($dateFormat, strtotime($this->varValue));
}
$this->dateFormat = $dateFormat;

Expand All @@ -74,7 +82,7 @@ public function parse($arrAttributes=null)
break;
case 'gtToday' : $this->minDate = "new Date().fp_incr(1)";
break;
case 'ownMinMax': $arrMinMax = \StringUtil::deserialize($this->dateDirectionMinMax, true);
case 'ownMinMax': $arrMinMax = StringUtil::deserialize($this->dateDirectionMinMax, true);
if (!empty($arrMinMax[0]))
{
$this->minDate = sprintf("new Date().fp_incr(%s)", $arrMinMax[0]);
Expand All @@ -88,10 +96,10 @@ public function parse($arrAttributes=null)

if ($this->dateImage) {
$strIcon = '';
if (\Validator::isUuid($this->dateImageSRC)) {
$objModel = \FilesModel::findByUuid($this->dateImageSRC);
if (Validator::isUuid($this->dateImageSRC)) {
$objModel = FilesModel::findByUuid($this->dateImageSRC);

if ($objModel !== null && is_file(\System::getContainer()->getParameter('kernel.project_dir') . '/' . $objModel->path))
if ($objModel !== null && is_file(System::getContainer()->getParameter('kernel.project_dir') . '/' . $objModel->path))
{
$strIcon = $objModel->path;
$arrData = array(
Expand All @@ -109,7 +117,7 @@ public function parse($arrAttributes=null)
}

// add the disallowed weekdays to the template
$this->disabledWeekdays = \StringUtil::deserialize($this->dateDisabledWeekdays, true);
$this->disabledWeekdays = StringUtil::deserialize($this->dateDisabledWeekdays, true);

// add the disallowed days to the template
$this->disabledDays = $this->getActiveDisabledDays($dateFormat);
Expand All @@ -132,7 +140,7 @@ public function generate()

public function validator($varInput)
{
$objToday = new \Date();
$objToday = new Date();

$intTstamp = 0;
$dateFormat = $this->dateFormat ?: $GLOBALS['TL_CONFIG'][$this->rgxp . 'Format'];
Expand All @@ -154,7 +162,7 @@ public function validator($varInput)
// Convert timestamps
try
{
$objDate = new \Date($varInput, $dateFormat);
$objDate = new Date($varInput, $dateFormat);
$intTstamp = $objDate->tstamp;
}
catch (\Exception $e)
Expand Down Expand Up @@ -191,7 +199,7 @@ public function validator($varInput)
}

//validate disallowed weekdays
$disabledWeekdays = \StringUtil::deserialize($this->dateDisabledWeekdays, true);
$disabledWeekdays = StringUtil::deserialize($this->dateDisabledWeekdays, true);
if (in_array(date("w", $intTstamp), $disabledWeekdays))
{
$this->addError($GLOBALS['TL_LANG']['ERR']['calendarfield_disabled_weekday']);
Expand Down Expand Up @@ -225,7 +233,7 @@ public function getRegexp($strFormat = false)

if (preg_match('/[BbCcDEeFfIJKkLlMNOoPpQqRrSTtUuVvWwXxZz]+/', $strFormat))
{
throw new \Exception(sprintf('Invalid date format "%s"', $strFormat));
throw new InternalServerErrorException(sprintf('Invalid date format "%s"', $strFormat));
}

$strRegexp = '';
Expand Down Expand Up @@ -347,7 +355,7 @@ private function dateformat_PHP_to_jQueryUI($php_format)

private function getActiveDisabledDays($dateFormat)
{
$arrDateDisabledDays = \StringUtil::deserialize($this->dateDisabledDays, true);
$arrDateDisabledDays = StringUtil::deserialize($this->dateDisabledDays, true);
$arrDateDisabledDaysActive = array();
foreach ($arrDateDisabledDays as $config)
{
Expand Down

0 comments on commit 4924fd5

Please sign in to comment.