mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge branch '4.13' into 4
This commit is contained in:
commit
8b20be838c
@ -1645,7 +1645,9 @@ class Form extends ViewableData implements HasRequestHandler
|
|||||||
public function defaultAction()
|
public function defaultAction()
|
||||||
{
|
{
|
||||||
if ($this->hasDefaultAction && $this->actions) {
|
if ($this->hasDefaultAction && $this->actions) {
|
||||||
return $this->actions->first();
|
return $this->actions->flattenFields()->filterByCallback(function ($field) {
|
||||||
|
return $field instanceof FormAction;
|
||||||
|
})->first();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ use LogicException;
|
|||||||
use SilverStripe\Admin\LeftAndMain;
|
use SilverStripe\Admin\LeftAndMain;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\HTTPResponse;
|
use SilverStripe\Control\HTTPResponse;
|
||||||
|
use SilverStripe\Core\ClassInfo;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\Dev\Deprecation;
|
use SilverStripe\Dev\Deprecation;
|
||||||
@ -258,9 +259,13 @@ class GridFieldFilterHeader extends AbstractGridFieldComponent implements GridFi
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$modelClass = $gridField->getModelClass();
|
$modelClass = $gridField->getModelClass();
|
||||||
|
$singleton = singleton($modelClass);
|
||||||
|
if (ClassInfo::hasMethod($singleton, 'summaryFields')
|
||||||
|
&& ClassInfo::hasMethod($singleton, 'searchableFields')
|
||||||
|
) {
|
||||||
// note: searchableFields() will return summary_fields if there are no searchable_fields on the model
|
// note: searchableFields() will return summary_fields if there are no searchable_fields on the model
|
||||||
$searchableFields = array_keys($modelClass::singleton()->searchableFields());
|
$searchableFields = array_keys($singleton->searchableFields());
|
||||||
$summaryFields = array_keys($modelClass::singleton()->summaryFields());
|
$summaryFields = array_keys($singleton->summaryFields());
|
||||||
sort($searchableFields);
|
sort($searchableFields);
|
||||||
sort($summaryFields);
|
sort($summaryFields);
|
||||||
// searchable_fields has been explictily defined i.e. searchableFields() is not falling back to summary_fields
|
// searchable_fields has been explictily defined i.e. searchableFields() is not falling back to summary_fields
|
||||||
@ -273,6 +278,18 @@ class GridFieldFilterHeader extends AbstractGridFieldComponent implements GridFi
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Allows non-DataObject classes to be used with this component
|
||||||
|
$columns = $gridField->getColumns();
|
||||||
|
foreach ($columns as $columnField) {
|
||||||
|
$metadata = $gridField->getColumnMetadata($columnField);
|
||||||
|
$title = $metadata['title'];
|
||||||
|
|
||||||
|
if ($title && $list->canFilterBy($columnField)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class TinyMCEConfig extends HTMLEditorConfig implements i18nEntityProvider
|
|||||||
'ar_EG' => 'ar',
|
'ar_EG' => 'ar',
|
||||||
'ca_AD' => 'ca',
|
'ca_AD' => 'ca',
|
||||||
'ca_ES' => 'ca',
|
'ca_ES' => 'ca',
|
||||||
'cs_CZ' => 'cs',
|
'cs_CZ' => 'cs_CZ',
|
||||||
'cy_GB' => 'cy',
|
'cy_GB' => 'cy',
|
||||||
'da_DK' => 'da',
|
'da_DK' => 'da',
|
||||||
'da_GL' => 'da',
|
'da_GL' => 'da',
|
||||||
|
@ -7,6 +7,7 @@ use SilverStripe\Control\HTTPRequest;
|
|||||||
use SilverStripe\Control\Session;
|
use SilverStripe\Control\Session;
|
||||||
use SilverStripe\Dev\CSSContentParser;
|
use SilverStripe\Dev\CSSContentParser;
|
||||||
use SilverStripe\Dev\FunctionalTest;
|
use SilverStripe\Dev\FunctionalTest;
|
||||||
|
use SilverStripe\Forms\CompositeField;
|
||||||
use SilverStripe\Forms\DateField;
|
use SilverStripe\Forms\DateField;
|
||||||
use SilverStripe\Forms\DatetimeField;
|
use SilverStripe\Forms\DatetimeField;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
@ -23,7 +24,6 @@ use SilverStripe\Forms\Tests\FormTest\ControllerWithStrictPostCheck;
|
|||||||
use SilverStripe\Forms\Tests\FormTest\Player;
|
use SilverStripe\Forms\Tests\FormTest\Player;
|
||||||
use SilverStripe\Forms\Tests\FormTest\Team;
|
use SilverStripe\Forms\Tests\FormTest\Team;
|
||||||
use SilverStripe\Forms\Tests\FormTest\TestController;
|
use SilverStripe\Forms\Tests\FormTest\TestController;
|
||||||
use SilverStripe\Forms\Tests\ValidatorTest\TestValidator;
|
|
||||||
use SilverStripe\Forms\TextareaField;
|
use SilverStripe\Forms\TextareaField;
|
||||||
use SilverStripe\Forms\TextField;
|
use SilverStripe\Forms\TextField;
|
||||||
use SilverStripe\Forms\TimeField;
|
use SilverStripe\Forms\TimeField;
|
||||||
@ -348,6 +348,23 @@ class FormTest extends FunctionalTest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDefaultAction()
|
||||||
|
{
|
||||||
|
$form = Form::create(Controller::curr(), 'Form', new FieldList(), new FieldList(
|
||||||
|
new FormAction('doForm', 'Form Action')
|
||||||
|
));
|
||||||
|
$this->assertNotNull($form->defaultAction());
|
||||||
|
$this->assertEquals('action_doForm', $form->defaultAction()->getName());
|
||||||
|
|
||||||
|
$form = Form::create(Controller::curr(), 'AnotherForm', new FieldList(), new FieldList(
|
||||||
|
new CompositeField(
|
||||||
|
new FormAction('doAnotherForm', 'Another Form Action')
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$this->assertNotNull($form->defaultAction());
|
||||||
|
$this->assertEquals('action_doAnotherForm', $form->defaultAction()->getName());
|
||||||
|
}
|
||||||
|
|
||||||
public function testLoadDataFromIgnoreFalseish()
|
public function testLoadDataFromIgnoreFalseish()
|
||||||
{
|
{
|
||||||
$form = new Form(
|
$form = new Form(
|
||||||
|
@ -8,13 +8,16 @@ use SilverStripe\Dev\SapphireTest;
|
|||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Forms\Form;
|
use SilverStripe\Forms\Form;
|
||||||
use SilverStripe\Forms\GridField\GridField;
|
use SilverStripe\Forms\GridField\GridField;
|
||||||
|
use SilverStripe\Forms\GridField\GridFieldConfig;
|
||||||
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
||||||
use SilverStripe\Forms\GridField\GridFieldFilterHeader;
|
use SilverStripe\Forms\GridField\GridFieldFilterHeader;
|
||||||
use SilverStripe\Forms\Tests\GridField\GridFieldFilterHeaderTest\Cheerleader;
|
use SilverStripe\Forms\Tests\GridField\GridFieldFilterHeaderTest\Cheerleader;
|
||||||
use SilverStripe\Forms\Tests\GridField\GridFieldFilterHeaderTest\CheerleaderHat;
|
use SilverStripe\Forms\Tests\GridField\GridFieldFilterHeaderTest\CheerleaderHat;
|
||||||
use SilverStripe\Forms\Tests\GridField\GridFieldFilterHeaderTest\Mom;
|
use SilverStripe\Forms\Tests\GridField\GridFieldFilterHeaderTest\Mom;
|
||||||
|
use SilverStripe\Forms\Tests\GridField\GridFieldFilterHeaderTest\NonDataObject;
|
||||||
use SilverStripe\Forms\Tests\GridField\GridFieldFilterHeaderTest\Team;
|
use SilverStripe\Forms\Tests\GridField\GridFieldFilterHeaderTest\Team;
|
||||||
use SilverStripe\Forms\Tests\GridField\GridFieldFilterHeaderTest\TeamGroup;
|
use SilverStripe\Forms\Tests\GridField\GridFieldFilterHeaderTest\TeamGroup;
|
||||||
|
use SilverStripe\ORM\ArrayList;
|
||||||
use SilverStripe\ORM\DataList;
|
use SilverStripe\ORM\DataList;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
|
|
||||||
@ -208,4 +211,33 @@ class GridFieldFilterHeaderTest extends SapphireTest
|
|||||||
Config::modify()->set(Team::class, 'summary_fields', ['MySummaryField']);
|
Config::modify()->set(Team::class, 'summary_fields', ['MySummaryField']);
|
||||||
$this->assertFalse($filterHeader->canFilterAnyColumns($gridField));
|
$this->assertFalse($filterHeader->canFilterAnyColumns($gridField));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCanFilterAnyColumnsNonDataObject()
|
||||||
|
{
|
||||||
|
$list = new ArrayList([
|
||||||
|
new NonDataObject([]),
|
||||||
|
]);
|
||||||
|
$config = GridFieldConfig::create()->addComponent(new GridFieldFilterHeader());
|
||||||
|
$gridField = new GridField('testfield', 'testfield', $list, $config);
|
||||||
|
$form = new Form(null, 'Form', new FieldList([$gridField]), new FieldList());
|
||||||
|
/** @var GridFieldFilterHeader $component */
|
||||||
|
$component = $gridField->getConfig()->getComponentByType(GridFieldFilterHeader::class);
|
||||||
|
|
||||||
|
$this->assertFalse($component->canFilterAnyColumns($gridField));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRenderHeadersNonDataObject()
|
||||||
|
{
|
||||||
|
$list = new ArrayList([
|
||||||
|
new NonDataObject([]),
|
||||||
|
]);
|
||||||
|
$config = GridFieldConfig::create()->addComponent(new GridFieldFilterHeader());
|
||||||
|
$gridField = new GridField('testfield', 'testfield', $list, $config);
|
||||||
|
$form = new Form(null, 'Form', new FieldList([$gridField]), new FieldList());
|
||||||
|
/** @var GridFieldFilterHeader $component */
|
||||||
|
$component = $gridField->getConfig()->getComponentByType(GridFieldFilterHeader::class);
|
||||||
|
$htmlFragment = $component->getHTMLFragments($gridField);
|
||||||
|
|
||||||
|
$this->assertNull($htmlFragment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Forms\Tests\GridField\GridFieldFilterHeaderTest;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\View\ArrayData;
|
||||||
|
|
||||||
|
class NonDataObject extends ArrayData implements TestOnly
|
||||||
|
{
|
||||||
|
public function summaryFields()
|
||||||
|
{
|
||||||
|
return ['Title' => 'Title'];
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user