2015-08-12 06:08:32 +02:00
|
|
|
<?php
|
|
|
|
|
2017-08-09 01:55:09 +02:00
|
|
|
namespace SilverStripe\UserForms\FormField;
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\Forms\CompositeField;
|
2017-08-11 02:36:28 +02:00
|
|
|
use SilverStripe\UserForms\Model\EditableFormField;
|
2017-08-09 01:55:09 +02:00
|
|
|
use SilverStripe\UserForms\Model\EditableFormField\EditableFormStep;
|
|
|
|
|
2015-08-12 06:08:32 +02:00
|
|
|
/**
|
|
|
|
* Represents a composite field group, which may contain other groups
|
|
|
|
*/
|
2016-07-21 07:53:59 +02:00
|
|
|
abstract class UserFormsCompositeField extends CompositeField implements UserFormsFieldContainer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Parent field
|
|
|
|
*
|
|
|
|
* @var UserFormsFieldContainer
|
|
|
|
*/
|
|
|
|
protected $parent = null;
|
|
|
|
|
|
|
|
public function getParent()
|
|
|
|
{
|
|
|
|
return $this->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setParent(UserFormsFieldContainer $parent)
|
|
|
|
{
|
|
|
|
$this->parent = $parent;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processNext(EditableFormField $field)
|
|
|
|
{
|
|
|
|
// When we find a step, bubble up to the top
|
|
|
|
if ($field instanceof EditableFormStep) {
|
|
|
|
return $this->getParent()->processNext($field);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip over fields that don't generate formfields
|
2017-08-14 00:06:17 +02:00
|
|
|
if (get_class($field) === EditableFormField::class || !$field->getFormField()) {
|
2016-07-21 07:53:59 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2017-08-14 00:06:17 +02:00
|
|
|
/** @var EditableFormField $formField */
|
|
|
|
$formField = $field->getFormField();
|
2016-07-21 07:53:59 +02:00
|
|
|
|
|
|
|
// Save this field
|
|
|
|
$this->push($formField);
|
|
|
|
|
|
|
|
// Nest fields that are containers
|
|
|
|
if ($formField instanceof UserFormsFieldContainer) {
|
|
|
|
return $formField->setParent($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add any subsequent fields to this
|
|
|
|
return $this;
|
|
|
|
}
|
2015-08-12 06:08:32 +02:00
|
|
|
}
|