You are here

public static function WebformTermsOfService::processCheckbox in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Element/WebformTermsOfService.php \Drupal\webform\Element\WebformTermsOfService::processCheckbox()

Sets the #checked property of a checkbox element.

Overrides Checkbox::processCheckbox

File

src/Element/WebformTermsOfService.php, line 44

Class

WebformTermsOfService
Provides a webform terms of service element.

Namespace

Drupal\webform\Element

Code

public static function processCheckbox(&$element, FormStateInterface $form_state, &$complete_form) {
  $element = parent::processCheckbox($element, $form_state, $complete_form);

  // Remove curly brackets from the {terms of service} title.
  if (empty($element['#required_error'])) {
    $title = empty($element['#title']) ? (string) t('I agree to the {terms of service}.') : $element['#title'];
    $title = str_replace('{', '', $title);
    $title = str_replace('}', '', $title);
    $element['#required_error'] = t('@name field is required.', [
      '@name' => $title,
    ]);
  }
  return $element;
}