diff --git a/src/EasyBreadcrumbBuilder.php b/src/EasyBreadcrumbBuilder.php index 938ec2b..5ff3e29 100755 --- a/src/EasyBreadcrumbBuilder.php +++ b/src/EasyBreadcrumbBuilder.php @@ -306,11 +306,12 @@ class EasyBreadcrumbBuilder implements BreadcrumbBuilderInterface { // then check if the urls for any segments have matched group variables // (eg. $1 or $3) and if they do substitute them out for the the corresponding // matched strings. - if ($is_regex) { - foreach ($regex_match[1] as $group_num) { - if (isset($url_group_matches[0+$group_num])) { - $url = str_replace('$' . $group_num, urlencode($url_group_matches[0+$group_num]), $url); - } + if ($is_regex && sizeof($url_group_matches) > 1) { + // Discard first element as that's the full matched string + // rather than a captured group + array_shift($url_group_matches); + foreach ($url_group_matches as $group_num => $captured_str) { + $url = str_replace('$' . ($group_num + 1), urlencode($captured_str), $url); } } diff --git a/src/Form/EasyBreadcrumbGeneralSettingsForm.php b/src/Form/EasyBreadcrumbGeneralSettingsForm.php index 059befb..1b128f6 100644 --- a/src/Form/EasyBreadcrumbGeneralSettingsForm.php +++ b/src/Form/EasyBreadcrumbGeneralSettingsForm.php @@ -143,7 +143,7 @@ class EasyBreadcrumbGeneralSettingsForm extends ConfigFormBase { $details_advanced[EasyBreadcrumbConstants::CUSTOM_PATHS] = [ '#type' => 'textarea', '#title' => $this->t('Paths to replace with custom breadcrumbs'), - '#description' => $this->t('Enter a line separated list of internal paths followed by breadcrumb pattern. Separate crumbs from their path with a vertical bar ("|"). Separate crumbs with double-colon ("::"). Omit the URL to display an unlinked crumb. Fields will be trimmed to remove extra start/end spaces, so you can use them to help format your input, if desired. Replaced Titles will not be processed on custom paths. Excluded paths listed here will have breadcrumbs added. Examples (with and without extra spacing):
/news/archive/site_launched :: News | /news :: Archive | /news/archive :: Site Launched
/your/path::LinkedCrumb1|url1::LinkedCrumb2|url2::UnlinkedCrumb3

It is also possible to express the path to be matched as a regex expression:
/news/archive/\d{4} :: News | /news :: Archive | /news/archive

Expressions can even include matching groups which can be referenced in the path of a segment path:
/groups/([^/]*)/info :: Groups | /groups :: Group | /groups/$1

'), + '#description' => $this->t('Enter a line separated list of internal paths followed by breadcrumb pattern. Separate crumbs from their path with a vertical bar ("|"). Separate crumbs with double-colon ("::"). Omit the URL to display an unlinked crumb. Fields will be trimmed to remove extra start/end spaces, so you can use them to help format your input, if desired. Replaced Titles will not be processed on custom paths. Excluded paths listed here will have breadcrumbs added. Examples (with and without extra spacing):
/news/archive/site_launched :: News | /news :: Archive | /news/archive :: Site Launched
/your/path::LinkedCrumb1|url1::LinkedCrumb2|url2::UnlinkedCrumb3

It is also possible to express the path to be matched as a regex expression. "regex!" must be added to the start of the path to match in order for it to be interpreted as regex:
regex!/news/archive/\d{4} :: News | /news :: Archive | /news/archive

Expressions can even include matching groups which can be referenced in the path of a segment path:
regex!/groups/([^/]*)/info :: Groups | /groups :: Group | /groups/$1

'), '#default_value' => $custom_paths, ];