public static function FontAwesomeIconWidget::validateIconName in Font Awesome Icons 8.2
Validate the Font Awesome icon name.
1 method overrides FontAwesomeIconWidget::validateIconName()
- FontAwesomeIconpickerWidget::validateIconName in modules/
fontawesome_iconpicker_widget/ src/ Plugin/ Field/ FieldWidget/ FontAwesomeIconpickerWidget.php - Validate the Font Awesome icon name.
File
- src/
Plugin/ Field/ FieldWidget/ FontAwesomeIconWidget.php, line 487
Class
- FontAwesomeIconWidget
- Plugin implementation of the 'fontawesome_icon' widget.
Namespace
Drupal\fontawesome\Plugin\Field\FieldWidgetCode
public static function validateIconName($element, FormStateInterface $form_state) {
// Load the configuration settings.
$configuration_settings = \Drupal::config('fontawesome.settings');
// Check if we need to bypass.
if ($configuration_settings
->get('bypass_validation')) {
return;
}
$value = $element['#value'];
if (strlen($value) == 0) {
$form_state
->setValueForElement($element, '');
return;
}
// Load the icon data so we can check for a valid icon.
$iconData = \Drupal::service('fontawesome.font_awesome_manager')
->getIconMetadata($value);
if (!isset($iconData['name'])) {
$form_state
->setError($element, t("Invalid icon name %value. Please see @iconLink for correct icon names, or turn off validation in the Font Awesome settings if you are trying to use custom icon names.", [
'%value' => $value,
'@iconLink' => Link::fromTextAndUrl(t('the Font Awesome icon list'), Url::fromUri('https://fontawesome.com/icons'))
->toString(),
]));
}
}