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

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



// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new PN\MediaBundle\PNMediaBundle(),
        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;

// 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 {

    use PostTrait;
    
    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
}


// 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 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 {

    use PostTrait;
        
    // 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;

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

    use DateTimeTrait;
    ....

    /**
     * @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
                ])
                ......
                ;
    }
    .....
}