fix: eBay config CRUD — override createEntity() for required constructor args
Some checks are pending
CI / test (push) Waiting to run
Some checks are pending
CI / test (push) Waiting to run
EasyAdmin calls new ArticleTypePlatformConfig() with no args. Fix: - Add setArticleType() setter to the entity - Override createEntity() in the CRUD controller to inject the eBay Platform and first available ArticleType as placeholder (form overwrites both) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
36e7d02539
commit
40834a8bd6
2 changed files with 26 additions and 1 deletions
|
|
@ -65,6 +65,11 @@ class ArticleTypePlatformConfig
|
|||
return $this->articleType;
|
||||
}
|
||||
|
||||
public function setArticleType(ArticleType $articleType): void
|
||||
{
|
||||
$this->articleType = $articleType;
|
||||
}
|
||||
|
||||
public function getPlatform(): Platform
|
||||
{
|
||||
return $this->platform;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Infrastructure\Http\Controller\Admin;
|
||||
|
||||
use App\Domain\Article\Repository\ArticleTypeRepositoryInterface;
|
||||
use App\Domain\Channel\ArticleTypePlatformConfig;
|
||||
use App\Domain\Channel\Repository\PlatformRepositoryInterface;
|
||||
use App\Infrastructure\Channel\Ebay\EbayPolicyProvider;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
|
||||
|
|
@ -21,8 +23,26 @@ use EasyCorp\Bundle\EasyAdminBundle\Orm\EntityRepository;
|
|||
/** @extends AbstractCrudController<ArticleTypePlatformConfig> */
|
||||
final class EbayArticleTypePlatformConfigCrudController extends AbstractCrudController
|
||||
{
|
||||
public function __construct(private readonly EbayPolicyProvider $policyProvider)
|
||||
public function __construct(
|
||||
private readonly EbayPolicyProvider $policyProvider,
|
||||
private readonly PlatformRepositoryInterface $platformRepository,
|
||||
private readonly ArticleTypeRepositoryInterface $articleTypeRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function createEntity(string $entityFqcn): ArticleTypePlatformConfig
|
||||
{
|
||||
$platform = $this->platformRepository->findByType('ebay');
|
||||
if (null === $platform) {
|
||||
throw new \RuntimeException('eBay-Platform nicht in der Datenbank konfiguriert. Bitte zuerst eine Platform mit type="ebay" anlegen.');
|
||||
}
|
||||
|
||||
$articleTypes = $this->articleTypeRepository->findAll();
|
||||
if ([] === $articleTypes) {
|
||||
throw new \RuntimeException('Kein Artikeltyp vorhanden. Bitte zuerst einen Artikeltyp anlegen.');
|
||||
}
|
||||
|
||||
return new ArticleTypePlatformConfig($articleTypes[0], $platform, '');
|
||||
}
|
||||
|
||||
public static function getEntityFqcn(): string
|
||||
|
|
|
|||
Loading…
Reference in a new issue