return '/';
}
$prefix = '';
- $languageId = (int)$recordData[$GLOBALS['TCA'][$this->tableName]['ctrl']['languageField']];
if ($this->configuration['generatorOptions']['prefixParentPageSlug'] ?? false) {
+ $languageId = (int)$recordData[$GLOBALS['TCA'][$this->tableName]['ctrl']['languageField']];
$rootLine = BackendUtility::BEgetRootLine($pid, '', true, ['nav_title']);
$parentPageRecord = reset($rootLine);
if ($languageId > 0) {
}
}
$slug = implode($fieldSeparator, $slugParts);
+ $slug = $this->sanitize($slug);
+ // No valid data found
+ if ($slug === '/') {
+ $slug .= 'default-' . GeneralUtility::shortMD5(json_encode($recordData));
+ }
if (!empty($prefix)) {
- $slug = $prefix . '/' . $slug;
+ $slug = $prefix . $slug;
}
return $this->sanitize($slug);
$subject->sanitize($input)
);
}
+
+ public function generateNeverDeliversEmptySlugDataProvider()
+ {
+ return [
+ 'simple title' => [
+ 'Products',
+ '/products'
+ ],
+ 'title with spaces' => [
+ 'Product Cow',
+ '/product-cow'
+ ],
+ 'title with invalid characters' => [
+ 'Products - Cows',
+ '/products-cows'
+ ],
+ 'title with only invalid characters' => [
+ '!!!',
+ '/default-51cf35392c'
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider generateNeverDeliversEmptySlugDataProvider
+ * @param string $input
+ * @param string $expected
+ * @test
+ */
+ public function generateNeverDeliversEmptySlug(string $input, string $expected)
+ {
+ $GLOBALS['dummyTable']['ctrl'] = [];
+ $subject = new SlugHelper(
+ 'dummyTable',
+ 'dummyField',
+ ['generatorOptions' => ['fields' => ['title']]]
+ );
+ static::assertEquals(
+ $expected,
+ $subject->generate(['title' => $input, 'uid' => 13], 13)
+ );
+ }
}