Skip to content

Commit

Permalink
adjust dca field changes for php 8
Browse files Browse the repository at this point in the history
  • Loading branch information
koertho committed Mar 1, 2024
1 parent a32b190 commit 57c518f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 42 deletions.
8 changes: 2 additions & 6 deletions src/Dca/AuthorField.php
Expand Up @@ -7,7 +7,7 @@ class AuthorField extends AbstractDcaField
public const TYPE_USER = 'user';
public const TYPE_MEMBER = 'member';

protected static $tables = [];
protected static array $tables = [];

/**
* @return array<AuthorFieldConfiguration>
Expand All @@ -17,11 +17,7 @@ public static function getRegistrations(): array
return parent::getRegistrations();
}

/**
* @param string $table
* @return AuthorFieldConfiguration
*/
protected static function createOptionObject(string $table): DcaFieldConfiguration
protected static function createOptionObject(string $table): DcaFieldConfiguration|AuthorFieldConfiguration
{
return new AuthorFieldConfiguration($table);
}
Expand Down
18 changes: 6 additions & 12 deletions src/Dca/AuthorFieldConfiguration.php
Expand Up @@ -4,18 +4,12 @@

class AuthorFieldConfiguration extends DcaFieldConfiguration
{
/** @var string */
protected $type = AuthorField::TYPE_USER;
/** @var string */
protected $fieldNamePrefix = '';
/** @var bool */
protected $useDefaultLabel = true;
/** @var bool */
protected $exclude = true;
/** @var bool */
protected $search = true;
/** @var bool */
protected $filter = true;
protected string $type = AuthorField::TYPE_USER;
protected string $fieldNamePrefix = '';
protected bool $useDefaultLabel = true;
protected bool $exclude = true;
protected bool $search = true;
protected bool $filter = true;

public function setType(string $type): AuthorFieldConfiguration
{
Expand Down
2 changes: 1 addition & 1 deletion src/Dca/DateAddedField.php
Expand Up @@ -4,7 +4,7 @@

class DateAddedField extends AbstractDcaField
{
private static $tables = [];
private static array $tables = [];

protected static function storeConfig(DcaFieldConfiguration $config): void
{
Expand Down
11 changes: 1 addition & 10 deletions src/Dca/DcaFieldConfiguration.php
Expand Up @@ -4,17 +4,8 @@

class DcaFieldConfiguration
{
/**
* @var string
*/
private $table;

/**
* @param string $table
*/
public function __construct(string $table)
public function __construct(private string $table)
{
$this->table = $table;
}

public function getTable(): string
Expand Down
7 changes: 2 additions & 5 deletions src/EventListener/DcaField/AbstractDcaFieldListener.php
Expand Up @@ -9,10 +9,7 @@

abstract class AbstractDcaFieldListener implements ServiceSubscriberInterface
{
/**
* @var ContainerInterface
*/
private $container;
private ContainerInterface $container;

protected function getModelInstance(string $table, int $id): ?Model
{
Expand All @@ -21,7 +18,7 @@ protected function getModelInstance(string $table, int $id): ?Model
return $framework->getAdapter($modelClass)->findByPk($id);
}

public static function getSubscribedServices()
public static function getSubscribedServices(): array
{
return [
'contao.framework' => ContaoFramework::class,
Expand Down
6 changes: 2 additions & 4 deletions src/EventListener/DcaField/DateAddedFieldListener.php
Expand Up @@ -2,15 +2,13 @@

namespace HeimrichHannot\UtilsBundle\EventListener\DcaField;

use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\DataContainer;
use HeimrichHannot\UtilsBundle\Dca\DateAddedField;

class DateAddedFieldListener extends AbstractDcaFieldListener
{
/**
* @Hook("loadDataContainer")
*/
#[AsHook("loadDataContainer")]
public function onLoadDataContainer(string $table): void
{
if (!isset(DateAddedField::getRegistrations()[$table])) {
Expand Down
6 changes: 2 additions & 4 deletions src/EventListener/DcaField/DcaAuthorListener.php
Expand Up @@ -3,8 +3,8 @@
namespace HeimrichHannot\UtilsBundle\EventListener\DcaField;

use Contao\BackendUser;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\DataContainer;
use Contao\FrontendUser;
use Contao\Model;
Expand All @@ -23,9 +23,7 @@ public function __construct(ContaoFramework $framework, Security $security)
$this->security = $security;
}

/**
* @Hook("loadDataContainer")
*/
#[AsHook("loadDataContainer")]
public function onLoadDataContainer(string $table): void
{
if (!isset(AuthorField::getRegistrations()[$table])) {
Expand Down

0 comments on commit 57c518f

Please sign in to comment.