You are here

function file_entity_replace_alt in File Entity (fieldable files) 7.2

Same name and namespace in other branches
  1. 7.3 file_entity.module \file_entity_replace_alt()

Replace file entity alt.

Parameters

$file: The file entity.

array $replace_options: (Optional) Options to pass to token_replace().

$alt: (Optional) The alt text to use.

string $langcode: (Optional) Language code

Return value

string Returns the replaced alt text.

2 calls to file_entity_replace_alt()
file_entity_file_formatter_file_image_view in ./file_entity.module
Implements hook_file_formatter_FORMATTER_view().
file_entity_set_title_alt_properties in ./file_entity.file.inc
Set the title / alt properties of file objects.

File

./file_entity.module, line 1307
Extends Drupal file entities to be fieldable and viewable.

Code

function file_entity_replace_alt($file, $replace_options = array(), $alt = NULL, $langcode = NULL) {
  $replace_options += array(
    'clear' => TRUE,
    'sanitize' => FALSE,
  );
  $alt_default = '[file:field_file_image_alt_text]';
  if (!isset($alt)) {
    $alt = variable_get('file_entity_alt', $alt_default);
  }

  // If the defaults are not changed then inlining replacement is much faster
  // than dealing with the token system.
  if ($alt === $alt_default) {
    $alt_items = field_get_items('file', $file, 'field_file_image_alt_text', $langcode);
    return $alt_items ? $alt_items[0]['value'] : '';
  }
  elseif (!empty($alt)) {
    $token_replaced = token_replace($alt, array(
      'file' => $file,
    ), $replace_options);
    return decode_entities($token_replaced);

    // Filter out possible XSS.
  }
  return '';
}