開発環境[EC-CUBE] 4.0.5
[レンタルサーバ] Xserver
[OS]
[PHP] PHP7.4
[データベース] MySQL
[WEBサーバ]
[ブラウザ] Chrome
要件EC-CUBE4でお届け先情報に、性別の選択を作るためにラジオボタンを設定したいのですが、理由の分からないエラーが発生して困っています。
発生しているエラーフロント側の「お届け先の追加」画面です。
https://hoge.com/shopping/shipping_edit/4[Syntax Error] Expected PlainValue, got '�' at position 309 in property Eccube\Entity\CustomerAddress::$gender.文字化けは、このままでエラー表示されています。
ソースコード/app/Customize/Entity/CustomerAddressTrait.php
namespace Customize\Entity;
use Doctrine\ORM\Mapping as ORM;
use Eccube\Annotation\EntityExtension;
use Eccube\Entity\Shipping;
/**
* @EntityExtension("Eccube\Entity\CustomerAddress")
*/
trait CustomerAddressTrait
{
/**
* @var string|null
* @ORM\Column(type="string", length=2, nullable=true)
* @Eccube\Annotation\FormAppend(
* auto_render=false,
* type="\Symfony\Component\Form\Extension\Core\Type\TextType",
* options={
* "required": false,
* "label": "年齢",
* "attr": {"placeholder": "20"}
* })
*/
private $age;
/**
* Set birth.
*
* @param string|null $birth
*
* @return Shipping
*/
public function setAge($birth = null)
{
$this->age = $birth;
return $this;
}
/**
* Get birth.
*
* @return string|null
*/
public function getAge()
{
return $this->age;
}
/**
* @var string|null
* @ORM\Column(type="string", length=14, nullable=true)
* @Eccube\Annotation\FormAppend(
* auto_render=false,
* type="\Symfony\Component\Form\Extension\Core\Type\TextType",
* options={
* "required": false,
* "label": "携帯電話番号",
* "attr": {"placeholder": "例:09000000000"}
* })
*/
private $mobile_number;
/**
* @return string|null
*/
public function getMobileNumber()
{
return $this->mobile_number;
}
/**
* @param string|null $mobile_number
*/
public function setMobileNumber($mobile_number)
{
$this->mobile_number = $mobile_number;
return $this;
}
/**
* @var string|null
* @ORM\Column(type="string", nullable=true)
* @Eccube\Annotation\FormAppend(
* auto_render=false,
* type="\Symfony\Component\Form\Extension\Core\Type\ChoiceType",
* options={
* "required": true,
* "label": "性別",
* "expanded": true,
* "multiple": false,
* "choices":{
* "男" : "男",
* "女" : "女",
* "選択しない" : "選択しない"
* },
* })
*/
private $gender;
/**
* @return string|null
*/
public function getGender()
{
return $this->gender;
}
/**
* @param string|null $gender
*/
public function setGender($gender)
{
$this->gender = $gender;
return $this;
}
}
問題の箇所options の expanded を削除すると、エラーが表示されなくなります。
ただ expanded が無いとセレクトボックスで表示されてしまいます。
/**
* @var string|null
* @ORM\Column(type="string", nullable=true)
* @Eccube\Annotation\FormAppend(
* auto_render=false,
* type="\Symfony\Component\Form\Extension\Core\Type\ChoiceType",
* options={
* "required": true,
* "label": "性別",
* "expanded": true, ←これを削除すると表示される
* "multiple": false,
* "choices":{
* "男" : "男",
* "女" : "女",
* "選択しない" : "選択しない"
* },
* })
*/
参考Entityのカスタマイズ
https://doc4.ec-cube.net/customize_entityChoiceType Field (select drop-downs, radio buttons & checkboxes)
https://symfony.com/doc/current/reference/forms/types/choice.html