class FileRequirements
Requirements for the File module.
Hierarchy
- class \Drupal\file\Hook\FileRequirements uses \Drupal\Core\StringTranslation\StringTranslationTrait
Expanded class hierarchy of FileRequirements
File
-
core/
modules/ file/ src/ Hook/ FileRequirements.php, line 11
Namespace
Drupal\file\HookView source
class FileRequirements {
use StringTranslationTrait;
/**
* Implements hook_runtime_requirements().
*/
public function runtime() : array {
$requirements = [];
$server_software = \Drupal::request()->server
->get('SERVER_SOFTWARE', '');
// Get the web server identity.
$is_nginx = preg_match("/Nginx/i", $server_software);
$is_apache = preg_match("/Apache/i", $server_software);
$fastcgi = $is_apache && (str_contains($server_software, 'mod_fastcgi') || str_contains($server_software, 'mod_fcgi'));
// Check the uploadprogress extension is loaded.
if (extension_loaded('uploadprogress')) {
$value = $this->t('Enabled (<a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress</a>)');
$description = NULL;
}
else {
$value = $this->t('Not enabled');
$description = $this->t('Your server is capable of displaying file upload progress, but does not have the required libraries. It is recommended to install the <a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress library</a>.');
}
// Adjust the requirement depending on what the server supports.
if (!$is_apache && !$is_nginx) {
$value = $this->t('Not enabled');
$description = $this->t('Your server is not capable of displaying file upload progress. File upload progress requires an Apache server running PHP with mod_php or Nginx with PHP-FPM.');
}
elseif ($fastcgi) {
$value = $this->t('Not enabled');
$description = $this->t('Your server is not capable of displaying file upload progress. File upload progress requires PHP be run with mod_php or PHP-FPM and not as FastCGI.');
}
$requirements['file_progress'] = [
'title' => $this->t('Upload progress'),
'value' => $value,
'description' => $description,
];
return $requirements;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
FileRequirements::runtime | public | function | Implements hook_runtime_requirements(). | |
StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 |
StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | |
StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | |
StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. | 1 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.