Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ayman-benmada/sylius-broken-link-handler-plugin

The Broken Link Handler plugin automatically redirects outdated product and taxon slugs to their new versions, ensuring they remain permanent and preventing their reuse by other entities
https://github.com/ayman-benmada/sylius-broken-link-handler-plugin

seo seo-optimization sylius sylius-plugin symfony

Last synced: about 13 hours ago
JSON representation

The Broken Link Handler plugin automatically redirects outdated product and taxon slugs to their new versions, ensuring they remain permanent and preventing their reuse by other entities

Awesome Lists containing this project

README

        

Sylius Broken Link Handler Plugin


The Broken Link Handler plugin automatically redirects outdated product and taxon slugs to their new versions, ensuring they remain permanent and preventing their reuse by other entities.



The goal is to optimize your site so that search engines can index it more effectively, which will help improve its organic search ranking (SEO).

## Presentation

Whenever you create or update a product's slug, it will be automatically saved in the product's slug history.


![presentation photo](https://github.com/ayman-benmada/sylius-broken-link-handler-plugin/blob/main/src/Resources/public/presentation-1.png?raw=true)

A slug that has already been used for a product can never be reused for another. This ensures that old slugs will always remain associated with the same product, so that when accessing an old slug, the user will be redirected to the new one.


![presentation photo](https://github.com/ayman-benmada/sylius-broken-link-handler-plugin/blob/main/src/Resources/public/presentation-2.png?raw=true)

For example, if someone tries to access the URL `/fr_FR/products/000f-grey-jeans`, a 301 redirect will automatically lead to `/fr_FR/products/000f-v2-jean-gris`.

This slug management system is also implemented for taxons. Thus, when attempting to access the page `/fr_FR/taxons/t-shirts/les-hommes`, a redirection will occur to `/fr_FR/taxons/t-shirts/hommes`.


![presentation photo](https://github.com/ayman-benmada/sylius-broken-link-handler-plugin/blob/main/src/Resources/public/presentation-3.png?raw=true)

## Installation

Require plugin with composer :

```bash
composer require abenmada/sylius-broken-link-handler-plugin
```

Change your `config/bundles.php` file to add the line for the plugin :

```php
['all' => true],
]
```

Then create the config file in `config/packages/abenmada_broken_link_handler_plugin.yaml` :

```yaml
imports:
- { resource: "@BrokenLinkHandlerPlugin/Resources/config/services.yaml" }
```

Copy the view responsible for displaying the taxon creation form :
````bash
mkdir -p templates/bundles/SyliusAdminBundle/Taxon
cp vendor/abenmada/sylius-broken-link-handler-plugin/src/Resources/views/Admin/Taxon/_form.html.twig templates/bundles/SyliusAdminBundle/Taxon/_form.html.twig
````

Update the entity `src/Entity/Product/Product.php` :

```php
productSlugHistories = new ArrayCollection();
parent::__construct();
}

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

Update the entity `src/Entity/Taxonomy/Taxon.php` :

```php
taxonSlugHistories = new ArrayCollection();
parent::__construct();
}

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

Run the migration :
```bash
bin/console doctrine:migration:migrate
```