Created
December 10, 2020 23:53
-
-
Save kurozumi/e079ffecc67872e2ab644144b8c95244 to your computer and use it in GitHub Desktop.
ProductTrait
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of Customize | |
* | |
* Copyright(c) Akira Kurozumi <[email protected]> | |
* | |
* 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