You are here

public function YaMapsBlock::yamapsFieldValidatePixelsPercentage in Yandex.Maps 8

Validate pixels or percentage value.

Parameters

array $element: Field form element.

\Drupal\Core\Form\FormStateInterface $form_state: Field form state.

File

src/Plugin/Block/YaMapsBlock.php, line 341

Class

YaMapsBlock
Provides a yandex map block.

Namespace

Drupal\yamaps\Plugin\Block

Code

public function yamapsFieldValidatePixelsPercentage(array $element, FormStateInterface $form_state) {
  $value = $element['#value'];
  if (!preg_match('/^[1-9]{1}[0-9]*(px|%)$/', $value)) {
    $form_state
      ->setErrorByName($element['#name'], $this
      ->t('%name must be a positive integer value and has "%" or "px" at the end.', [
      '%name' => $element['#title'],
    ]));
  }
}