Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Created December 10, 2020 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/e079ffecc67872e2ab644144b8c95244 to your computer and use it in GitHub Desktop.
Save kurozumi/e079ffecc67872e2ab644144b8c95244 to your computer and use it in GitHub Desktop.
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