View source
<?php
namespace Drupal\yamlform\Element;
use Drupal\Core\Render\Element\FormElement;
use Drupal\Core\Render\Element;
class YamlFormSignature extends FormElement {
public function getInfo() {
$class = get_class($this);
return [
'#input' => TRUE,
'#process' => [
[
$class,
'processAjaxForm',
],
[
$class,
'processGroup',
],
],
'#pre_render' => [
[
$class,
'preRenderYamlFormSignature',
],
],
'#theme' => 'input__yamlform_signature',
'#theme_wrappers' => [
'form_element',
],
];
}
public static function preRenderYamlFormSignature($element) {
$element['#attributes']['type'] = 'hidden';
Element::setAttributes($element, [
'name',
'value',
]);
static::setAttributes($element, [
'js-yamlform-signature',
'form-yamlform-signature',
]);
$build = [
'#prefix' => '<div class="js-yamlform-signature-pad yamlform-signature-pad">',
'#suffix' => '</div>',
];
$build['reset'] = [
'#type' => 'button',
'#value' => t('Reset'),
];
$build['canvas'] = [
'#type' => 'html_tag',
'#tag' => 'canvas',
];
$element['#children'] = $build;
$element['#attached']['library'][] = 'yamlform/yamlform.element.signature';
return $element;
}
}