You are here

class FileLink 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
  2. 8 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink
  3. 8.3 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink
  4. 8.4 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink
  5. 8.5 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink
  6. 8.6 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink
  7. 8.7 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink
  8. 8.8 themes/socialbase/src/Plugin/Preprocess/FileLink.php \Drupal\socialbase\Plugin\Preprocess\FileLink

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

Plugin annotation


@BootstrapPreprocess("file_link",
  replace = "template_preprocess_file_link"
)

Hierarchy

Expanded class hierarchy of FileLink

File

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

Namespace

Drupal\socialbase\Plugin\Preprocess
View source
class FileLink extends BaseFileLink {

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FileLink::preprocess public function Preprocess theme hook variables. Overrides PreprocessBase::preprocess
FileLink::preprocessVariables public function Preprocess the variables array. Overrides PreprocessBase::preprocessVariables
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::$theme protected property The currently set theme object.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct 1
PreprocessBase::$hook protected property The theme hook invoked.
PreprocessBase::$info protected property The theme hook info array from the theme registry.
PreprocessBase::$variables protected property The Variables object.
PreprocessBase::preprocessAttributes protected function Ensures all attributes have been converted to an Attribute object.
PreprocessBase::preprocessDescription protected function Converts any set description variable into a traversable array.
PreprocessBase::preprocessElement protected function Preprocess the variables array if an element is present. 8
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
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.