Skip to content

Commit

Permalink
Update GetList.php
Browse files Browse the repository at this point in the history
Applies new modManagerDateFormatter to Context settings
  • Loading branch information
smg6511 committed Sep 26, 2024
1 parent eedb80f commit 6150494
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions core/src/Revolution/Processors/Context/Setting/GetList.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This file is part of the MODX Revolution package.
*
Expand All @@ -10,7 +11,7 @@

namespace MODX\Revolution\Processors\Context\Setting;


use MODX\Revolution\Formatter\modManagerDateFormatter;
use MODX\Revolution\modContextSetting;
use MODX\Revolution\Processors\Model\GetListProcessor;
use MODX\Revolution\modX;
Expand All @@ -34,20 +35,20 @@ class GetList extends GetListProcessor
public $languageTopics = ['setting', 'namespace'];
public $permission = 'settings';
public $defaultSortField = 'key';
protected $dateFormat;

private modManagerDateFormatter $formatter;

public function initialize()
{
$initialized = parent::initialize();
$this->formatter = $this->modx->services->get(modManagerDateFormatter::class);

Check warning on line 44 in core/src/Revolution/Processors/Context/Setting/GetList.php

View check run for this annotation

Codecov / codecov/patch

core/src/Revolution/Processors/Context/Setting/GetList.php#L44

Added line #L44 was not covered by tests
$this->setDefaultProperties([
'key' => false,
'namespace' => false,
'area' => false,
'dateFormat' => ''

Check warning on line 49 in core/src/Revolution/Processors/Context/Setting/GetList.php

View check run for this annotation

Codecov / codecov/patch

core/src/Revolution/Processors/Context/Setting/GetList.php#L49

Added line #L49 was not covered by tests
]);

$this->dateFormat = $this->modx->getOption('manager_date_format') . ', '
. $this->modx->getOption('manager_time_format');

return $initialized;
}

Expand Down Expand Up @@ -110,8 +111,10 @@ public function prepareRow(xPDOObject $object)
$k = 'setting_' . $settingArray['key'];

/* if 3rd party setting, load proper text, fallback to english */
$this->modx->lexicon->load('en:' . $object->get('namespace') . ':default',
'en:' . $object->get('namespace') . ':setting');
$this->modx->lexicon->load(
'en:' . $object->get('namespace') . ':default',
'en:' . $object->get('namespace') . ':setting'
);

Check warning on line 117 in core/src/Revolution/Processors/Context/Setting/GetList.php

View check run for this annotation

Codecov / codecov/patch

core/src/Revolution/Processors/Context/Setting/GetList.php#L114-L117

Added lines #L114 - L117 were not covered by tests
$this->modx->lexicon->load($object->get('namespace') . ':default', $object->get('namespace') . ':setting');

/* get translated area text */
Expand All @@ -128,8 +131,10 @@ public function prepareRow(xPDOObject $object)
$settingArray['description_trans'] = $this->modx->lexicon($k . '_desc');
$settingArray['description'] = $k . '_desc';
} else {
$this->modx->log(modX::LOG_LEVEL_DEBUG,
'[' . __METHOD__ . '] lexicon entry for ' . $k . '_desc not found');
$this->modx->log(
modX::LOG_LEVEL_DEBUG,
'[' . __METHOD__ . '] lexicon entry for ' . $k . '_desc not found'
);

Check warning on line 137 in core/src/Revolution/Processors/Context/Setting/GetList.php

View check run for this annotation

Codecov / codecov/patch

core/src/Revolution/Processors/Context/Setting/GetList.php#L134-L137

Added lines #L134 - L137 were not covered by tests
$settingArray['description_trans'] = !empty($settingArray['description']) ? $settingArray['description'] : '';
}
} else {
Expand All @@ -148,10 +153,12 @@ public function prepareRow(xPDOObject $object)

$settingArray['oldkey'] = $settingArray['key'];

$settingArray['editedon'] = in_array(
$object->get('editedon'),
['-001-11-30 00:00:00', '-1-11-30 00:00:00', '0000-00-00 00:00:00', null]
) ? '' : date($this->dateFormat, strtotime($object->get('editedon')));
$customFormat = $this->getProperty('dateFormat');
$editedOn = $object->get('editedon');
$settingArray['editedon'] = !empty($customFormat)
? $this->formatter->format($editedOn, $customFormat)
: $this->formatter->formatDateTime($editedOn)
;

Check warning on line 161 in core/src/Revolution/Processors/Context/Setting/GetList.php

View check run for this annotation

Codecov / codecov/patch

core/src/Revolution/Processors/Context/Setting/GetList.php#L156-L161

Added lines #L156 - L161 were not covered by tests

return $settingArray;
}
Expand Down

0 comments on commit 6150494

Please sign in to comment.