You are here

file_link.module in File Link 8

Same filename and directory in other branches
  1. 2.0.x file_link.module

Contains file_link.module.

File

file_link.module
View source
<?php

/**
 * @file
 * Contains file_link.module.
 */
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Link;

/**
 * Implements hook_help().
 */
function file_link_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the featured_content module.
    case 'help.page.file_link':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('File Link module provides a field that extends the core Link module field by storing metadata about the target file like size and mime-type. The link URI must point to file not to a directory. The site builder can define a list of allowed target file extensions.') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_theme().
 */
function file_link_theme() {
  return [
    'file_link_formatter' => [
      'variables' => [
        'link' => NULL,
        'size' => NULL,
        'format' => NULL,
      ],
    ],
    'file_link_formatter_link_separate' => [
      'variables' => [
        'title' => NULL,
        'url_title' => NULL,
        'url' => NULL,
        'size' => NULL,
        'format' => NULL,
      ],
    ],
  ];
}

/**
 * Prepares variables for separated file_link field templates.
 *
 * This template outputs a separate title and link.
 *
 * Default template: file-link-formatter-link-separate.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - title: (optional) A descriptive or alternate title for the link, which
 *     may be different than the actual link text.
 *   - url_title: The anchor text for the link.
 *   - url: A \Drupal\Core\Url object.
 *   - size: The target file size formatted according to formatter settings.
 *   - format: The file mime-type.
 */
function template_preprocess_file_link_formatter_link_separate(array &$variables) {
  $variables['link'] = Link::fromTextAndUrl($variables['url_title'], $variables['url']);
}

Functions

Namesort descending Description
file_link_help Implements hook_help().
file_link_theme Implements hook_theme().
template_preprocess_file_link_formatter_link_separate Prepares variables for separated file_link field templates.