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

3.1拡張機能のプラグインサンプルを追加 #2357

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) 2000-2017 LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

namespace Plugin\AnnotatedRouting\Controller;
use Eccube\Application;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

/**
* @Route("/arc")
*/
class AnnotatedRoutingController
{
/**
* @Route("/")
* @Template("AnnotatedRouting/Resource/template/index.twig")
*/
public function index(Application $app)
{
return [];
}

/**
* @Route("/form")
* @Method("GET")
* @Template("AnnotatedRouting/Resource/template/form.twig")
*/
public function form(Application $app)
{
return [];
}

/**
* @Route("/form")
* @Method("POST")
*/
public function submit(Application $app)
{
return 'Hello, '.$_REQUEST['value'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kiy0taka
$_REQUESTではなくsubmit(Application $app, Request $request)でパラメータ受け取ったほうがよいですね。のちほど修正しておきます。

}
}
4 changes: 4 additions & 0 deletions app/Plugin/AnnotatedRouting/Resource/template/form.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<form method="post">
<input type="text" name="value" />
<button type="submit">Submit</button>
</form>
1 change: 1 addition & 0 deletions app/Plugin/AnnotatedRouting/Resource/template/index.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>index</h1>
39 changes: 39 additions & 0 deletions app/Plugin/EntityExtension/Entity/CustomerRankTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) 2000-2017 LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/


namespace Plugin\EntityExtension\Entity;

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

/**
* @EntityExtension("Eccube\Entity\Customer")
*/
trait CustomerRankTrait
{
/**
* @ORM\Column(type="smallint", nullable=true)
*/
public $rank;
}
3 changes: 3 additions & 0 deletions app/Plugin/EntityExtension/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: エンティティ拡張機能のサンプル
code: EntityExtension
version: 1.0.0
40 changes: 40 additions & 0 deletions app/Plugin/EntityForm/Entity/ProductUrlTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) 2000-2017 LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

namespace Plugin\EntityForm\Entity;

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

/**
* @EntityExtension("Eccube\Entity\Product")
*/
trait ProductUrlTrait
{
/**
* @ORM\Column(type="string", nullable=true, options={ "eccube_form_options": { "auto_render": true, "form_theme": "EntityForm/Form/product_url.twig" } })
* @Assert\Url(message="外部の商品ページURLを入力してください。")
*/
public $url;
}
5 changes: 5 additions & 0 deletions app/Plugin/EntityForm/Form/product_url.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{%- extends 'Form/bootstrap_3_horizontal_layout.html.twig' -%}

{%- block _admin_product_url_label -%}
{{ form_label(form, '商品URL') }}
{%- endblock _admin_product_url_label -%}
3 changes: 3 additions & 0 deletions app/Plugin/EntityForm/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: エンティティからフォームを生成する機構のサンプル
code: EntityForm
version: 1.0.0
40 changes: 40 additions & 0 deletions app/Plugin/TwigUserFunc/Controller/TwigUserFuncController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) 2000-2017 LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

namespace Plugin\TwigUserFunc\Controller;

use Eccube\Application;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class TwigUserFuncController
{
/**
* @Route("/twiguserfunc")
*/
public function index(Application $app)
{
return $app['twig']
->createTemplate("{{ eccube_block_hello({'name':'EC-CUBE'}) }}")
->render([]);
}
}
3 changes: 3 additions & 0 deletions app/Plugin/TwigUserFunc/Resource/template/hello_block.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% block hello %}
<h1>Hello, {{ name }}!</h1>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) 2000-2017 LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

namespace Plugin\TwigUserFunc\ServiceProvider;


use Pimple\Container;
use Pimple\ServiceProviderInterface;

class TwigUserFuncServiceProvider implements ServiceProviderInterface
{
public function register(Container $app)
{
$app->extend('eccube.twig.block.templates', function($templates) {
$templates[] = 'TwigUserFunc/Resource/template/hello_block.twig';
return $templates;
});
}
}
5 changes: 5 additions & 0 deletions app/Plugin/TwigUserFunc/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: Twigユーザ定義関数のサンプル
code: TwigUserFunc
version: 1.0.0
service:
- TwigUserFuncServiceProvider
1 change: 1 addition & 0 deletions src/Eccube/Command/GenerateProxyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
->in(
[
$app['config']['root_dir'].'/app/Acme/Entity',
$app['config']['root_dir'].'/app/Plugin/*/Entity',
]
)
->name('*.php')
Expand Down
12 changes: 12 additions & 0 deletions src/Eccube/Resource/template/admin/Product/product.twig
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,18 @@ function fnClass(action) {
{% endfor %}
</div>

{# エンティティ拡張の自動出力 #}
{% for f in form %}
{# auto_render有効時に出力 #}
{% if f.vars.eccube_form_options.auto_render %}
{# form_themeが設定されている場合にthemeを適用 #}
{% if f.vars.eccube_form_options.form_theme %}
{% form_theme f f.vars.eccube_form_options.form_theme %}
{% endif %}
{{ form_row(f) }}
{% endif %}
{% endfor %}

</div><!-- /.box-body -->
</div><!-- /.box -->

Expand Down