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

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

Merged
merged 11 commits into from
May 18, 2017

Conversation

chihiro-adachi
Copy link
Contributor

概要(Overview・Refs Issue)

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

#2268 のTODO(twigへの自動出力)対応です。

方針(Policy)

  • 拡張機構で、簡単にフォーム生成を行うことを想定
  • 本体側でのFormTypeは現状通り

実装に関する補足(Appendix)

Acme/Entity/CustomerTrait.php

/**
 * @EntityExtension("Eccube\Entity\Customer")
 */
trait CustomerTrait
{
    /**
     * @ORM\Column(
     *     name="company_name_vn",
     *     type="string",
     *     length=255,
     *     nullable=true,
     *     options={
     *          "eccube_form_options": {
     *              "auto_render": true,
     *              "form_theme": "Form/company_name_vn.twig"
     *          }
     *     })
     * @Assert\NotBlank(message="入力してくださいね!!!"
     */
    public $company_name_vn;
}

設定

@Orm\Columnのoptionsにeccube_form_optionsを定義する(#2268 から変更しています)

  • auto_render: true時、自動生成対象
  • form_theme: 出力項目に使用するform_theme

form_theme

出力時のform_themeを設定することができます。
自動出力は、標準のform_themeを利用して出力するため、これで細かな調整を行う事ができます。

app/template/Form/company_name_vn.twig

{%- extends 'Form/form_div_layout.twig' -%}

{%- block _entry_company_name_vn_row -%}
    <dl>
        <dt>
            {{ form_label(form, '会社名(VN)', {'label_attr': {'class': 'ec-label'}}) }}
        </dt>
        <dd>
            {# 確認画面での表示 #}
            {% if type is defined and type == 'hidden' %}
                {{ form.vars.data }}
                {{ form_widget(form, {type: 'hidden'}) }}
            {% else %}
                {# 入力画面での表示 #}
                <div class="ec-select{{ has_errors(form) ? ' error' }}">
                    {{ form_widget(form) }}
                    {{ form_errors(form) }}
                </div>
            {% endif %}
        </dd>
    </dl>
{%- endblock _entry_company_name_vn_row -%}

備考

#2318 に継続しています。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants