diff --git a/contao/dca/tl_news_category.php b/contao/dca/tl_news_category.php index 635fe34..3bbfd05 100644 --- a/contao/dca/tl_news_category.php +++ b/contao/dca/tl_news_category.php @@ -101,8 +101,8 @@ 'inputType' => 'text', 'eval' => [ 'rgxp' => 'alias', - 'unique' => true, - 'spaceToUnderscore' => true, + 'doNotCopy'=>true, + 'alwaysSave' => true, 'maxlength' => 128, 'tl_class' => 'w50', ], diff --git a/src/EventListener/DataContainer/NewsCategoryAliasListener.php b/src/EventListener/DataContainer/NewsCategoryAliasListener.php index 7130dda..2c2d3e3 100644 --- a/src/EventListener/DataContainer/NewsCategoryAliasListener.php +++ b/src/EventListener/DataContainer/NewsCategoryAliasListener.php @@ -40,13 +40,13 @@ public function validateAlias(string $value, DataContainer $dc): string #[AsCallback('tl_news_category', 'config.onbeforesubmit')] public function generateAlias(array $values, DataContainer $dc): array { - if (!isset($values['alias']) || '' !== $values['alias']) { - return $values; - } - $currentRecord = $dc->getCurrentRecord(); $title = $values['frontendTitle'] ?? $currentRecord['frontendTitle'] ?: ($values['title'] ?? $currentRecord['title']); + if ('' !== ($values['alias'] ?? $currentRecord['alias'] ?? '')) { + return $values; + } + $slugOptions = []; if (!empty($validChars = Config::get('news_categorySlugSetting'))) { @@ -70,12 +70,16 @@ public function generateAlias(array $values, DataContainer $dc): array private function aliasExists(string $value, DataContainer $dc): bool { - $query = "SELECT id FROM {$dc->table} WHERE alias=? AND id!=?"; - $params = [$value, $dc->id]; + $query = "SELECT id FROM {$dc->table} WHERE alias=?"; + $params = [$value]; - if ($dc instanceof Driver) { - $query .= " AND {$dc->getLanguageColumn()}=?"; + if ($dc instanceof Driver && '' !== $dc->getCurrentLanguage()) { + $query .= " AND pid!=? AND {$dc->getLanguageColumn()}=?"; + $params[] = $dc->id; $params[] = $dc->getCurrentLanguage(); + } else { + $query .= ' AND id!=?'; + $params[] = $dc->id; } return false !== $this->db->fetchOne($query, $params);