2017-06-26 23 views
0

現在、ドキュメントの更新を許可するフォームを作成しようとしています。ドキュメントには0-n個のdocumentLegがあり、各documentLegにはleadPassengerと0-nの乗客が含まれています。各脚の乗客は他の脚から分離されています。ここでコレクション内のサブコレクションは正しく表示されません。

は私のフォームクラスです。この後

class DocumentType extends AbstractResourceType 
{ 
    /** 
    * {@inheritdoc} 
    */ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder 
      ->add('currencyCode', TextType::class, ['label' => 'model.document.currency_code']) 
      ->add('reservationId', TextType::class, ['label' => 'model.document.reservation_id']) 
      ->add('sum', NumberType::class, ['label' => 'model.document.sum']) 
      ->add('tax', NumberType::class, ['label' => 'model.document.tax']) 
      ->add('tripFolder', TextType::class, ['label' => 'model.document.trip_folder']) 
      ->add('documentCustomer', DocumentCustomerType::class) 
      ->add('documentAdditionalServices', CollectionType::class, ['entry_type' => DocumentAdditionalServiceType::class]) 
      ->add('documentLegs', CollectionType::class, ['entry_type' => DocumentLegType::class]) 
     ; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function configureOptions(OptionsResolver $resolver) 
    { 
     parent::configureOptions($resolver); 
     $resolver->setDefault('translation_domain', 'document'); 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getBlockPrefix() 
    { 
     return 'oj_document'; 
    } 
} 

class DocumentLegType extends AbstractResourceType 
{ 
    /** 
    * {@inheritdoc} 
    */ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder 
      ->add('airportFromIata', TextType::class, ['label' => 'model.leg.airport_from_iata']) 
      ->add('airportFromIcao', TextType::class, ['label' => 'model.leg.airport_from_icao']) 
      ->add('airportFromName', TextType::class, ['label' => 'model.leg.airport_from_name']) 
      ->add('airportToIata', TextType::class, ['label' => 'model.leg.airport_to_iata']) 
      ->add('airportToIcao', TextType::class, ['label' => 'model.leg.airport_to_icao']) 
      ->add('airportToName', TextType::class, ['label' => 'model.leg.airport_to_name']) 
      ->add('cityFromName', TextType::class, ['label' => 'model.leg.city_from_name']) 
      ->add('cityToName', TextType::class, ['label' => 'model.leg.city_to_name']) 
      ->add('price', NumberType::class, ['label' => 'model.leg.price']) 
      ->add('publicPrice', NumberType::class, ['label' => 'model.leg.public_price']) 
      ->add('tax', NumberType::class, ['label' => 'model.leg.tax']) 
      ->add('startedAtUtc', DateTimePickerType::class, ['label' => 'model.leg.started_at_utc']) 
      ->add('endedAtUtc', DateTimePickerType::class, ['label' => 'model.leg.ended_at_utc']) 
      ->add('leadPassenger', DocumentCustomerType::class) 
      ->add('passengers', CollectionType::class, ['entry_type' => DocumentCustomerType::class]) 
     ; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function configureOptions(OptionsResolver $resolver) 
    { 
     parent::configureOptions($resolver); 
     $resolver->setDefault('translation_domain', 'document'); 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getBlockPrefix() 
    { 
     return 'oj_document_leg'; 
    } 
} 

class DocumentCustomerType extends AbstractResourceType 
{ 
    /** 
    * {@inheritdoc} 
    */ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder 
      ->add('address', TextType::class, ['label' => 'model.customer.address']) 
      ->add('city', TextType::class, ['label' => 'model.customer.city']) 
      ->add('company', TextType::class, ['label' => 'model.customer.company']) 
      ->add('country', TextType::class, ['label' => 'model.customer.country']) 
      ->add('firstname', TextType::class, ['label' => 'model.customer.firstname']) 
      ->add('gender', TextType::class, ['label' => 'model.customer.gender']) 
      ->add('lastname', TextType::class, ['label' => 'model.customer.lastname']) 
      ->add('postalCode', TextType::class, ['label' => 'model.customer.postal_code']) 
      ->add('email', EmailType::class, ['label' => 'model.customer.email']) 
      ->add('phone', TextType::class, ['label' => 'model.customer.phone']) 
      ->add('passportNumber', TextType::class, ['label' => 'model.customer.passport_number']) 
      ->add('birthdate', DatePickerType::class, ['label' => 'model.customer.birthdate']) 
      ->add('passportExpirationDate', DatePickerType::class, ['label' => 'model.customer.passport_expiration_date']) 
      ->add('nationality', TextType::class, ['label' => 'model.customer.nationality']) 
      ->add('honorific', TextType::class, ['label' => 'model.customer.honorific']) 
     ; 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function configureOptions(OptionsResolver $resolver) 
    { 
     parent::configureOptions($resolver); 
     $resolver->setDefault('translation_domain', 'document'); 
    } 

