You are here

public function UltimenuTool::extractTitleHtml in Ultimenu 8.2

Returns titles as both HTML and plain text titles.

File

src/UltimenuTool.php, line 196

Class

UltimenuTool
Provides Ultimenu utility methods.

Namespace

Drupal\ultimenu

Code

public function extractTitleHtml($link) {
  $icon = '';
  $goodies = $this
    ->getSetting('goodies');
  $titles = $this
    ->extractTitle($link);
  $title_html = $title = $titles['title'];
  if (!empty($titles['icon'])) {
    $icon_class = $titles['fa'] ? 'fa ' . $titles['icon'] : 'icon ' . $titles['icon'];
    $icon = '<span class="ultimenu__icon ' . $icon_class . '" aria-hidden="true"></span>';
  }
  if (!empty($goodies['menu-desc']) && ($description = $link
    ->getDescription())) {

    // Render description, if so configured.
    // If you override this, be sure to have proper sanitization.
    $description = '<small>' . strip_tags($description, '<em><strong><i><b>') . '</small>';
    $title_html = !empty($goodies['desc-top']) ? $description . $title : $title . $description;
  }

  // Holds the title in a separate SPAN for easy positioning if it has icon.
  if ($icon) {
    $title_html = $icon . '<span class="ultimenu__title">' . $title_html . '</span>';
  }
  return [
    'title' => $title,
    'title_html' => $title_html,
  ];
}