protected function LinkToFileConstraint::hasValidExtension in File Link 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Validation/Constraint/LinkToFileConstraint.php \Drupal\file_link\Plugin\Validation\Constraint\LinkToFileConstraint::hasValidExtension()
Check whereas basename has a valid extension.
Parameters
string $basename: URL path basename.
\Drupal\file_link\Plugin\Field\FieldType\FileLinkItem $link: Link item.
Return value
bool Whereas basename has a valid extension.
1 call to LinkToFileConstraint::hasValidExtension()
- LinkToFileConstraint::validate in src/
Plugin/ Validation/ Constraint/ LinkToFileConstraint.php - Checks if the passed value is valid.
File
- src/
Plugin/ Validation/ Constraint/ LinkToFileConstraint.php, line 159
Class
- LinkToFileConstraint
- Validation constraint for file_link, checking that URI points to a file.
Namespace
Drupal\file_link\Plugin\Validation\ConstraintCode
protected function hasValidExtension($basename, FileLinkItem $link) {
$extensions = trim($link
->getFieldDefinition()
->getSetting('file_extensions'));
if (!empty($extensions)) {
$regex = '/\\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')$/i';
return (bool) preg_match($regex, $basename) !== FALSE;
}
return TRUE;
}