Skip to content

Commit

Permalink
Merge pull request EC-CUBE#158 from chihiro-adachi/id-type-string
Browse files Browse the repository at this point in the history
ID型に対応
  • Loading branch information
kiy0taka authored Sep 19, 2023
2 parents 9e0f4f6 + c9dabf2 commit b3730ac
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Form/Type/Front/AddCartType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Eccube\Form\Type\AbstractType;
use Eccube\Repository\ProductClassRepository;
use Eccube\Validator\Constraints as Assert;
use Plugin\Api42\Form\Type\IdType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;

class AddCartType extends AbstractType
Expand All @@ -48,7 +49,7 @@ public function __construct(ProductClassRepository $productClassRepository, Eccu
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('product_class_id', IntegerType::class, [
->add('product_class_id', IdType::class, [
'constraints' => [
new Assert\NotBlank(),
new Assert\Regex(['pattern' => '/^\d+$/']),
Expand Down
20 changes: 20 additions & 0 deletions Form/Type/IdType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api42\Form\Type;

use Symfony\Component\Form\Extension\Core\Type\TextType;

class IdType extends TextType
{
}
7 changes: 6 additions & 1 deletion GraphQL/Mutation/AbstractMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use Plugin\Api42\Form\Type\IdType;
use Plugin\Api42\GraphQL\Error\FormValidationException;
use Plugin\Api42\GraphQL\Error\Info;
use Plugin\Api42\GraphQL\Error\Warning;
Expand Down Expand Up @@ -81,6 +82,7 @@ protected function convertArgs(FormInterface $form, array &$args = []): void
RepeatedEmailType::class,
RepeatedPasswordType::class,
IntegerType::class,
IdType::class,
];
$innerType = $formConfig->getType()->getInnerType();

Expand All @@ -96,9 +98,12 @@ protected function convertArgs(FormInterface $form, array &$args = []): void
if (in_array($typeClass, $innerTypes) || count($form) === 0) {
$type = Type::string();
if ($innerType->getParent() === MasterType::class) {
$type = Type::int();
$type = Type::Id();
}
switch ($typeClass) {
case IdType::class:
$type = Type::id();
break;
case IntegerType::class:
$type = Type::int();
break;
Expand Down

0 comments on commit b3730ac

Please sign in to comment.