You are here

public static function Signature::processElement in SignatureField 1.x

Processes a signature element.

Parameters

array $element: The element being processed.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array $complete_form: The complete form structure.

Return value

array The altered form element.

File

src/Element/Signature.php, line 100

Class

Signature
Provides a form element for a signature.

Namespace

Drupal\signaturefield\Element

Code

public static function processElement(array $element, FormStateInterface $form_state, array $complete_form) {
  $value_id = Html::getUniqueId('signature-value');
  $canvas_id = Html::getUniqueId('signature-canvas');
  $element['value'] = [
    '#type' => 'hidden',
    '#default_value' => $element['#value'],
    '#parents' => $element['#parents'],
    '#attributes' => [
      'id' => $value_id,
    ],
  ];
  $element['canvas'] = [
    '#theme' => 'signature_canvas',
    '#id' => $canvas_id,
    '#width' => $element['#width'],
    '#height' => $element['#height'],
  ];
  $element['#attached']['library'][] = 'signaturefield/signature';
  $element['#attached']['drupalSettings']['signaturefield'][$canvas_id] = [
    'valueId' => $value_id,
    'penColor' => $element['#pen_color'],
    'backgroundColor' => $element['#background_color'],
  ];
  return $element;
}