1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Symfony 2.7.3 SonataAdmin 任意の画面のカスタマイズ

Last updated at Posted at 2018-07-05

サービスの定義に使うhtmlを明記

編集画面に表示要素を追加するとします

app/config/services.yml
  #
  # 管理画面 会員管理
  #
  sonata.admin.member:
    class: AppBundle\Admin\MemberAdmin
    tags:
      - { name: sonata.admin, manager_type: orm, group: "項目", label: "会員" }
    arguments:
      - ~
      - AppBundle\Entity\Member
      - ~
    calls:
      - [ setTranslationDomain, [AppBundle]]
      - [ setTemplate, [edit, admin/member/edit.html.twig]]

setTemplate で admin/member/edit.html.twig を定義

編集画面のhtmlを用意

app/Resources/views/admin/member/edit.html.twig
{% extends 'SonataAdminBundle:CRUD:base_edit.html.twig' %}

下記のファイルを参考に、必要に応じてブロックをオーバーライドする

vendor/sonata-project/admin-bundle/Resources/views/standard_layout.html.twig
vendor/sonata-project/admin-bundle/Resources/views/CRUD/base_edit.html.twig

サンプル

{% extends 'admin/base_edit.html.twig' %}

{% block form %}
{{ parent() }}
{% if admin.id(object) is not null %}
        <div class="col-md-12">
            <div class="box box-success">
                <div class="box-body">
                    <div class="sonata-ba-collapsed-fields">

                      <div class="form-group">
                        <label class="control-label">
                          年齢
                        </label>
                        <div class=" sonata-ba-field sonata-ba-field-standard-natural  ">
                          {{ object.age }}歳 ({{ object.birthday|date("Y年m月d日生まれ") }})
                        </div>
                      </div>

                      <div class="form-group">
                        <label class="control-label">
                          購入履歴
                        </label>

                        <div class="sonata-ba-field sonata-ba-field-standard-natural">
                          <table class="table table-bordered table-striped">
                            <thead>
                              <tr class="sonata-ba-list-field-header">
                                <th>注文番号</th>
                                <th>注文日時</th>
                                <th>売上金額</th>
                              </tr>
                            </thead>
                            <tbody>
                              {% for order in object.memberOrders %}
                              <tr>
                                <td><a href="{{ path('sonata_order_show', {'id': order.id}) }}">{{ order.orderId }}</a></td>
                                <td>{{ order.createdString}}</td>
                                <td>{{ order.totalString|raw }}</td>
                              </tr>
                              {% endfor %}
                            </tbody>
                          </table>
                        </div>
                      </div>
                    </div>
                </div>
            </div>
        </div>
{% endif %}
{% endblock %}

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?