Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
exclude:
- php: 8.1
contao: 5.6.*
- php: 8.4
contao: 4.13.*


steps:
Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@
"ext-simplexml": "*",
"php": "^8.1",
"contao/core-bundle": "^4.13 || ^5.0",
"doctrine/dbal": "^2.13 || ^3.0",
"doctrine/dbal": "^3.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"symfony/config": "^5.4 || ^6.0",
"symfony/config": "^5.4 || ^6.0 || ^7.0",
"symfony/event-dispatcher-contracts": "^1.0 || ^2.0 || ^3.0",
"symfony/filesystem": "^5.4 || ^6.0",
"symfony/http-foundation": "^5.4 || ^6.0",
"symfony/http-kernel": "^5.4 || ^6.0",
"symfony/string": "^5.2 || ^6.0",
"symfony/filesystem": "^5.4 || ^6.0 || ^7.0",
"symfony/http-foundation": "^5.4 || ^6.0 || ^7.0",
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0",
"symfony/string": "^5.2 || ^6.0 || ^7.0",
"twig/twig": "^3.0"
},
"require-dev": {
"contao/manager-plugin": "^2.0",
"contao/news-bundle": "^4.13 || ^5.0",
"contao/test-case": "^4.13 || ^5.0",
"heimrichhannot/contao-test-utilities-bundle": "^0.1",
"phpunit/phpunit": "^9.0 || ^10.0 || ^11.0",
"php-coveralls/php-coveralls": "^2.0",
"symfony/phpunit-bridge": "^5.4 || ^6.0 || ^7.0",
"phpstan/phpstan": "^1.10 || ^2.0",
"phpstan/phpstan-symfony": "^1.2 || ^2.0",
"rector/rector": "^1.2 || ^2.0",
"rector/rector": "^1.2 || ^2.3.3",
"contao/contao-rector": "dev-main"
},
"autoload": {
Expand Down
25 changes: 21 additions & 4 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,45 @@
use Contao\Rector\Set\ContaoLevelSetList;
use Contao\Rector\Set\ContaoSetList;
use Rector\Config\RectorConfig;
use Rector\Php81\Rector\Array_\ArrayToFirstClassCallableRector;
use Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
])
->withPhpVersion(\Rector\ValueObject\PhpVersion::PHP_84)
->withPhpVersion(PhpVersion::PHP_84)
->withRules([
AddVoidReturnTypeWhereNoReturnRector::class,
# In Vorbereitung für PHP 8.4:
ExplicitNullableParamTypeRector::class
])

->withImportNames(importShortClasses: false, removeUnusedImports: true)
->withComposerBased(symfony: true)
->withImportNames(
importShortClasses: false,
removeUnusedImports: true,
)
->withComposerBased(
twig: true,
doctrine: true,
phpunit: true,
symfony: true,
)
->withSets([
LevelSetList::UP_TO_PHP_81,
# Erst mit Symfony 6 (Contao 5) nutzen:
// SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
ContaoLevelSetList::UP_TO_CONTAO_413,
ContaoSetList::FQCN,
ContaoSetList::ANNOTATIONS_TO_ATTRIBUTES,
]);
])
->withSkip([
ArrayToFirstClassCallableRector::class,
])



;
43 changes: 40 additions & 3 deletions src/Dca/AliasFieldConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,46 @@

