-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nested fields with url_handlers (eg UploadField) now work in DataList…
…Field
- Loading branch information
1 parent
7984c22
commit 3ffc742
Showing
6 changed files
with
182 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
Name: silverstripe-serialized-dataobject-extensions | ||
After: 'framework/*','cms/*' | ||
--- | ||
Form: | ||
extensions: | ||
- 'zauberfisch\SerializedDataObject\Form\FormExtension' | ||
url_handlers: | ||
'field/$FieldName!': 'handleFieldArrayList' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace zauberfisch\SerializedDataObject\Form; | ||
|
||
class FormExtension extends \Extension { | ||
private static $allowed_actions = [ | ||
'handleFieldArrayList', | ||
]; | ||
// private static $url_handlers = [ | ||
// 'field/$FieldName!' => 'handleFieldArrayList', | ||
// ]; | ||
|
||
|
||
/** | ||
* @param \SS_HTTPRequest $request | ||
* @return \FormField | ||
*/ | ||
public function handleFieldArrayList($request) { | ||
$field = $this->owner->handleField($request); | ||
if (!$field) { | ||
$fieldName = $request->param('FieldName'); | ||
foreach($this->owner->Fields()->dataFields() as $dataField) { | ||
/** @var \FormField|ArrayListField $dataField */ | ||
if ($dataField->is_a(ArrayListField::class)) { | ||
if (strpos($fieldName, $dataField->getName()) == 0) { | ||
$field = $dataField->handleSubField($fieldName); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
return $field; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace zauberfisch\SerializedDataObject\Form; | ||
|
||
use zauberfisch\NamespaceTemplates\Form\CompositeField; | ||
|
||
class ProxyArrayListField extends CompositeField { | ||
public function __construct($name, $title = null, $recordClassName) { | ||
$_this = $this; | ||
parent::__construct([ | ||
(new ArrayListField($name, $title, $recordClassName)) | ||
->setRecordFieldsUpdateCallback(function ($fields, $listField, $record = null) use ($_this) { | ||
foreach($fields as $field) { | ||
$_this->push(new ProxyArrayListField_FieldProxy($field)); | ||
} | ||
return $fields; | ||
}), | ||
]); | ||
$this->setName("{$name}_proxy_holder"); | ||
} | ||
|
||
|
||
} | ||
|
||
class ProxyArrayListField_FieldProxy extends \DatalessField { | ||
private static $allowed_actions = [ | ||
'handleField', | ||
]; | ||
private static $url_handlers = [ | ||
'' => 'handleField', | ||
]; | ||
protected $originalField; | ||
|
||
/** | ||
* @param \FormField $originalField | ||
*/ | ||
public function __construct($originalField) { | ||
$this->originalField = $originalField; | ||
parent::__construct($originalField->getName()); | ||
} | ||
|
||
|
||
public function handleField(\SS_HTTPRequest $request) { | ||
return $this->originalField; | ||
} | ||
|
||
public function Field($properties = []) { | ||
return ''; | ||
} | ||
|
||
public function FieldHolder($properties = []) { | ||
return ''; | ||
} | ||
|
||
public function SmallFieldHolder($properties = []) { | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters