2017-11-24 10 views
0

私は、フォームをカスタマイズするためにSyliusの文書に関するチュートリアルに従っています。ここでSyliusカスタマイゼーションフォームお客様

私が持っているものです。

SRC \ AppBundle \フォーム\拡張\ CustomerProfileTypeExtension.php:

<?php 

namespace AppBundle\Form\Extension; 

use Sylius\Bundle\CustomerBundle\Form\Type\CustomerProfileType; 
use Symfony\Component\Form\AbstractTypeExtension; 
use Symfony\Component\Form\Extension\Core\Type\TextType; 
use Symfony\Component\Form\FormBuilderInterface; 


final class CustomerProfileTypeExtension extends AbstractTypeExtension 
{ 
/** 
* {@inheritdoc} 
*/ 
public function buildForm(FormBuilderInterface $builder, array $options): void 
{ 
    // Adding new fields works just like in the parent form type. 
    $builder->add('contactHours', TextType::class, [ 
     'required' => false, 
     'label' => 'app.form.customer.contact_hours', 
    ]); 

    // To remove a field from a form simply call ->remove(`fieldName`). 
    // $builder->remove('gender'); 

    // You can change the label by adding again the same field with a changed `label` parameter. 
    $builder->add('lastName', TextType::class, [ 
     'label' => 'app.form.customer.surname', 
    ]); 
} 

/** 
* {@inheritdoc} 
*/ 
public function getExtendedType(): string 
{ 
    return CustomerProfileType::class; 
} 
} 

SRC \ AppBundle \エンティティ\ Customer.php:

<?php 

namespace AppBundle\Entity; 

use Sylius\Component\Core\Model\Customer as BaseCustomer; 

class Customer extends BaseCustomer 
{ 
/** 
* @var string|null 
*/ 
private $contactHours; 

/** 
* @return string 
*/ 
public function getContactHours(): ?string 
{ 
    return $this->contactHours; 
} 

/** 
* @param string $contactHours 
*/ 
public function setContactHours(?string $contactHours): void 
{ 
    $this->contactHours = $contactHours; 
} 
} 

AppBundle/Resources/config/services.yml: サービス: .... app.form.extension.type.customer_profile: クラス:AppBundle \フォーム\拡張\ CustomerProfileTypeExtension タグ: - {名:form.type_extension、extended_type:Sylius \バンドル\ CustomerBundle \フォーム\タイプ\ CustomerProfileType}リソース\ SyliusShopBundle \ビュー\

アプリ\アカウント\ profileUpdate.html.twig

<div class="two fields"> 
    <div class="field">{{ form_row(form.birthday) }}</div> 
    <div class="field">{{ form_row(form.contactHours) }}</div> 
</div> 

シリウス1.0.4。

姓のラベルに「app.form.customer.surname」と「Expected」と表示されています。 しかし、私のフィールド "contactHours"は表示されません...

ご存じですか? 私の "app \ Resources \ SyliusShopBundle \ views \ Account \ profileUpdate.html.twig"はどうですか?

答えて

2

私は、\ vendor \ sylius \ sylius \ src \ Sylius \ Bundle \ AdminBundle \ Resources \ views \ Customer_form.html.twigをapp \ Resources \ SyliusAdminBundle \ views \ Customer_form.html.twigにコピーし、私の必要に応じてそれを変更してください! ここに私の変更されたコードがあります。

アプリの\リソース\ SyliusAdminBundle

.... 
    <div class="ui segment"> 
     <h4 class="ui dividing header">{{ 'sylius.ui.extra_information'|trans }}</h4> 
     {{ form_row(form.contactHours) }} 
     {{ form_row(form.birthday) }} 
     {{ form_row(form.phoneNumber) }} 
     {{ form_row(form.subscribedToNewsletter) }} 
    </div> 
.... 
Customer_form.html.twig

\ビュー\
関連する問題