    /** 
    * {@inheritdoc} 
    */ 
    public function getBlockPrefix() 
    { 
     return 'oj_document_customer'; 
    } 
} 

、こちらのフォームテンプレートは、小枝を使用して、です:

{% form_theme form with [ 
':Form:horizontalLayout.html.twig', 
':Form:widgetHorizontal.html.twig', 
] %} 

{% trans_default_domain 'document' %} 

{{ set_globals({ 
    label_col : 3, 
    group_col : 9 
}) }} 

<div class="section section-heading"> 
    <h2>{{ 'model.section.document'|trans }}</h2> 
</div> 
<section> 
    {{ form_row(form.reservationId) }} 
    {{ form_row(form.tripFolder) }} 
    {{ form_row(form.currencyCode) }} 
    {{ form_row(form.sum) }} 
    {{ form_row(form.tax) }} 
</section> 
<div class="section section-heading"> 
    <h2>{{ 'model.section.document_customer'|trans }}</h2> 
</div> 
<section> 
    {{ form_widget(form.documentCustomer) }} 
</section> 
<div class="section section-heading"> 
    <h2>{{ 'model.section.additional_services'|trans }}</h2> 
</div> 
<section> 
    {% for service in form.documentAdditionalServices %} 
     <div>{{ loop.index }}</div> 
     {{ form_row(service.name) }} 
     {{ form_row(service.description) }} 
     {{ form_row(service.price) }} 
     {{ form_row(service.publicPrice) }} 
    {% endfor %} 
</section> 
<div class="section section-heading"> 
    <h2>{{ 'model.section.document_legs'|trans }}</h2> 
</div> 
<section> 
    <div class="panel-group" id="legAccordion" role="tablist" aria-multiselectable="true"> 
     {% for leg in form.documentLegs %} 
      <div class="panel panel-default"> 
       <div class="panel-heading" role="tab" id="headerLeg{{ loop.index }}"> 
        <h4 class="panel-title"> 
         <a role="button" data-toggle="collapse" data-parent="#legAccordion" href="#collapseLeg{{ loop.index }}" aria-expanded="true" aria-controls="#collapseLeg{{ loop.index }}"> 
          {{ 'model.accordion.leg_header'|trans({'%number%': loop.index}, 'document') }} 
         </a> 
        </h4> 
       </div> 
       <div id="collapseLeg{{ loop.index }}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headerLeg{{ loop.index }}"> 
        <div class="panel-body"> 
         {{ form_row(leg.airportFromName) }} 
         {{ form_row(leg.airportFromIcao) }} 
         {{ form_row(leg.airportFromIata) }} 
         {{ form_row(leg.airportToIata) }} 
         {{ form_row(leg.airportToIata) }} 
         {{ form_row(leg.airportToIata) }} 
         {{ form_row(leg.cityFromName) }} 
         {{ form_row(leg.cityToName) }} 
         {{ form_row(leg.price) }} 
         {{ form_row(leg.publicPrice) }} 
         {{ form_row(leg.tax) }} 
         {{ form_row(leg.startedAtUtc) }} 
         {{ form_row(leg.endedAtUtc) }} 
         <div class="panel-group" id="leadPaxAccordion" role="tablist" aria-multiselectable="true"> 
          <div class="panel panel-default"> 
           <div class="panel-heading" role="tab" id="headerLeadPax"> 
            <h4 class="panel-title"> 
             <a role="button" data-toggle="collapse" data-parent="#leadPaxAccordion" href="#collapseLeadPax" aria-expanded="true" aria-controls="#collapseLeadPax"> 
              {{ 'model.section.lead_passenger'|trans({}, 'document') }} 
             </a> 
            </h4> 
           </div> 
           <div id="collapseLeadPax" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headerLeadPax"> 
            <div class="panel-body"> 
             {{ form_row(leg.leadPassenger.firstname) }} 
             {{ form_row(leg.leadPassenger.lastname) }} 
             {{ form_row(leg.leadPassenger.company) }} 
             {{ form_row(leg.leadPassenger.address) }} 
             {{ form_row(leg.leadPassenger.city) }} 
             {{ form_row(leg.leadPassenger.postalCode) }} 
             {{ form_row(leg.leadPassenger.country) }} 
             {{ form_row(leg.leadPassenger.email) }} 
             {{ form_row(leg.leadPassenger.phone) }} 
             {{ form_row(leg.leadPassenger.passportNumber) }} 
             {{ form_row(leg.leadPassenger.passportExpirationDate) }} 
             {{ form_row(leg.leadPassenger.nationality) }} 
             {{ form_row(leg.leadPassenger.honorific) }} 
            </div> 
           </div> 
          </div> 
         </div> 
         <div class="panel-group" id="passengerAccordion" role="tablist" aria-multiselectable="true"> 
          {% for passenger in leg.passengers %} 
          <div class="panel panel-default"> 
           <div class="panel-heading" role="tab" id="headerPassenger{{ loop.index }}"> 
            <h4 class="panel-title"> 
             <a role="button" data-toggle="collapse" data-parent="#passengerAccordion" href="#collapsePassenger{{ loop.index }}" aria-expanded="true" aria-controls="#collapsePassenger{{ loop.index }}"> 
              {{ 'model.accordion.passenger'|trans({'%number%': loop.index}, 'document') }} 
             </a> 
            </h4> 
           </div> 
           <div id="collapsePassenger{{ loop.index }}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headerPassenger{{ loop.index }}"> 
            <div class="panel-body"> 
             {{ form_row(passenger.firstname) }} 
             {{ form_row(passenger.lastname) }} 
             {{ form_row(passenger.company) }} 
             {{ form_row(passenger.address) }} 
             {{ form_row(passenger.city) }} 
             {{ form_row(passenger.postalCode) }} 
             {{ form_row(passenger.country) }} 
             {{ form_row(passenger.email) }} 
             {{ form_row(passenger.phone) }} 
             {{ form_row(passenger.passportNumber) }} 
             {{ form_row(passenger.passportExpirationDate) }} 
             {{ form_row(passenger.nationality) }} 
             {{ form_row(passenger.honorific) }} 
            </div> 
           </div> 
          </div> 
          {% endfor %} 
         </div> 
        </div> 
       </div> 
      </div> 
     {% endfor %} 
    </div> 
</section> 

{{ form_row(form._token) }} 

さて、問題。私は2つのdocumentLegsがあると仮定しましょう。最初のdocumentLegには2人の乗客と1人のleadPassengerがあります。第2脚には3人の乗客と1人乗りのPassenger(第1脚とは異なる)があります。

私は2度の脚の中で、3人目の乗客にしか乗りません。先頭と2つは最初に生成されません。私は例として2を取ったが、それはnのために働く。

誰でも考えがある場合。前もって感謝します。

答えて

0

HTML表示の問題。崩壊のIDと競合する

関連する問題