You are here

function yamlform_system_breadcrumb_alter in YAML Form 8

Implements hook_system_breadcrumb_alter().

File

./yamlform.module, line 168
Enables the creation of forms and questionnaires.

Code

function yamlform_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInterface $route_match, array $context) {

  // Remove 'Forms' prefix from breadcrumb links generated path breadcrumbs.
  // @see \Drupal\system\PathBasedBreadcrumbBuilder
  $path = Url::fromRouteMatch($route_match)
    ->toString();
  if (strpos($path, '/admin/structure/yamlform/settings/') !== FALSE) {
    $links = $breadcrumb
      ->getLinks();
    foreach ($links as $link) {
      $text = $link
        ->getText();
      if (strpos($text, (string) t('Forms') . ' ') == 0) {
        $text = str_replace((string) t('Forms') . ': ', '', $text);
        $link
          ->setText(Unicode::ucfirst($text));
      }
    }
  }

  // Fix 'Help' breadcrumb text.
  if ($route_match
    ->getRouteName() == 'yamlform.help') {
    $links = $breadcrumb
      ->getLinks();
    $link = end($links);
    $link
      ->setText(t('Forms'));
  }
}