PHP code example of lch / seo-bundle

1. Go to this page and download the library: Download lch/seo-bundle 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/ */

    

lch / seo-bundle example snippets


     use Lch\SeoBundle\Behaviour\Seoable;
     use Lch\SeoBundle\Model\SeoInterface;
    
     class MyEntity implements SeoInterface
     {
     
         use Seoable;
         
         ...
 

    /**
     * @inheritdoc
     */
    public function getSluggableFields()
    {
        // This assume your entity have a field 'title'
        return [
            'title'
        ];
    }


    /**
     * @inheritdoc
     */
    public function getRouteFields()
    {
        return [
            'slug' => 'slug'
        ];
    }

    /**
     * @inheritdoc
     */
    public function getRouteName()
    {
        // This assume to return the entity show page route
        return 'yourproject_yourentity_show';
    }

    /**
      * @inheritdoc
      */
     public function getSeoTitleDefaultValue()
     {
         return $this->title;
     }
 

     const OG_TITLE = 'title';
     const OG_TYPE = 'type';
     const OG_URL = 'url';
     const OG_IMAGE = 'image';
 

    /**
     * @inheritdoc
     */
    public function getOpenGraphData()
    {
        $openGraphData = [
            static::OG_TITLE => $this->title,
            static::OG_TYPE => "Open Graph type"
        ];

        // Image check example
        if($this->headBandImage instanceof Image) {
            $imageData = explode('/web', $this->getHeadBandImage()->getFile());
            $openGraphData[static::OG_IMAGE] = array_pop($imageData);
        }

        return $openGraphData;
    }

     use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
    
     /**
      * Class MyEntity
      * @package App\Entity\MyEntity
      *
      * @ORM\Table
      * @ORM\Entity
      * @UniqueEntity("slug")
      */
     class MyEntity implements SeoInterface
     {
     
         use Seoable;
         
         ...
 

use Lch\SeoBundle\Form\SeoType;

/**
 * {@inheritdoc}
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder

        // ...

        ->add('seo', SeoType::class, array(
            'label' => 'lch.seo.form.label',
            '