2017 © Pedro PelĂĄez
 

symfony-bundle display-bundle

This Bundle provides generate view for given object

image

enterprisephp/display-bundle

This Bundle provides generate view for given object

  • Wednesday, March 29, 2017
  • by behramcelen
  • Repository
  • 7 Watchers
  • 4 Stars
  • 2,097 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 1 % Grown

The README.md

EPDisplayBundle

Easily generate view for given entity/object, (*1)

SensioLabsInsight knpbundles.com, (*2)

Very Basic Screenshot;

image, (*3)

  • https://github.com/ojs/ojs/issues/990
  • https://github.com/ojs/ojs/blob/master/src/Ojs/CoreBundle/Service/Twig/DisplayExtension.php

  • Development steps can be followed from https://github.com/behramcelen/symfony-bundle-develop
  • A basic test and logic controller and view can be found in https://github.com/behramcelen/symfony-bundle-develop/blob/master/src/AppBundle/Controller/DisplayController.php#L16
  • https://github.com/behramcelen/symfony-bundle-develop/blob/master/src/AppBundle/Resources/views/Display/display.html.twig#L7

Installation

Step 1: Download the Bundle

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

$ composer require enterprisephp/display-bundle "dev-master"

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

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:, (*6)

<?php
// app/AppKernel.php

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

            new EP\DisplayBundle\EPDisplayBundle(),
        );

        // ...
    }

    // ...
}

DisplayTrait

use DisplayTrait on which you want to display objects/entities (!important):, (*7)


namespace AppBundle\Entity; use EP\DisplayBundle\Entity\DisplayTrait; class MyEntity { use DisplayTrait; }

Configuration

Add below configs to config.yml file:, (*8)

ep_display:
    global:
        image_render: true # (optinal) defaults to true
        file_render: true # (optinal) defaults to true
        template: EPDisplayBundle::display.html.twig # (optinal) defaults to EPDisplayBundle:display.html.twig template
        exclude_vars: # (optinal) defaults to empty array
            - excludeField
            - hiddenField
            - password
        array_collection_render: true # (optinal) defaults to true
        collection_item_count: 5 # (optinal) defaults to 10

Usage

If you do not want to any extreme things. Only display on template;, (*9)

{{ display(entity) }} # so easy isn't it 😉

You can override all bundle configs via class annotation:
related : https://github.com/EnterprisePHP/EPDisplayBundle/blob/master/Annotation/Display.php#L11, (*10)

namespace AppBundle\Entity;

use EP\DisplayBundle\Annotation as Display;

/**
 * @Display\Display(
 *     image_render=false, # optinal
 *     file_render=false, # optinal
 *     template="my_entity_special_template.html.twig", # optinal
 *     array_collection_render=true, # optinal
 *     collection_item_count=8, # optinal
 * )
 */
class MyEntity
{

If you exclude spesific fields of entity use Exclude annotation:
related : https://github.com/EnterprisePHP/EPDisplayBundle/blob/master/Annotation/Exclude.php, (*11)

namespace AppBundle\Entity;

use EP\DisplayBundle\Annotation as Display;

class DummyEntity
{
  /**
   * @Display\Exclude
   */
  protected $unPublicfieldForOnlyThisEntity;

Expose field. All fields defaultly exposes but if you excluded from config but only one time you want to expose this field;, (*12)

namespace AppBundle\Entity;

use EP\DisplayBundle\Annotation as Display;

class DummyEntity
{
  /**
   * @Display\Expose
   */
  protected $oneTimeExposeField;

File expose with link;, (*13)

namespace AppBundle\Entity;

use EP\DisplayBundle\Annotation as Display;

class DummyEntity
{
  /**
   * @Display\File(path="uploads/files")
   */
  protected $mainFile;

Image expose with img tag;, (*14)

namespace AppBundle\Entity;

use EP\DisplayBundle\Annotation as Display;

class DummyEntity
{
  /**
   * @Display\Image(
   *    path="uploads/files",
   *    height="50",
   *    width="70",
   * )
   */
  protected $cover;

You can spesify all configs from template as second param on display function;, (*15)

{{ display(entity, {
    files: {
        my_file: {
            path: "web/uploads"
        }
    },
    images: {
        header: {
            path: "web/images",
            width: "70",
            height: "50"
        }
    },
    exclude: "myVeryPrivateField", // can be array
    expose: "onlyForThisPageExposeVar", // can be array
    image_render: true,
    file_render: true,
    array_collection_render: false,
    collection_item_count: 90,
    template: "my_stylish_template.html.twig"
}) }}

Reporting an issue or a feature request

Issues and feature requests are tracked in the Github issue tracker., (*16)

When reporting a bug, it may be a good idea to reproduce it in a basic project built using the Symfony Standard Edition to allow developers of the bundle to reproduce the issue by simply cloning it and following some steps., (*17)

The Versions