PHP code example of perfectneeds / content-multi-lang-bundle

1. Go to this page and download the library: Download perfectneeds/content-multi-lang-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/ */

    

perfectneeds / content-multi-lang-bundle example snippets



// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new VM5\EntityTranslationsBundle\VM5EntityTranslationsBundle(),
        new PN\MediaBundle\PNMediaBundle(),
        new \PN\LocaleBundle\PNLocaleBundle(),
        new \PN\ServiceBundle\PNServiceBundle(),
        new \PN\ContentBundle\PNContentBundle(),
        // ...
    );
}


// src/PN/Bundle/ContentBundle/Entity/Post.php

namespace PN\Bundle\ContentBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use VM5\EntityTranslationsBundle\Model\Translatable;

// DON'T forget the following use statement!!!
use PN\ContentBundle\Entity\Post as BasePost;
use PN\ContentBundle\Model\PostTrait;

 /**
 * Post
 * @ORM\Table(name="post")
 * @ORM\Entity(repositoryClass="PN\Bundle\ContentBundle\Repository\PostRepository")
 */
class Post extends BasePost implements Translatable {

    use PostTrait;
    
    /**
     * @ORM\OneToMany(targetEntity="PN\Bundle\ContentBundle\Entity\Translation\PostTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true)
     */
    protected $translations;
    
    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
}


// src/PN/Bundle/ContentBundle/Entity/Translation/PostTranslation.php

namespace PN\Bundle\ContentBundle\Entity\Translation;

use Doctrine\ORM\Mapping as ORM;

// DON'T forget the following use statement!!!
use PN\ContentBundle\Entity\Translation\PostTranslation as BasePostTranslation;

/**
 * @ORM\Entity
 * @ORM\Table(name="post_translations")
 */
class PostTranslation extends BasePostTranslation {

    /**
     * @var
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="PN\Bundle\ContentBundle\Entity\Post", inversedBy="translations")
     * @ORM\JoinColumn(name="translatable_id", referencedColumnName="id")
     */
    protected $translatable;

}


// src/PN/Bundle/ContentBundle/Repository/PostRepository.php


namespace PN\Bundle\ContentBundle\Repository;

use PN\ContentBundle\Repository\PostRepository as BasePostRepository;

class PostRepository extends BasePostRepository {

}


// src/PN/Bundle/ContentBundle/Entity/Post.php

namespace PN\Bundle\ContentBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use VM5\EntityTranslationsBundle\Model\Translatable;
use PN\ContentBundle\Entity\Post as BasePost;
use PN\ContentBundle\Model\PostTrait;

/**
 * Post
 * @ORM\Table(name="post")
 * @ORM\Entity(repositoryClass="PN\Bundle\CMSBundle\Repository\PostRepository")
 */
class Post extends BasePost implements Translatable {

    use PostTrait;
    
     /**
     * @ORM\OneToMany(targetEntity="PN\Bundle\ContentBundle\Entity\Translation\PostTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true)
     */
    protected $translations;
    
    // Add here your own relations
    
    /**
     * @ORM\OneToOne(targetEntity="\PN\Bundle\CMSBundle\Entity\DynamicPage", mappedBy="post")
     */
    protected $dynamicPage;
    
    public function __construct()
    {
        parent::__construct();
        // your own logic
    }



namespace PN\Bundle\CMSBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use PN\ServiceBundle\Model\DateTimeTrait;
use VM5\EntityTranslationsBundle\Model\Translatable;
use PN\LocaleBundle\Model\LocaleTrait;

/**
 * DynamicPage
 *
 * @ORM\HasLifecycleCallbacks
 * @ORM\Table(name="dynamic_page")
 * @ORM\Entity(repositoryClass="PN\Bundle\CMSBundle\Repository\DynamicPageRepository")
 */
class DynamicPage implements Translatable {

    use DateTimeTrait,
        LocaleTrait;
    ....

    /**
     * @ORM\OneToOne(targetEntity="PN\Bundle\ContentBundle\Entity\Post", inversedBy="dynamicPage", cascade={"persist", "remove" })
     */
    protected $post;
    
    ....
}




namespace PN\Bundle\CMSBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

// DON'T forget the following use statement!!!
use PN\ContentBundle\Form\PostType;


class DynamicPageType extends AbstractType {

    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
                ->add('post', PostType::class)
                ......
                ;
    }
    .....
}



namespace PN\Bundle\CMSBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use PN\ContentBundle\Form\PostType;

// DON'T forget the following use statement!!!
use PN\ContentBundle\Form\Model\PostTypeModel;


class DynamicPageType extends AbstractType {

    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options) {
        $postTypeModel = new PostTypeModel();
        $postTypeModel->add("description", "descriptionsss");
        $postTypeModel->add("brief", "Brief");
        
        /** documentation
         * @param string $name field_name (must not contain any spaces or special characters)
         * @param string $label field_label
         * @param array $options field_options
         */
        $postTypeModel->add({field_name}, {field_label}, {field_options});
    
        $builder
                ->add('post', PostType::class, [
                    //  DON'T forget the following statement!!!
                    "attributes" => $postTypeModel
                ])
                ......
                ;
    }
    .....
}