class AliasFieldConfiguration extends DcaFieldConfiguration
{
/**
* @internal
* @deprecated
*/
public ?array $aliasExistCallback = [AliasDcaFieldListener::class, 'onFieldsAliasSaveCallback'];

/**
* @internal
*/
public string $fieldName = 'alias';

/**
* Override the default alias exist function. Provide as [Class, 'method'].
*
* @internal
*/
public string $titleField = 'title';

/**
* @internal
*/
public ?array $generateAliasCallback = [AliasDcaFieldListener::class, 'onFieldsAliasSaveCallback'];

/**
* @param array<string, string> $aliasExistCallback
* @deprecated Deprecated since version 3.10. Use setGenerateAliasCallback instead.
* @codeCoverageIgnore
*/
public function setAliasExistCallback(?array $aliasExistCallback): AliasFieldConfiguration
{
$this->aliasExistCallback = $aliasExistCallback;
$this->generateAliasCallback = $aliasExistCallback;
return $this;
}

/**
* Override the default alias generation function. Provide as [Class, 'method'].
*
* @param array<string, string> $callback
*/
public function setGenerateAliasCallback(?array $callback): AliasFieldConfiguration
{
$this->generateAliasCallback = $callback;
return $this;
}

Expand All @@ -26,4 +54,13 @@ public function setFieldName(string $fieldName): AliasFieldConfiguration
$this->fieldName = $fieldName;
return $this;
}

/**
* Set the field name from which the alias should be generated.
*/
public function setTitleField(string $titleField): AliasFieldConfiguration
{
$this->titleField = $titleField;
return $this;
}
}
2 changes: 1 addition & 1 deletion src/EntityFinder/EntityFinderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@ public function setRow(array $arrData)
}
};
}
}
}
1 change: 0 additions & 1 deletion src/EntityFinder/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ private function news(int $id): ?Element
NewsModel::getTable(),
'News ' . $model->headline . ' (ID: ' . $model->id . ')',
(function () use ($model): \Generator {
/* @phpstan-ignore class.notFound */
yield ['table' => NewsArchiveModel::getTable(), 'id' => $model->pid];
})()
);
Expand Down
27 changes: 20 additions & 7 deletions src/EventListener/DcaField/AliasDcaFieldListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function onLoadDataContainer(string $table): void
$registration = AliasField::getRegistrations()[$table];

$field = AliasField::getField();
if (is_array($registration->aliasExistCallback)) {
$field['save_callback'][] = $registration->aliasExistCallback;
if (is_array($registration->generateAliasCallback)) {
$field['save_callback'][] = $registration->generateAliasCallback;
}

$this->applyDefaultFieldAdjustments($field, $registration);
Expand All @@ -40,16 +40,29 @@ public function onFieldsAliasSaveCallback($value, DataContainer $dc)
->execute($alias, $dc->id)
->numRows > 0);

if (method_exists($dc, 'getCurrentRecord')) {
$row = $dc->getCurrentRecord();
} else {
/**
* Contao 4 fallback
* @todo Remove when contao 5 only
* @phpstan-ignore property.notFound
*/
$row = $dc->activeRecord?->row() ?? [];
}

// Generate an alias if there is none
if (!$value) {
/** @var ?AliasFieldConfiguration $fieldConfiguration */
$fieldConfiguration = AliasField::getRegistrations()[$dc->table] ?? null;
$titleField = $fieldConfiguration?->titleField ?? 'title';

$value = $this->container->get('contao.slug')->generate(
/** @phpstan-ignore property.notFound */
(string)$dc->activeRecord->title,
/** @phpstan-ignore property.notFound */
(int)$dc->activeRecord->pid,
(string)$row[$titleField] ?? '',
(int)$row['pid'],
$aliasExists
);
} elseif (preg_match('/^[1-9]\d*$/', (string) $value)) {
} elseif (preg_match('/^[1-9]\d*$/', (string)$value)) {
throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasNumeric'], $value));
} elseif ($aliasExists($value)) {
throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $value));
Expand Down
2 changes: 0 additions & 2 deletions src/Util/UserUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
use Contao\Model\Collection;
use Contao\StringUtil;
use Contao\UserModel;
use HeimrichHannot\UtilsBundle\Util\DatabaseUtil;
use HeimrichHannot\UtilsBundle\Util\ModelUtil;
use HeimrichHannot\UtilsBundle\Util\UserUtil\UserType;

class UserUtil
Expand Down
Loading