View source
<?php
namespace Drupal\yamlform_test\Plugin\YamlFormElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\yamlform\YamlFormElementBase;
use Drupal\yamlform\YamlFormSubmissionInterface;
class YamlFormTest extends YamlFormElementBase {
public function prepare(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
$this
->displayMessage(__FUNCTION__);
$element['#element_validate'][] = [
get_class($this),
'validate',
];
}
public function setDefaultValue(array &$element) {
$this
->displayMessage(__FUNCTION__);
}
public function formatHtml(array &$element, $value, array $options = []) {
$this
->displayMessage(__FUNCTION__);
return '<i>' . $this
->formatText($element, $value, $options) . '</i>';
}
public function formatText(array &$element, $value, array $options = []) {
$this
->displayMessage(__FUNCTION__);
return strtoupper($value);
}
public function preCreate(array &$element, array $values) {
$this
->displayMessage(__FUNCTION__);
}
public function postCreate(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
$this
->displayMessage(__FUNCTION__);
}
public function postLoad(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
$this
->displayMessage(__FUNCTION__);
}
public function preDelete(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
$this
->displayMessage(__FUNCTION__);
}
public function postDelete(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
$this
->displayMessage(__FUNCTION__);
}
public function preSave(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
$this
->displayMessage(__FUNCTION__);
}
public function save(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
$this
->displayMessage(__FUNCTION__);
}
public function postSave(array &$element, YamlFormSubmissionInterface $yamlform_submission, $update = TRUE) {
$this
->displayMessage(__FUNCTION__, $update ? 'update' : 'insert');
}
protected function displayMessage($method_name, $context1 = NULL) {
if (PHP_SAPI != 'cli') {
$t_args = [
'@class_name' => get_class($this),
'@method_name' => $method_name,
'@context1' => $context1,
];
drupal_set_message($this
->t('Invoked: @class_name:@method_name @context1', $t_args));
}
}
public static function validate(array &$element, FormStateInterface $form_state) {
drupal_set_message(t('Invoked: Drupal\\yamlform_test\\Plugin\\YamlFormElement\\YamlFormTest::validate'));
}
}