Skip to content

Commit

Permalink
ENH: Prefer dependency injection over use of new keyword. (#333)
Browse files Browse the repository at this point in the history
* ENH: Prefer dependency injection over use of `new` keyword.

* MNT Fix phpcs linting error.
  • Loading branch information
GuySartorelli authored Feb 18, 2022
1 parent 8e9ee0b commit 8c4e924
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/GridFieldAddExistingSearchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function doSearch($data, $form)
{
$list = $this->context->getQuery($data, false, false, $this->getSearchList());
$list = $list->subtract($this->grid->getList());
$list = new PaginatedList($list, $this->request);
$list = PaginatedList::create($list, $this->request);

$data = $this->customise(array(
'SearchForm' => $form,
Expand All @@ -109,7 +109,7 @@ public function Items()
{
$list = $this->getSearchList();
$list = $list->subtract($this->grid->getList());
$list = new PaginatedList($list, $this->request);
$list = PaginatedList::create($list, $this->request);

return $list;
}
Expand Down
6 changes: 3 additions & 3 deletions src/GridFieldAddNewInlineButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function getHTMLFragments($grid)
Requirements::javascript('symbiote/silverstripe-gridfieldextensions:javascript/tmpl.js');
GridFieldExtensions::include_requirements();

$data = new ArrayData(array(
$data = ArrayData::create(array(
'Title' => $this->getTitle(),
));

Expand All @@ -114,7 +114,7 @@ public function getHTMLFragments($grid)

private function getRowTemplate(GridField $grid, GridFieldEditableColumns $editable)
{
$columns = new ArrayList();
$columns = ArrayList::create();
$handled = array_keys($editable->getDisplayFields($grid));

if ($grid->getList()) {
Expand Down Expand Up @@ -161,7 +161,7 @@ private function getRowTemplate(GridField $grid, GridFieldEditableColumns $edita
$attrs .= sprintf(' %s="%s"', $attr, Convert::raw2att($val));
}

$columns->push(new ArrayData(array(
$columns->push(ArrayData::create(array(
'Content' => $content,
'Attributes' => DBField::create_field('HTMLFragment', $attrs),
'IsActions' => $column == 'Actions'
Expand Down
9 changes: 7 additions & 2 deletions src/GridFieldAddNewMultiClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,18 @@ public function getHTMLFragments($grid)

GridFieldExtensions::include_requirements();

$field = new DropdownField(sprintf('%s[%s]', __CLASS__, $grid->getName()), '', $classes, $this->defaultClass);
$field = DropdownField::create(
sprintf('%s[%s]', __CLASS__, $grid->getName()),
'',
$classes,
$this->defaultClass
);
if (Config::inst()->get(__CLASS__, 'showEmptyString')) {
$field->setEmptyString(_t('GridFieldExtensions.SELECTTYPETOCREATE', '(Select type to create)'));
}
$field->addExtraClass('no-change-track');

$data = new ArrayData(array(
$data = ArrayData::create(array(
'Title' => $this->getTitle(),
'Link' => Controller::join_links($grid->Link(), 'add-multi-class', '{class}'),
'ClassField' => $field
Expand Down
10 changes: 5 additions & 5 deletions src/GridFieldEditableColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getColumnContent($grid, $record, $col)
// Fall back to previous logic
if (!$field) {
$rel = (strpos($col, '.') === false); // field references a relation value
$field = ($rel) ? clone $fields->fieldByName($col) : new ReadonlyField($col);
$field = ($rel) ? clone $fields->fieldByName($col) : ReadonlyField::create($col);
}

if (!$field) {
Expand Down Expand Up @@ -211,7 +211,7 @@ public function getURLHandlers($grid)
public function getFields(GridField $grid, DataObjectInterface $record)
{
$cols = $this->getDisplayFields($grid);
$fields = new FieldList();
$fields = FieldList::create();

/** @var DataList $list */
$list = $grid->getList();
Expand Down Expand Up @@ -263,12 +263,12 @@ public function getFields(GridField $grid, DataObjectInterface $record)
if ($class && $obj = DataObject::singleton($class)->dbObject($colRelation[0])) {
$field = $obj->scaffoldFormField();
} else {
$field = new ReadonlyField($colRelation[0]);
$field = ReadonlyField::create($colRelation[0]);
}
} elseif ($class && $obj = DataObject::singleton($class)->dbObject($col)) {
$field = $obj->scaffoldFormField();
} else {
$field = new ReadonlyField($col);
$field = ReadonlyField::create($col);
}
}

Expand Down Expand Up @@ -301,7 +301,7 @@ public function getForm(GridField $grid, DataObjectInterface $record)
{
$fields = $this->getFields($grid, $record);

$form = new Form($grid, null, $fields, new FieldList());
$form = Form::create($grid, null, $fields, FieldList::create());
$form->loadDataFrom($record);

$form->setFormAction(Controller::join_links(
Expand Down
2 changes: 1 addition & 1 deletion src/GridFieldExternalLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getColumnsHandled($gridField)
*/
public function getColumnContent($gridField, $record, $columnName)
{
$data = new ArrayData(array(
$data = ArrayData::create(array(
'Link' => $record->hasMethod('getExternalLink') ? $record->getExternalLink() : $record->ExternalLink,
'Text' => $record->hasMethod('getExternalLinkText') ? $record->getExternalLinkText() : 'External Link'
));
Expand Down
8 changes: 4 additions & 4 deletions src/GridFieldRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public function Link($action = null)
*/
public function Form()
{
$form = new Form(
$form = Form::create(
$this,
'SilverStripe\\Forms\\Form',
new FieldList($root = new TabSet('Root', new Tab('Main'))),
new FieldList()
FieldList::create($root = TabSet::create('Root', Tab::create('Main'))),
FieldList::create()
);

if ($this->getTopLevelController() instanceof LeftAndMain) {
Expand Down Expand Up @@ -136,7 +136,7 @@ public function getBreadcrumbs()
if ($controller->hasMethod('Breadcrumbs')) {
return $controller->Breadcrumbs();
} else {
return new ArrayList();
return ArrayList::create();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/GridFieldTitleHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class GridFieldTitleHeader implements GridField_HTMLProvider

public function getHTMLFragments($grid)
{
$cols = new ArrayList();
$cols = ArrayList::create();

foreach ($grid->getColumns() as $name) {
$meta = $grid->getColumnMetadata($name);

$cols->push(new ArrayData(array(
$cols->push(ArrayData::create(array(
'Name' => $name,
'Title' => $meta['title']
)));
Expand Down

0 comments on commit 8c4e924

Please sign in to comment.