You are here

public function Countdown::blockValidate in Countdown 8

Implements form validation.

The validateForm method is the default method called to validate input on a form.

Parameters

array $form: The render array of the currently built form.

FormStateInterface $form_state: Object describing the current state of the form.

Overrides BlockPluginTrait::blockValidate

File

src/Plugin/Block/countdown.php, line 269

Class

Countdown
Provides a 'Countdown' Block.

Namespace

Drupal\countdown\Plugin\Block

Code

public function blockValidate($form, FormStateInterface $form_state) {
  $url = $form_state
    ->getValue('countdown_url');
  if ($url != "" || $url == "<front>") {
    if (!UrlHelper::isExternal($url) && !(strpos($url, '/') === 0)) {
      $form_state
        ->setErrorByName('countdown_url', $this
        ->t('Event URL is not vaild. Entered paths should start with /'));
    }
  }
}