簡體   English   中英

Sylius定制表單客戶

[英]Sylius Customizing Form Customer

我正在按照Sylius文檔上的教程自定義表單。

這是我所擁有的:

src \\ AppBundle \\ Form \\ Extension \\ 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 \\ Entity \\ 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 \\ Form \\ Extension \\ CustomerProfileTypeExtension標簽:-{名稱:form.type_extension,extended_type:Sylius \\ Bundle \\ CustomerBundle \\ Form \\ Type \\ CustomerProfileType}

app \\ Resources \\ SyliusShopBundle \\ views \\ Account \\ profileUpdate.html.twig

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

Sylius 1.0.4。

我的姓氏標簽中有“ app.form.customer.surname”。 但是我的字段“ contactHours”沒有出現...

任何想法 ? 我的“ app \\ Resources \\ SyliusShopBundle \\ views \\ Account \\ profileUpdate.html.twig”可以嗎?

我只是發現我應該將\\vendor\\sylius\\sylius\\src\\Sylius\\Bundle\\AdminBundle\\Resources\\views\\Customer\\_form.html.twigapp\\Resources\\SyliusAdminBundle\\views\\Customer\\_form.html.twig並然后根據我的需要進行修改。

這是我修改的代碼:

app\\Resources\\SyliusAdminBundle\\views\\Customer\\_form.html.twig

....
    <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>
....

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM