MultipleEntityFormState.php in Flexiform 8
File
src/MultipleEntityFormState.php
View source
<?php
namespace Drupal\flexiform;
use Drupal\Core\Form\FormStateDecoratorBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\FormStateValuesTrait;
use Drupal\flexiform\FormEntity\FlexiformFormEntityManager;
class MultipleEntityFormState extends FormStateDecoratorBase implements MultipleEntityFormStateInterface {
use FormStateValuesTrait;
protected $formEntityManager;
protected $parents;
public function __construct(array &$subform, FormStateInterface $form_state) {
$this->decoratedFormState = $form_state;
$this->subform = $subform;
$this->parents = isset($subform['#parents']) ? $subform['#parents'] : [];
}
public static function createForForm(array &$form, FormStateInterface $form_state) {
return new static($form, $form_state);
}
public function setFormEntityManager(FlexiformFormEntityManager $form_entity_manager) {
$managers_property = array_merge([
'entity_manager',
], $this->parents, [
'#manager',
]);
$this->decoratedFormState
->set($managers_property, $form_entity_manager);
return $this;
}
public function getFormEntityManager() {
$managers_property = array_merge([
'entity_manager',
], $this->parents, [
'#manager',
]);
return $this->decoratedFormState
->get($managers_property);
}
}