Commit f6869c6d authored by iMiksu's avatar iMiksu Committed by g089h515r806

Issue #2168719 by iMiksu, yenidem, jeni_dc, pingevt, BD3: Show only image file name

parent b5b83fb8
......@@ -8,6 +8,7 @@
/**
* Define constants for determine which type of URL should be used.
*/
define('IMAGE_URL_FORMATTER_FILENAME', '4');
define('IMAGE_URL_FORMATTER_URI_PATH', '3');
define('IMAGE_URL_FORMATTER_RELATIVE_PATH', '2');
define('IMAGE_URL_FORMATTER_ABSOLUTE_PATH', '1');
......@@ -59,6 +60,7 @@ function image_url_formatter_field_formatter_settings_form($field, $instance, $v
'#title' => t('URL type'),
'#type' => 'radios',
'#options' => array(
IMAGE_URL_FORMATTER_FILENAME => t('Filename'),
IMAGE_URL_FORMATTER_URI_PATH => t('URI path'),
IMAGE_URL_FORMATTER_RELATIVE_PATH => t('Relative file path'),
IMAGE_URL_FORMATTER_ABSOLUTE_PATH => t('Absolute file path (recommended)'),
......@@ -66,6 +68,7 @@ function image_url_formatter_field_formatter_settings_form($field, $instance, $v
),
'#default_value' => $settings['url_type'],
);
$element['url_type'][IMAGE_URL_FORMATTER_FILENAME]['#description'] = t("Filename only, like: 'image.png'");
$element['url_type'][IMAGE_URL_FORMATTER_URI_PATH]['#description'] = t("Uses the URI path, like: 'public://image.png'");
$element['url_type'][IMAGE_URL_FORMATTER_RELATIVE_PATH]['#description'] = t("No base URL or leading slash, like: 'sites/default/files/image.png'");
$element['url_type'][IMAGE_URL_FORMATTER_ABSOLUTE_PATH]['#description'] = t("With leading slash, no base URL, like: '/sites/default/files/image.png'");
......@@ -105,6 +108,10 @@ function image_url_formatter_field_formatter_settings_summary($field, $instance,
$summary = array();
switch ($settings['url_type']) {
case IMAGE_URL_FORMATTER_FILENAME:
$summary[] = t('Use filename');
break;
case IMAGE_URL_FORMATTER_URI_PATH:
$summary[] = t('Use uri path');
break;
......@@ -233,6 +240,7 @@ function theme_image_url_formatter($variables) {
* @param string $url
* The full URL to convet.
* @param constant $format
* IMAGE_URL_FORMATTER_FILENAME for filename only,
* IMAGE_URL_FORMATTER_RELATIVE_PATH for relative path,
* IMAGE_URL_FORMATTER_ABSOLUTE_PATH for absolute path,
* IMAGE_URL_FORMATTER_FULL_URL for full URL.
......@@ -242,6 +250,10 @@ function theme_image_url_formatter($variables) {
*/
function image_url_formatter_convert_full_url($url, $format = IMAGE_URL_FORMATTER_FULL_URL) {
switch ($format) {
case IMAGE_URL_FORMATTER_FILENAME:
$url = _image_url_formater_get_filename($url);
break;
case IMAGE_URL_FORMATTER_RELATIVE_PATH:
$url = _image_url_formatter_get_relative_file_url($url);
break;
......@@ -275,3 +287,13 @@ function _image_url_formatter_get_relative_file_url($url) {
}
return $url;
}
/**
* Returns the filename from the url.
*/
function _image_url_formater_get_filename($url) {
$url = _image_url_formatter_get_absolute_file_url($url);
$exploded_url = explode('/', $url);
$url = array_pop($exploded_url);
return $url;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment