Skip to content

Instantly share code, notes, and snippets.

@monishdeb
Last active November 20, 2018 11:06
Show Gist options
  • Save monishdeb/a59abadd7b12bec138c9ea8d2adf442e to your computer and use it in GitHub Desktop.
Save monishdeb/a59abadd7b12bec138c9ea8d2adf442e to your computer and use it in GitHub Desktop.

Before explaining the issue why breadcrumb is incomplete accross various Civi forms, let me explain the algorithm how the Civi Breadcrum is built for each link.

Code

https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Menu.php#L548L585

Algorithm

1. foreach ($paths as path) 
2. $pathElements = explode('/', $path)  // say $path = civicrm/contribute/add
3.  array_pop($pathElements); // here to exclude current page from breadcrumb

4. $currentPath = NULL;
5.  // iterate through each sub path and check if the sub path has title and url
  5.1 while ($newPath = array_shift($pathElements)) {
    5.2 $currentPath = $currentPath ? ($currentPath . '/' . $newPath) : $newPath; 
    // say at second iteration $currentpath is 'civicrm/contribute'

    // add to crumb array, if current-path's title exists in list of paths
    5.3 if (array_key_exists($currentPath, $paths) && isset($menu[$currentPath]['title'])) {
      $crumbs[] = array(
        'title' => $paths[$currentPath]['title'],
        'url' => $paths[$currentPath]['url'],
      );
     }
   }
6.  $paths[$path]['breadcrumb'] = $crumbs;
7. } // end of foreach loop

Bugs

Currently some pages show incomplete breadcrumb because it might be two case which are:

  1. Missing breadcrumb : For particular sub-path (as in step 5.2) there is no title present, hence the breadcrumb for that sub path din't got added in the sequence. e.g. 'New Student' - https://dmaster.demo.civicrm.org/civicrm/contact/add?ct=Individual&cst=Student&reset=1 Here the url path is 'civicrm/contact/add' and as per code there should be Home(/) >> CiviCRM(/civicrm) >> Contact Dashboard (civicrm/contact) but currently it shows Home >> CiviCRM as no url -'civicrm/contact' exist in the list of path.

Fix : Register a url 'civicrm/contact' with title 'Contact Dashboard' (i.e. https://dmaster.demo.civicrm.org/civicrm/user?reset=1&id=203&cid=203) Similarly we need to register the missing sub-url in CiviCRM for other urls which has missing breadcrumb(s)

  1. Incorrect breadcrumb(s) : It might be the case that sometime wrong breadcrumb is appended. Let me explain with an example - say 'Manage Contribution Pages' whose url is 'civicrm/admin/contribute' and currently Civi translates its breadcrumb as "Home >> CiviCRM >> Administer CiviCRM" where it should be 'Home >> CiviCRM >> CiviContribute Dashboard'. This because there is a sub-path 'civicrm/admin' whose title is 'CiviCRM Administer'.

Fix : Change the url to 'civicrm/contribute/admin' from 'civicrm/admin/contribute'

NOTE: I think its ok to exclude the breadcrumb of current page (as in step 3) because this is how other CMSs render their breadcrumbs.

Core Fix

  1. Register missing sub-url in CRM/Core/xml/Menu/Core.xml
  2. Correct the url by arranging the menu subparts in correct order as mentioned in Bugs#2/Fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment