mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch '4.0' into 4.1
This commit is contained in:
commit
ce58890baf
@ -1171,8 +1171,6 @@ warnings:
|
|||||||
message: 'moved to SilverStripe\View\HTML->createTag()'
|
message: 'moved to SilverStripe\View\HTML->createTag()'
|
||||||
'SilverStripe\Forms\Form->transformTo()':
|
'SilverStripe\Forms\Form->transformTo()':
|
||||||
message: 'Removed'
|
message: 'Removed'
|
||||||
'SilverStripe\Forms\Form->callfieldmethod()':
|
|
||||||
message: 'Removed'
|
|
||||||
'SilverStripe\Forms\Form::single_field_required()':
|
'SilverStripe\Forms\Form::single_field_required()':
|
||||||
message: 'Removed'
|
message: 'Removed'
|
||||||
'SilverStripe\Forms\Form::current_action()':
|
'SilverStripe\Forms\Form::current_action()':
|
||||||
@ -1323,8 +1321,6 @@ warnings:
|
|||||||
message: 'Use new asset abstraction'
|
message: 'Use new asset abstraction'
|
||||||
url: 'https://docs.silverstripe.org/en/4/changelogs/4.0.0#asset-storage'
|
url: 'https://docs.silverstripe.org/en/4/changelogs/4.0.0#asset-storage'
|
||||||
constants:
|
constants:
|
||||||
'SS_TRUSTED_PROXY_HOST_HEADER':
|
|
||||||
message: 'See TrustedProxyMiddleware'
|
|
||||||
'SS_TRUSTED_PROXY_PROTOCOL_HEADER':
|
'SS_TRUSTED_PROXY_PROTOCOL_HEADER':
|
||||||
message: 'See TrustedProxyMiddleware'
|
message: 'See TrustedProxyMiddleware'
|
||||||
'SS_TRUSTED_PROXY_IP_HEADER':
|
'SS_TRUSTED_PROXY_IP_HEADER':
|
||||||
|
@ -584,6 +584,11 @@ class Injector implements ContainerInterface
|
|||||||
$factory = isset($spec['factory']) ? $this->get($spec['factory']) : $this->getObjectCreator();
|
$factory = isset($spec['factory']) ? $this->get($spec['factory']) : $this->getObjectCreator();
|
||||||
$object = $factory->create($class, $constructorParams);
|
$object = $factory->create($class, $constructorParams);
|
||||||
|
|
||||||
|
// Handle empty factory responses
|
||||||
|
if (!$object) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// figure out if we have a specific id set or not. In some cases, we might be instantiating objects
|
// figure out if we have a specific id set or not. In some cases, we might be instantiating objects
|
||||||
// that we don't manage directly; we don't want to store these in the service cache below
|
// that we don't manage directly; we don't want to store these in the service cache below
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
|
@ -220,6 +220,8 @@ class DateField extends TextField
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ($this->getHTML5() && $this->locale) {
|
if ($this->getHTML5() && $this->locale) {
|
||||||
throw new \LogicException(
|
throw new \LogicException(
|
||||||
'Please opt-out of HTML5 processing of ISO 8601 dates via setHTML5(false) if using setLocale()'
|
'Please opt-out of HTML5 processing of ISO 8601 dates via setHTML5(false) if using setLocale()'
|
||||||
@ -353,9 +355,12 @@ class DateField extends TextField
|
|||||||
|
|
||||||
public function performReadonlyTransformation()
|
public function performReadonlyTransformation()
|
||||||
{
|
{
|
||||||
$field = $this->castedCopy(DateField_Disabled::class);
|
$field = $this
|
||||||
$field->setValue($this->dataValue());
|
->castedCopy(DateField_Disabled::class)
|
||||||
$field->setReadonly(true);
|
->setValue($this->dataValue())
|
||||||
|
->setLocale($this->getLocale())
|
||||||
|
->setReadonly(true);
|
||||||
|
|
||||||
return $field;
|
return $field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,27 +14,51 @@ class DateField_Disabled extends DateField
|
|||||||
|
|
||||||
protected $disabled = true;
|
protected $disabled = true;
|
||||||
|
|
||||||
public function Field($properties = array())
|
public function Field($properties = [])
|
||||||
{
|
{
|
||||||
if ($this->valueObj) {
|
// Default display value
|
||||||
if ($this->valueObj->isToday()) {
|
$displayValue = '<i>(' . _t(DateField::class . '.NOTSET', 'not set') . ')</i>';
|
||||||
$val = Convert::raw2xml($this->valueObj->toString($this->getConfig('dateformat'))
|
|
||||||
. ' (' . _t('SilverStripe\\Forms\\DateField.TODAY', 'today') . ')');
|
$value = $this->dataValue();
|
||||||
} else {
|
|
||||||
|
if ($value) {
|
||||||
|
$value = $this->tidyInternal($value);
|
||||||
$df = new DBDate($this->name);
|
$df = new DBDate($this->name);
|
||||||
$df->setValue($this->dataValue());
|
$df->setValue($value);
|
||||||
$val = Convert::raw2xml($this->valueObj->toString($this->getConfig('dateformat'))
|
|
||||||
. ', ' . $df->Ago());
|
if ($df->IsToday()) {
|
||||||
}
|
// e.g. 2018-06-01 (today)
|
||||||
|
$format = '%s (%s)';
|
||||||
|
$infoComplement = _t(DateField::class . '.TODAY', 'today');
|
||||||
} else {
|
} else {
|
||||||
$val = '<i>(' . _t('SilverStripe\\Forms\\DateField.NOTSET', 'not set') . ')</i>';
|
// e.g. 2018-06-01, 5 days ago
|
||||||
|
$format = '%s, %s';
|
||||||
|
$infoComplement = $df->Ago();
|
||||||
}
|
}
|
||||||
|
|
||||||
return "<span class=\"readonly\" id=\"" . $this->ID() . "\">$val</span>";
|
// Render the display value with some complement of info
|
||||||
|
$displayValue = Convert::raw2xml(sprintf(
|
||||||
|
$format,
|
||||||
|
$this->Value(),
|
||||||
|
$infoComplement
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprintf(
|
||||||
|
"<span class=\"readonly\" id=\"%s\">%s</span>",
|
||||||
|
$this->ID(),
|
||||||
|
$displayValue
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Type()
|
public function Type()
|
||||||
{
|
{
|
||||||
return "date_disabled readonly";
|
return "date_disabled readonly " . parent::Type();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHTML5()
|
||||||
|
{
|
||||||
|
// Always disable HTML5 feature when using the readonly field.
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ use SilverStripe\Core\Tests\Injector\InjectorTest\CircularOne;
|
|||||||
use SilverStripe\Core\Tests\Injector\InjectorTest\CircularTwo;
|
use SilverStripe\Core\Tests\Injector\InjectorTest\CircularTwo;
|
||||||
use SilverStripe\Core\Tests\Injector\InjectorTest\ConstructableObject;
|
use SilverStripe\Core\Tests\Injector\InjectorTest\ConstructableObject;
|
||||||
use SilverStripe\Core\Tests\Injector\InjectorTest\DummyRequirements;
|
use SilverStripe\Core\Tests\Injector\InjectorTest\DummyRequirements;
|
||||||
|
use SilverStripe\Core\Tests\Injector\InjectorTest\EmptyFactory;
|
||||||
use SilverStripe\Core\Tests\Injector\InjectorTest\MyChildClass;
|
use SilverStripe\Core\Tests\Injector\InjectorTest\MyChildClass;
|
||||||
use SilverStripe\Core\Tests\Injector\InjectorTest\MyParentClass;
|
use SilverStripe\Core\Tests\Injector\InjectorTest\MyParentClass;
|
||||||
use SilverStripe\Core\Tests\Injector\InjectorTest\NeedsBothCirculars;
|
use SilverStripe\Core\Tests\Injector\InjectorTest\NeedsBothCirculars;
|
||||||
@ -102,6 +103,21 @@ class InjectorTest extends SapphireTest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEmptyFactory()
|
||||||
|
{
|
||||||
|
$this->expectException(InjectorNotFoundException::class);
|
||||||
|
$injector = new Injector();
|
||||||
|
$services = array(
|
||||||
|
'SomeClass' => array(
|
||||||
|
'class' => AnotherService::class,
|
||||||
|
'factory' => EmptyFactory::class,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$injector->load($services);
|
||||||
|
$injector->create('SomeClass');
|
||||||
|
}
|
||||||
|
|
||||||
public function testConfiguredInjector()
|
public function testConfiguredInjector()
|
||||||
{
|
{
|
||||||
$injector = new Injector();
|
$injector = new Injector();
|
||||||
|
13
tests/php/Core/Injector/InjectorTest/EmptyFactory.php
Normal file
13
tests/php/Core/Injector/InjectorTest/EmptyFactory.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Core\Tests\Injector\InjectorTest;
|
||||||
|
|
||||||
|
use SilverStripe\Core\Injector\Factory;
|
||||||
|
|
||||||
|
class EmptyFactory implements Factory
|
||||||
|
{
|
||||||
|
public function create($service, array $params = array())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
79
tests/php/Forms/DateField_DisabledTest.php
Normal file
79
tests/php/Forms/DateField_DisabledTest.php
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Forms\Tests;
|
||||||
|
|
||||||
|
use IntlDateFormatter;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\Forms\DateField_Disabled;
|
||||||
|
use SilverStripe\Forms\RequiredFields;
|
||||||
|
use SilverStripe\i18n\i18n;
|
||||||
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @skipUpgrade
|
||||||
|
*/
|
||||||
|
class DateField_DisabledTest extends SapphireTest
|
||||||
|
{
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
i18n::set_locale('en_NZ');
|
||||||
|
DBDatetime::set_mock_now('2011-02-01 8:34:00');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFieldToday()
|
||||||
|
{
|
||||||
|
// Today date with normal local
|
||||||
|
$actual = DateField_Disabled::create('Test')
|
||||||
|
->setValue('2011-02-01')
|
||||||
|
->Field();
|
||||||
|
$expected = '<span class="readonly" id="Test">1/02/2011 (today)</span>';
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
|
||||||
|
// Test today's date with time
|
||||||
|
$actual = DateField_Disabled::create('Test')
|
||||||
|
->setValue('2011-02-01 10:34:00')
|
||||||
|
->Field();
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFieldWithDifferentDay()
|
||||||
|
{
|
||||||
|
// Test past
|
||||||
|
$actual = DateField_Disabled::create('Test')
|
||||||
|
->setValue('2011-01-27')
|
||||||
|
->Field();
|
||||||
|
$expected = '<span class="readonly" id="Test">27/01/2011, 5 days ago</span>';
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
|
||||||
|
// Test future
|
||||||
|
$actual = DateField_Disabled::create('Test')
|
||||||
|
->setValue('2011-02-06')
|
||||||
|
->Field();
|
||||||
|
$expected = '<span class="readonly" id="Test">6/02/2011, in 5 days</span>';
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFieldWithDifferentLocal()
|
||||||
|
{
|
||||||
|
// Test different local
|
||||||
|
$actual = DateField_Disabled::create('Test')
|
||||||
|
->setValue('2011-02-06')
|
||||||
|
->setHTML5(false)
|
||||||
|
->setLocale('de_DE')
|
||||||
|
->Field();
|
||||||
|
$expected = '<span class="readonly" id="Test">06.02.2011, in 5 days</span>';
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFieldWithNonValue()
|
||||||
|
{
|
||||||
|
// Test none value
|
||||||
|
$actual = DateField_Disabled::create('Test')->Field();
|
||||||
|
$expected = '<span class="readonly" id="Test"><i>(not set)</i></span>';
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
|
||||||
|
$actual = DateField_Disabled::create('Test')->setValue('This is not a date')->Field();
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user