function image_effects_image_effects_text_overlay_text_alter in Image Effects 8.2
Same name and namespace in other branches
- 8.3 image_effects.module \image_effects_image_effects_text_overlay_text_alter()
- 8 image_effects.module \image_effects_image_effects_text_overlay_text_alter()
Implements hook_image_effects_text_overlay_text_alter().
File
- ./
image_effects.module, line 118 - Provides effects and operations for the Image API.
Code
function image_effects_image_effects_text_overlay_text_alter(&$text, ConfigurableImageEffectBase $image_effect) {
// Skip if the effect is not TextOverlayImageEffect or an alternative
// implementation.
if ($image_effect
->getPluginId() !== "image_effects_text_overlay") {
return;
}
// Get effect data.
$effect_data = $image_effect
->getConfiguration()['data'];
// Strip HTML tags, if requested.
if ($effect_data['text']['strip_tags'] === TRUE) {
$text = strip_tags($text);
}
// Decode HTML entities, if requested.
if ($effect_data['text']['decode_entities'] === TRUE) {
$text = Html::decodeEntities($text);
}
// Convert case, if requested.
if ($effect_data['text']['case_format']) {
$method_map = [
'upper' => 'strtoupper',
'lower' => 'strtolower',
'ucwords' => 'ucwords',
'ucfirst' => 'ucfirst',
];
$text = Unicode::{$method_map[$effect_data['text']['case_format']]}($text);
}
// Limit the maximum number of characters.
if ($effect_data['text']['maximum_chars'] > 0 && Unicode::strlen($text) > $effect_data['text']['maximum_chars']) {
$text = Unicode::substr($text, 0, $effect_data['text']['maximum_chars']) . $effect_data['text']['excess_chars_text'];
}
}