2015-08-12 06:08:32 +02:00
|
|
|
<?php
|
|
|
|
|
2017-08-09 01:55:09 +02:00
|
|
|
namespace SilverStripe\UserForms\FormField;
|
|
|
|
|
|
|
|
use SilverStripe\Forms\FieldList;
|
2017-08-11 02:36:28 +02:00
|
|
|
use SilverStripe\UserForms\Model\EditableFormField;
|
2017-08-09 01:55:09 +02:00
|
|
|
|
2015-08-12 06:08:32 +02:00
|
|
|
/**
|
|
|
|
* A list of formfields which allows for iterative processing of nested composite fields
|
|
|
|
*/
|
2016-07-21 07:53:59 +02:00
|
|
|
class UserFormsFieldList extends FieldList implements UserFormsFieldContainer
|
|
|
|
{
|
|
|
|
public function processNext(EditableFormField $field)
|
|
|
|
{
|
|
|
|
$formField = $field->getFormField();
|
|
|
|
if (!$formField) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->push($formField);
|
|
|
|
|
|
|
|
if ($formField instanceof UserFormsFieldContainer) {
|
|
|
|
return $formField->setParent($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getParent()
|
|
|
|
{
|
|
|
|
// Field list does not have a parent
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setParent(UserFormsFieldContainer $parent)
|
|
|
|
{
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all empty steps
|
|
|
|
*/
|
|
|
|
public function clearEmptySteps()
|
|
|
|
{
|
|
|
|
foreach ($this as $field) {
|
|
|
|
if ($field instanceof UserFormsStepField && count($field->getChildren()) === 0) {
|
|
|
|
$this->remove($field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-12 06:08:32 +02:00
|
|
|
}
|