You are here

function file_entity_replace_title in File Entity (fieldable files) 7.2

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

Replace file entity title text.

Parameters

$file: The file entity.

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

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

string $langcode: (Optional) Language code

Return value

string Returns the replaced title text.

2 calls to file_entity_replace_title()
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 1268
Extends Drupal file entities to be fieldable and viewable.

Code

function file_entity_replace_title($file, $replace_options = array(), $title = NULL, $langcode = NULL) {
  $replace_options += array(
    'clear' => TRUE,
    'sanitize' => FALSE,
  );
  $title_default = '[file:field_file_image_title_text]';
  if (!isset($title)) {
    $title = variable_get('file_entity_title', $title_default);
  }

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

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