5 * Install, update and uninstall functions for File module.
8 use Drupal\Core\Entity\Entity\EntityViewDisplay;
11 * Implements hook_schema().
13 function file_schema() {
14 $schema['file_usage'] = [
15 'description' => 'Track where a file is used.',
18 'description' => 'File ID.',
24 'description' => 'The name of the module that is using the file.',
25 'type' => 'varchar_ascii',
26 'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH,
31 'description' => 'The name of the object type in which the file is used.',
32 'type' => 'varchar_ascii',
38 'description' => 'The primary key of the object using the file.',
39 'type' => 'varchar_ascii',
45 'description' => 'The number of times this file is used by this object.',
52 'primary key' => ['fid', 'type', 'id', 'module'],
54 'type_id' => ['type', 'id'],
55 'fid_count' => ['fid', 'count'],
56 'fid_module' => ['fid', 'module'],
63 * Implements hook_requirements().
65 * Display information about getting upload progress bars working.
67 function file_requirements($phase) {
70 // Check the server's ability to indicate upload progress.
71 if ($phase == 'runtime') {
73 $implementation = file_progress_implementation();
74 $server_software = \Drupal::request()->server->get('SERVER_SOFTWARE');
76 // Test the web server identity.
77 if (preg_match("/Nginx/i", $server_software)) {
82 elseif (preg_match("/Apache/i", $server_software)) {
85 $fastcgi = strpos($server_software, 'mod_fastcgi') !== FALSE || strpos($server_software, 'mod_fcgi') !== FALSE;
93 if (!$is_apache && !$is_nginx) {
94 $value = t('Not enabled');
95 $description = 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.');
98 $value = t('Not enabled');
99 $description = 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.');
101 elseif (!$implementation) {
102 $value = t('Not enabled');
103 $description = 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>.');
105 elseif ($implementation == 'apc') {
106 $value = t('Enabled (<a href="http://php.net/manual/apcu.configuration.php#ini.apcu.rfc1867">APC RFC1867</a>)');
107 $description = t('Your server is capable of displaying file upload progress using APC RFC1867. Note that only one upload at a time is supported. It is recommended to use the <a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress library</a> if possible.');
109 elseif ($implementation == 'uploadprogress') {
110 $value = t('Enabled (<a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress</a>)');
112 $requirements['file_progress'] = [
113 'title' => t('Upload progress'),
115 'description' => $description,
119 return $requirements;
123 * Prevent unused files from being deleted.
125 function file_update_8300() {
126 // Disable deletion of unused permanent files.
127 \Drupal::configFactory()->getEditable('file.settings')
128 ->set('make_unused_managed_files_temporary', FALSE)
131 return t('Files that have no remaining usages are no longer deleted by default.');
135 * Add 'use_description_as_link_text' setting to file field formatters.
137 function file_update_8001() {
138 $displays = EntityViewDisplay::loadMultiple();
139 foreach ($displays as $display) {
140 /** @var \Drupal\Core\Entity\Entity\EntityViewDisplay $display */
141 $fields_settings = $display->get('content');
143 foreach ($fields_settings as $field_name => $settings) {
144 if (!empty($settings['type'])) {
145 switch ($settings['type']) {
146 // The file_table formatter never displayed available descriptions
147 // before, so we disable this option to ensure backward compatibility.
149 $fields_settings[$field_name]['settings']['use_description_as_link_text'] = FALSE;
153 // The file_default formatter always displayed available descriptions
154 // before, so we enable this option to ensure backward compatibility.
156 $fields_settings[$field_name]['settings']['use_description_as_link_text'] = TRUE;
162 if ($changed === TRUE) {
163 $display->set('content', $fields_settings)->save();