PHP code example of abenmada / sylius-broken-link-handler-plugin

1. Go to this page and download the library: Download abenmada/sylius-broken-link-handler-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

abenmada / sylius-broken-link-handler-plugin example snippets




return [
    //..
    Abenmada\BrokenLinkHandlerPlugin\BrokenLinkHandlerPlugin::class => ['all' => true],
]



declare(strict_types=1);

namespace App\Entity\Product;

use Abenmada\BrokenLinkHandlerPlugin\Model\SlugHistory\ProductSlugHistoryTrait;
use Abenmada\BrokenLinkHandlerPlugin\Validator\SlugExistsInOtherProductSlugHistories;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\Product as BaseProduct;
use Symfony\Component\Validator\Mapping\ClassMetadata;

/**
 * @ORM\Entity
 * @ORM\Table(name="sylius_product")
 */
#[ORM\Entity]
#[ORM\Table(name: 'sylius_product')]
class Product extends BaseProduct
{
    use ProductSlugHistoryTrait;

    public function __construct()
    {
        $this->productSlugHistories = new ArrayCollection();
        parent::__construct();
    }

    public static function loadValidatorMetadata(ClassMetadata $metadata): void
    {
        $metadata->addConstraint(new SlugExistsInOtherProductSlugHistories([
            'groups' => 'sylius',
        ]));
    }
}



declare(strict_types=1);

namespace App\Entity\Taxonomy;

use Abenmada\BrokenLinkHandlerPlugin\Model\SlugHistory\TaxonSlugHistoryTrait;
use Abenmada\BrokenLinkHandlerPlugin\Validator\SlugExistsInOtherTaxonSlugHistories;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\Taxon as BaseTaxon;
use Symfony\Component\Validator\Mapping\ClassMetadata;

/**
 * @ORM\Entity
 * @ORM\Table(name="sylius_taxon")
 */
#[ORM\Entity]
#[ORM\Table(name: 'sylius_taxon')]
class Taxon extends BaseTaxon
{
    use TaxonSlugHistoryTrait;

    public function __construct()
    {
        $this->taxonSlugHistories = new ArrayCollection();
        parent::__construct();
    }

    public static function loadValidatorMetadata(ClassMetadata $metadata): void
    {
        $metadata->addConstraint(new SlugExistsInOtherTaxonSlugHistories([
            'groups' => 'sylius',
        ]));
    }
}