Merge pull request #106 from SilverStripers/master

Fixed performReadonlyTransformation
This commit is contained in:
Daniel Hensby 2018-01-24 18:00:10 +00:00 committed by GitHub
commit 80d8cf6a04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 7 deletions

View File

@ -1,9 +1,8 @@
<?php
namespace SilverStripe\TagField\TagField;
namespace SilverStripe\TagField;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\TagField\TagField;
/**
* A readonly extension of TagField useful for non-editable items within the CMS.
@ -11,7 +10,7 @@ use SilverStripe\TagField\TagField;
* @package forms
* @subpackage fields
*/
class Readonly extends TagField
class ReadonlyTagField extends TagField
{
/**
* {@inheritDoc}

View File

@ -7,7 +7,6 @@ use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
@ -67,7 +66,7 @@ class TagField extends DropdownField
* @param null|DataList $source
* @param null|DataList $value
*/
public function __construct($name, $title = '', $source = null, $value = null)
public function __construct($name, $title = '', $source = array(), $value = null)
{
$this->setSourceList($source);
parent::__construct($name, $title, $source, $value);
@ -447,7 +446,7 @@ class TagField extends DropdownField
*/
public function performReadonlyTransformation()
{
$copy = $this->castedCopy(TagFieldReadonly::class);
$copy = $this->castedCopy(ReadonlyTagField::class);
$copy->setSourceList($this->getSourceList());
return $copy;
}

View File

@ -4,11 +4,11 @@ namespace SilverStripe\TagField\Tests;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\TagField\ReadonlyTagField;
use SilverStripe\TagField\TagField;
use SilverStripe\TagField\Tests\Stub\TagFieldTestBlogPost;
use SilverStripe\TagField\Tests\Stub\TagFieldTestBlogTag;
@ -342,4 +342,14 @@ class TagFieldTest extends SapphireTest
$record->Tags()->first()->ID
);
}
/**
* Test read only fields are returned
*/
public function testReadonlyTransformation()
{
$field = new TagField('Tags', '', TagFieldTestBlogTag::get());
$readOnlyField = $field->performReadonlyTransformation();
$this->assertEquals(ReadonlyTagField::class, get_class($readOnlyField));
}
}