Issue #3055474 by Gribnif, Berdir: template_preprocess_file_link will not work with a stdClass object, though it tries to
							parent
							
								
									f4fbbd1e65
								
							
						
					
					
						commit
						070e49b1a5
					
				| 
						 | 
					@ -1443,7 +1443,7 @@ function template_preprocess_file_managed_file(&$variables) {
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @param array $variables
 | 
					 * @param array $variables
 | 
				
			||||||
 *   An associative array containing:
 | 
					 *   An associative array containing:
 | 
				
			||||||
 *   - file: A file object to which the link will be created.
 | 
					 *   - file: A File entity to which the link will be created.
 | 
				
			||||||
 *   - icon_directory: (optional) A path to a directory of icons to be used for
 | 
					 *   - icon_directory: (optional) A path to a directory of icons to be used for
 | 
				
			||||||
 *     files. Defaults to the value of the "icon.directory" variable.
 | 
					 *     files. Defaults to the value of the "icon.directory" variable.
 | 
				
			||||||
 *   - description: A description to be displayed instead of the filename.
 | 
					 *   - description: A description to be displayed instead of the filename.
 | 
				
			||||||
| 
						 | 
					@ -1453,13 +1453,12 @@ function template_preprocess_file_link(&$variables) {
 | 
				
			||||||
  $file = $variables['file'];
 | 
					  $file = $variables['file'];
 | 
				
			||||||
  $options = [];
 | 
					  $options = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $file_entity = ($file instanceof File) ? $file : File::load($file->fid);
 | 
					 | 
				
			||||||
  // @todo Wrap in file_url_transform_relative(). This is currently
 | 
					  // @todo Wrap in file_url_transform_relative(). This is currently
 | 
				
			||||||
  // impossible. As a work-around, we currently add the 'url.site' cache context
 | 
					  // impossible. As a work-around, we currently add the 'url.site' cache context
 | 
				
			||||||
  // to ensure different file URLs are generated for different sites in a
 | 
					  // to ensure different file URLs are generated for different sites in a
 | 
				
			||||||
  // multisite setup, including HTTP and HTTPS versions of the same site.
 | 
					  // multisite setup, including HTTP and HTTPS versions of the same site.
 | 
				
			||||||
  // Fix in https://www.drupal.org/node/2646744.
 | 
					  // Fix in https://www.drupal.org/node/2646744.
 | 
				
			||||||
  $url = $file_entity->createFileUrl(FALSE);
 | 
					  $url = $file->createFileUrl(FALSE);
 | 
				
			||||||
  $variables['#cache']['contexts'][] = 'url.site';
 | 
					  $variables['#cache']['contexts'][] = 'url.site';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $mime_type = $file->getMimeType();
 | 
					  $mime_type = $file->getMimeType();
 | 
				
			||||||
| 
						 | 
					@ -1469,11 +1468,11 @@ function template_preprocess_file_link(&$variables) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Use the description as the link text if available.
 | 
					  // Use the description as the link text if available.
 | 
				
			||||||
  if (empty($variables['description'])) {
 | 
					  if (empty($variables['description'])) {
 | 
				
			||||||
    $link_text = $file_entity->getFilename();
 | 
					    $link_text = $file->getFilename();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  else {
 | 
					  else {
 | 
				
			||||||
    $link_text = $variables['description'];
 | 
					    $link_text = $variables['description'];
 | 
				
			||||||
    $options['attributes']['title'] = $file_entity->getFilename();
 | 
					    $options['attributes']['title'] = $file->getFilename();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Classes to add to the file field for icons.
 | 
					  // Classes to add to the file field for icons.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue