2017 © Pedro Peláez
 

symfony-bundle ezseobundle

Write your SEO for eZPublish easily

image

stevecohen/ezseobundle

Write your SEO for eZPublish easily

  • Tuesday, May 22, 2018
  • by ReaperSoon
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

EzSeoBundle

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*1)


$ composer require stevecohenfr/ezseobundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*2)

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:, (*3)

    // app/AppKernel.php

    // ...
    class AppKernel extends Kernel
    {
        public function registerBundles()
        {
            $bundles = array(
                // ...

                new SteveCohenFR\EzSeoBundle\SteveCohenFREzSeoBundle(),
            );

            // ...
        }

        // ...
    }

Step 3: Create your own provider

app/config.yml, (*4)

steve_cohen_fr_ez_seo:
    providers:
        article:
            class: ACME\ACMEBundle\SEO\Providers\ArticleProvider

Provider example:, (*5)

<?php

namespace ACME\ACMEBundle\SEO\Providers;

use SteveCohenFR\EzSeoBundle\SEO\Providers\AbstractProvider;

class ArticleProvider extends AbstractProvider
{
    /**
    * @override
    */
    function getMetaTitle()
    {
        /* Get first defined attribute */
        $metaTitle = $this->array_find([
            $this->getContent()->getFieldValue('meta_title'),
            $this->getContent()->getFieldValue('title')
        ], function($elem) {
            return $elem != null && $elem != '';
        });

        return $metaTitle;
    }

    /**
    * @override
    */
    function getMetaDescription()
    {
        /* Get first defined attribute */
        $metaDesc = $this->array_find([
            $this->getContent()->getFieldValue('meta_description'),
            $this->getContent()->getFieldValue('intro')->xml->textContent,
            $this->getContent()->getFieldValue('catcher')->xml->textContent
        ], function($elem) {
           return $elem != null && $elem != '';
        });
        return $metaDesc;
    }

    /**
    * Return the first item that match the user provided callback
    */
    private function array_find($xs, $f) {
        foreach ($xs as $x) {
            if (call_user_func($f, $x) === true)
                return $x;
        }
        return null;
    }

}

Step 4: Include SEO in your pagelayout

In your pagelayout.html.twig add this line between , (*6)

tags
<!--  SEO -->
    {{ render( controller( 'SteveCohenFREzSeoBundle:Seo:showMetaSeo', {
        content: content,
        prefix: "",
        suffix: " | ACME"
    } )) }}
  • content (required): Your current content (eZ\Publish\API\Repository\Values\Content)
  • prefix: A prefix for your Meta Title
  • suffix: A suffix for your Meta Title

Availables variables

You can access useful variables in your SEO Provider, like eZ Platform Repository, Container and Content, (*7)

/**
 * Get the current content
 * @var \eZ\Publish\API\Repository\Values\Content\Content $content
 */
$content = $this->getContent();

/**
 * Get eZ Platform Repository
 * @var \eZ\Publish\Core\SignalSlot\Repository $repository
 */
$repository = $this->getRepository();

/**
 * Get symfony Container
 * @var \Symfony\Component\DependencyInjection\Container $container
 */
$container = $this->getContainer();

/**
 * Get a service
 * @var ACME\ACMEBundle\Services\MyService
 */
$myService = $container->get('my.service');

/**
 * Get a parameter from ParametersBag
 * @var string $myParam
 */
$myParam = $container->getParameter('my.parameter');

The Versions

22/05 2018

dev-master

9999999-dev

Write your SEO for eZPublish easily

  Sources   Download

MIT

The Requires

 

by Steve Cohen

ezpublish bundle seo