public static function MinisiteItem::validateNoDeniedExtensions in Mini site 8
Check that entered extensions are not in the denied extensions list.
File
- src/
Plugin/ Field/ FieldType/ MinisiteItem.php, line 178
Class
- MinisiteItem
- Plugin implementation of the Minisite field type.
Namespace
Drupal\minisite\Plugin\Field\FieldTypeCode
public static function validateNoDeniedExtensions($element, FormStateInterface $form_state) {
if (!empty($element['#value'])) {
$extensions = preg_replace('/([, ]+\\.?)/', ' ', trim(strtolower($element['#value'])));
$extensions = array_filter(explode(' ', $extensions));
$denied_extensions = explode(' ', MinisiteInterface::DENIED_EXTENSIONS);
$invalid_extensions = array_intersect($extensions, $denied_extensions);
if (count($invalid_extensions) > 0) {
$form_state
->setError($element, t('The list of allowed extensions is not valid, be sure to not include %ext extension(s).', [
'%ext' => implode(', ', $invalid_extensions),
]));
}
}
}