Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

エンティティからフォームを生成する機構の追加 #2268

Merged
merged 10 commits into from
Apr 17, 2017
46 changes: 46 additions & 0 deletions app/Acme/Controller/EntityFormController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
namespace Acme\Controller;

use Eccube\Application;
use Eccube\Entity\BaseInfo;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;

class EntityFormController
{
/**
* @Route("/entity-form")
*/
public function index(Application $app, Request $request)
{
$BaseInfo = new BaseInfo();

$builder = $app->form(
$BaseInfo,
[
'data_class' => BaseInfo::class,
]
);

$form = $builder->getForm();
$form->add('submit', SubmitType::class);

$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// do stuff.
}

$template = "
{{ form_start(form) }}
{{ form_row(form) }}
{{ form_end(form) }}
";

$params = ['form' => $form->createView()];

return $app['twig']
->createTemplate($template)
->render($params);
}
}
19 changes: 19 additions & 0 deletions app/Acme/Entity/BaseInfoTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Acme\Entity;

use Doctrine\ORM\Mapping as ORM;
use Eccube\Annotation\EntityExt;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @EntityExt(target="Eccube\Entity\BaseInfo")
*/
trait BaseInfoTrait
{
/**
* @ORM\Column(name="company_name_vn", type="string", length=255, nullable=true, options={"eccube_form_render":true})
* @Assert\NotBlank(message="にゅうりょくしてくださいね!!!")
*/
public $company_name_vn;
}
18 changes: 18 additions & 0 deletions app/Acme/Entity/DbTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Acme\Entity;

use Doctrine\ORM\Mapping as ORM;
use Eccube\Annotation as Eccube;

/**
* @Eccube\EntityExtension("Eccube\Entity\Product")
*/
trait DbTrait
{
/**
* @ORM\ManyToOne(targetEntity="\Eccube\Entity\Master\Db")
* @ORM\JoinColumn(name="database_id", referencedColumnName="id")
*/
public $DataBase;
}
22 changes: 22 additions & 0 deletions app/Acme/Entity/MakerTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Acme\Entity;

use Doctrine\ORM\Mapping as ORM;
use Eccube\Annotation as Eccube;

/**
* @Eccube\EntityExtension("Eccube\Entity\Product")
*/
trait MakerTrait
{
/**
* @ORM\Column(type="string", nullable=true)
*/
public $maker_name;

/**
* @ORM\Column(type="string", nullable=true)
*/
public $maker_url;
}
2 changes: 1 addition & 1 deletion app/Acme/Entity/SoldOutEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Eccube\Entity\Event\Annotations\PreUpdate;
use Eccube\Annotation\PreUpdate;
use Eccube\Entity\Event\EntityEventListener;
use Eccube\Entity\ProductStock;

Expand Down
1 change: 1 addition & 0 deletions app/console
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ $console->add(new Eccube\Command\RouterCommand());
$console->add(new Eccube\Command\CacheClearCommand());
$console->add(new Eccube\Command\PluginCommand());
$console->add(new Eccube\Command\ConfigCommand());
$console->add(new Eccube\Command\GenerateProxyCommand());

$console->run();
Empty file added app/proxy/entity/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions cli-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

require_once __DIR__.'/autoload.php';

use Doctrine\ORM\Tools\Console\ConsoleRunner;

$app = \Eccube\Application::getInstance();
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"guzzlehttp/guzzle": "^6.2",
"symfony/event-dispatcher": ">=2.7,<3.3",
"mobiledetect/mobiledetectlib": "~2",
"doctrine/data-fixtures": "~1.1"
"doctrine/data-fixtures": "~1.1",
"saxulum/saxulum-validator-provider": "^2.1"
},
"require-dev": {
"phpunit/phpunit": "4.8.*",
Expand All @@ -77,6 +78,7 @@
"autoload": {
"files": [ "src/Eccube/Resource/functions/log.php" ],
"psr-4": {
"Eccube\\Entity\\": "app/proxy/entity",
"Eccube\\": "src/Eccube",
"Acme\\": "app/Acme",
"Plugin\\": "app/Plugin",
Expand Down
Loading