View source
<?php
namespace Drupal\yamlform;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginBase;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class YamlFormHandlerBase extends PluginBase implements YamlFormHandlerInterface {
protected $yamlform = NULL;
protected $handler_id;
protected $label;
protected $status = 1;
protected $weight = '';
protected $logger;
public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this
->setConfiguration($configuration);
$this->logger = $logger;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('logger.factory')
->get('yamlform'));
}
public function init(YamlFormInterface $yamlform) {
$this->yamlform = $yamlform;
return $this;
}
public function getYamlForm() {
return $this->yamlform;
}
public function getSummary() {
return [
'#theme' => 'yamlform_handler_' . $this->pluginId . '_summary',
'#settings' => $this->configuration,
'#handler' => [
'id' => $this->pluginDefinition['id'],
'handler_id' => $this
->getHandlerId(),
'label' => $this
->label(),
'description' => $this->pluginDefinition['description'],
],
];
}
public function label() {
return $this
->getLabel();
}
public function description() {
return $this->pluginDefinition['description'];
}
public function cardinality() {
return $this->pluginDefinition['cardinality'];
}
public function getHandlerId() {
return $this->handler_id;
}
public function setHandlerId($handler_id) {
$this->handler_id = $handler_id;
return $this;
}
public function setLabel($label) {
$this->label = $label;
return $this;
}
public function getLabel() {
return $this->label ?: $this->pluginDefinition['label'];
}
public function setStatus($status) {
$this->status = $status;
return $this;
}
public function getStatus() {
return $this->status;
}
public function setWeight($weight) {
$this->weight = $weight;
return $this;
}
public function getWeight() {
return $this->weight;
}
public function isEnabled() {
return $this->status ? TRUE : FALSE;
}
public function isDisabled() {
return !$this
->isEnabled();
}
public function getConfiguration() {
return [
'id' => $this
->getPluginId(),
'label' => $this
->getLabel(),
'handler_id' => $this
->getHandlerId(),
'status' => $this
->getStatus(),
'weight' => $this
->getWeight(),
'settings' => $this->configuration,
];
}
public function setConfiguration(array $configuration) {
$configuration += [
'handler_id' => '',
'label' => '',
'status' => 1,
'weight' => '',
'settings' => [],
];
$this->configuration = $configuration['settings'] + $this
->defaultConfiguration();
$this->handler_id = $configuration['handler_id'];
$this->label = $configuration['label'];
$this->weight = $configuration['weight'];
$this->status = $configuration['status'];
return $this;
}
public function defaultConfiguration() {
return [];
}
public function calculateDependencies() {
return [];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function alterElements(array &$elements, YamlFormInterface $yamlform) {
}
public function alterForm(array &$form, FormStateInterface $form_state, YamlFormSubmissionInterface $yamlform_submission) {
}
public function validateForm(array &$form, FormStateInterface $form_state, YamlFormSubmissionInterface $yamlform_submission) {
}
public function submitForm(array &$form, FormStateInterface $form_state, YamlFormSubmissionInterface $yamlform_submission) {
}
public function confirmForm(array &$form, FormStateInterface $form_state, YamlFormSubmissionInterface $yamlform_submission) {
}
public function preCreate(array $values) {
}
public function postCreate(YamlFormSubmissionInterface $yamlform_submission) {
}
public function postLoad(YamlFormSubmissionInterface $yamlform_submission) {
}
public function preDelete(YamlFormSubmissionInterface $yamlform_submission) {
}
public function postDelete(YamlFormSubmissionInterface $yamlform_submission) {
}
public function preSave(YamlFormSubmissionInterface $yamlform_submission) {
}
public function postSave(YamlFormSubmissionInterface $yamlform_submission, $update = TRUE) {
}
}