Back to HTMLHelper class

Method tooltipText

public static string
tooltipText
(mixed $title = '', mixed $content = '', mixed $translate = true, mixed $escape = true)
Converts a double colon separated string or 2 separate strings to a string ready for bootstrap tooltips
Parameters
  • string $title The title of the tooltip (or combined '::' separated string).
  • string $content The content to tooltip.
  • bool $translate If true will pass texts through Text.
  • bool $escape If true will pass texts through htmlspecialchars.
Returns
  • string The tooltip string
Since
  • 3.1.2
Class: HTMLHelper
Project: Joomla

Method tooltipText - Source code

/**
 * Converts a double colon separated string or 2 separate strings to a string ready for bootstrap tooltips
 *
 * @param   string   $title      The title of the tooltip (or combined '::' separated string).
 * @param   string   $content    The content to tooltip.
 * @param   boolean  $translate  If true will pass texts through Text.
 * @param   boolean  $escape     If true will pass texts through htmlspecialchars.
 *
 * @return  string  The tooltip string
 *
 * @since   3.1.2
 */
public static function tooltipText($title = '', $content = '', $translate = true, $escape = true)
{
    // Initialise return value.
    $result = '';
    // Don't process empty strings
    if ($content !== '' || $title !== '') {
        // Split title into title and content if the title contains '::' (old Mootools format).
        if ($content === '' && !(strpos($title, '::') === false)) {
            list($title, $content) = explode('::', $title, 2);
        }
        // Pass texts through Text if required.
        if ($translate) {
            $title = Text::_($title);
            $content = Text::_($content);
        }
        // Use only the content if no title is given.
        if ($title === '') {
            $result = $content;
        } elseif ($title === $content) {
            $result = '<strong>' . $title . '</strong>';
        } elseif ($content !== '') {
            $result = '<strong>' . $title . '</strong><br>' . $content;
        } else {
            $result = $title;
        }
        // Escape everything, if required.
        if ($escape) {
            $result = htmlspecialchars($result);
        }
    }
    return $result;
}