function _media_gallery_get_media_title in Media Gallery 7
Same name and namespace in other branches
- 7.2 media_gallery.fields.inc \_media_gallery_get_media_title()
Gets the title of a media entity either from the media_title field or based on the filename.
4 calls to _media_gallery_get_media_title()
- media_gallery_detail_page in ./
media_gallery.pages.inc - Menu callback; view a single gallery media entity as its own page.
- media_gallery_field_formatter_view in ./
media_gallery.fields.inc - Implements hook_field_formatter_view().
- media_gallery_form_alter in ./
media_gallery.module - Implements hook_form_alter().
- media_gallery_media_page_edit in ./
media_gallery.pages.inc - Menu callback; presents the Media editing form in the context of a gallery.
File
- ./
media_gallery.fields.inc, line 220 - Field API integration for media_gallery.module.
Code
function _media_gallery_get_media_title($file) {
// If the entity has a value for the title field, use it.
if (isset($file->media_title[LANGUAGE_NONE][0]['value'])) {
$title = $file->media_title[LANGUAGE_NONE][0]['value'];
}
else {
$replacements = array(
'/\\..*/' => '',
// Remove first "." and everything after.
'/[^a-zA-Z0-9]+/' => ' ',
// Replace non letters or numbers with a single space.
'/([a-z])([A-Z])/' => '\\1 \\2',
// Insert a space between a lowercase letter and an uppercase letter.
'/([a-zA-Z])([0-9])/' => '\\1 \\2',
// Insert a space between a letter and a number.
'/([0-9])([a-zA-Z])/' => '\\1 \\2',
);
// In addition to above replacements, also capitalize the first letter of
// each word, and remove leading and trailing spaces.
$title = trim(ucwords(preg_replace(array_keys($replacements), array_values($replacements), $file->filename)));
}
return $title;
}