View source
<?php
namespace Drupal\signature_field\Element;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\FormElement;
class Signature extends FormElement {
public function getInfo() {
$class = get_class($this);
return [
'#input' => TRUE,
'#process' => [
[
$class,
'processSignature',
],
],
'#pre_render' => [
[
$class,
'preRenderSignature',
],
],
'#theme' => 'signature',
'#theme_wrappers' => [
'form_element',
],
'#attached' => [
'library' => [
'signature_field/signature_pad',
],
],
'#type' => 'textarea',
];
}
public static function processSignature(&$element, FormStateInterface $form_state, &$complete_form) {
return $element;
}
public static function preRenderSignature(array $element) {
$sign_thumb = [
'#type' => 'html_tag',
'#tag' => 'img',
'#attributes' => [
'src' => '',
'id' => 'signature_thumb',
'class' => [
'align-right',
],
'width' => '120px',
'height' => '60px',
],
];
$element['#suffix'] = \Drupal::service('renderer')
->renderPlain($sign_thumb);
return $element;
}
public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
return $element;
}
}