getValue()); $extensions = preg_split('/[\s,]+/', $value, -1, PREG_SPLIT_NO_EMPTY) ?: []; if (!$extensions) { throw new LocalizedException(__('At least one allowed extension is required.')); } foreach ($extensions as $extension) { if (!preg_match('/^[a-z0-9]+$/', $extension)) { throw new LocalizedException(__('Invalid extension: %1', $extension)); } if (in_array($extension, FilePolicy::BLOCKED_EXTENSIONS, true)) { throw new LocalizedException(__('The extension %1 is always forbidden.', $extension)); } if (!in_array($extension, FilePolicy::getSupportedExtensions(), true)) { throw new LocalizedException( __('The extension %1 does not have a secure MIME policy.', $extension) ); } } $this->setValue(implode(',', array_values(array_unique($extensions)))); return parent::beforeSave(); } }