Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ProductTrait
<?php
/**
* This file is part of Customize
*
* Copyright(c) Akira Kurozumi <info@a-zumi.net>
*
* https://a-zumi.net
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Entity;
use Doctrine\ORM\Mapping as ORM;
use Eccube\Annotation\EntityExtension;
use Eccube\Annotation\FormAppend;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
/**
* Trait ProductTrait
* @package Customize\Entity
*
* @EntityExtension("Eccube\Entity\Product")
*/
trait ProductTrait
{
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
/**
* ここでslugのユニークチェック
*/
$metadata->addConstraint(new UniqueEntity([
'fields' => 'slug'
]));
}
/**
* 商品編集ページでスラッグを編集できるようにFormAppendアノテーションを追加
*
* @var string
*
* @ORM\Column(type="string", length=255, nullable=true, unique=true)
* @FormAppend(
* auto_render=true,
* options={"label": "スラッグ"}
* )
*/
private $slug;
/**
* @return string|null
*/
public function getSlug(): ?string
{
return $this->slug;
}
/**
* @param string|null $slug
* @return $this
*/
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment