YamlFormHandlerAddForm.php in YAML Form 8
File
src/Form/YamlFormHandlerAddForm.php
View source
<?php
namespace Drupal\yamlform\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\yamlform\YamlFormHandlerManagerInterface;
use Drupal\yamlform\YamlFormInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class YamlFormHandlerAddForm extends YamlFormHandlerFormBase {
protected $yamlformHandlerManager;
public function __construct(YamlFormHandlerManagerInterface $yamlform_handler) {
$this->yamlformHandlerManager = $yamlform_handler;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.yamlform.handler'));
}
public function buildForm(array $form, FormStateInterface $form_state, YamlFormInterface $yamlform = NULL, $yamlform_handler = NULL) {
$form = parent::buildForm($form, $form_state, $yamlform, $yamlform_handler);
$form['#title'] = $this
->t('Add @label handler', [
'@label' => $this->yamlformHandler
->label(),
]);
return $form;
}
protected function prepareYamlFormHandler($yamlform_handler) {
$yamlform_handler = $this->yamlformHandlerManager
->createInstance($yamlform_handler);
$yamlform_handler
->init($this->yamlform);
$yamlform_handler
->setWeight(count($this->yamlform
->getHandlers()));
return $yamlform_handler;
}
}