function NavigationLinkBlock::validateIconClassElement

Form element validation handler for the 'icon_class' element.

Disallows saving invalid class values.

File

core/modules/navigation/src/Plugin/Block/NavigationLinkBlock.php, line 105

Class

NavigationLinkBlock
Defines a link navigation block.

Namespace

Drupal\navigation\Plugin\Block

Code

public static function validateIconClassElement(array $element, FormStateInterface $form_state, array $form) : void {
    $icon = $element['#value'];
    if (!preg_match('/^[a-z0-9_-]+$/', $icon)) {
        $form_state->setError($element, t('The machine-readable name must contain only lowercase letters, numbers, underscores and hyphens.'));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.