You are here

public function FileLink::preprocess in Open Social 8.2

Same name and namespace in other branches
  1. 8.9 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink::preprocess()
  2. 8 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink::preprocess()
  3. 8.3 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink::preprocess()
  4. 8.4 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink::preprocess()
  5. 8.5 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink::preprocess()
  6. 8.6 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink::preprocess()
  7. 8.7 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink::preprocess()
  8. 8.8 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink::preprocess()

Preprocess theme hook variables.

Parameters

array $variables: The variables array, passed by reference (modify in place).

string $hook: The name of the theme hook.

array $info: The theme hook info array.

Overrides PreprocessBase::preprocess

File

themes/socialbase/src/Plugin/Preprocess/FileLink.php, line 22

Class

FileLink
Pre-processes variables for the "file_link" theme hook.

Namespace

Drupal\socialbase\Plugin\Preprocess

Code

public function preprocess(array &$variables, $hook, array $info) {
  parent::preprocess($variables, $hook, $info);

  // Find out what the active theme is first.
  $theme = \Drupal::theme()
    ->getActiveTheme();

  // Check if socialbase is one of the base themes.
  // Then get the path to socialbase theme and provide a variable
  // that can be used in the template for a path to the icons.
  if (array_key_exists('socialbase', $theme
    ->getBaseThemes())) {
    $basethemes = $theme
      ->getBaseThemes();
    $variables['path_to_socialbase'] = $basethemes['socialbase']
      ->getPath();
  }
  $file = $variables['file'] instanceof File ? $variables['file'] : File::load($variables['file']->fid);
  $mime_type = $file
    ->getMimeType();
  $generic_mime_type = file_icon_class($mime_type);
  if (isset($generic_mime_type)) {

    // Set new icons for the mime types.
    switch ($generic_mime_type) {
      case 'application-pdf':
        $node_icon = 'pdf';
        break;
      case 'x-office-document':
        $node_icon = 'document';
        break;
      case 'x-office-presentation':
        $node_icon = 'presentation';
        break;
      case 'x-office-spreadsheet':
        $node_icon = 'spreadsheet';
        break;
      case 'package-x-generic':
        $node_icon = 'archive';
        break;
      case 'audio':
        $node_icon = 'audio';
        break;
      case 'video':
        $node_icon = 'video';
        break;
      case 'image':
        $node_icon = 'image';
        break;
      default:
        $node_icon = 'text';
    }
  }

  // Set a new variable to be used in the template file.
  $variables['node_icon'] = $node_icon;
}