You are here

filefield_sources.api.php in FileField Sources 8

Same filename and directory in other branches
  1. 6 filefield_sources.api.php
  2. 7 filefield_sources.api.php

This file documents hooks provided by the FileField Sources module.

Note that none of this code is executed by using FileField Sources module, it is provided here for reference as an example how to implement these hooks in your own module.

File

filefield_sources.api.php
View source
<?php

/**
 * @file
 * This file documents hooks provided by the FileField Sources module.
 *
 * Note that none of this code is executed by using FileField Sources module,
 * it is provided here for reference as an example how to implement these hooks
 * in your own module.
 */

/**
 * Returns a list of widgets that are compatible with FileField Sources.
 *
 * FileField Sources works with the most common widgets used with Drupal (the
 * standard Image and File widgets). Any module that provides another widget
 * for uploading files may add compatibility with FileField Sources by
 * implementing this hook and returning the widgets that their module supports.
 */
function hook_filefield_sources_widgets() {

  // Add any widgets that your module supports here.
  return [
    'mymodule_file_widgetname',
  ];
}

/**
 * Allows altering the sources available on a field.
 *
 * This hook allows other modules to modify the sources available to a user.
 *
 * @param array $sources
 *   List of filefiled sources plugins.
 *
 * @param mixed $context
 *   Contains 'enabled_sources', 'element', 'form_state'.
 */
function hook_filefield_sources_sources_alter(&$sources, $context) {

  // This example will exclude sources the user doesn't have access to.
  foreach (array_keys($sources) as $type) {
    if (!user_access("use {$type} filefield source")) {
      unset($sources[$type]);
    }
  }
}

Functions

Namesort descending Description
hook_filefield_sources_sources_alter Allows altering the sources available on a field.
hook_filefield_sources_widgets Returns a list of widgets that are compatible with FileField Sources.