2017 © Pedro Peláez
 

symfony-bundle simple-configuration-bundle

This is a Symfony Bundle that adds key value storage to your Sonata admin.

image

kunicmarko/simple-configuration-bundle

This is a Symfony Bundle that adds key value storage to your Sonata admin.

  • Friday, November 24, 2017
  • by kunicmarko20
  • Repository
  • 2 Watchers
  • 4 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Simple Configuration Bundle

Build Status SensioLabsInsight StyleCI Coverage Status, (*1)

This bundle adds key:value storage to your sonata admin, also you can easily extend bundle and add your own types., (*2)

This bundle depends on SonataAdminBundle, (*3)

Dashboard, (*4)

Documentation

Installation

1. Add to composer.json to the require key, (*5)

composer require kunicmarko/simple-configuration-bundle

2. Register the bundle in app/AppKernel.php, (*6)

$bundles = array(
    // ...
    new KunicMarko\SimpleConfigurationBundle\SimpleConfigurationBundle(),
);

If you are not using auto_mapping add it to your orm mappings, (*7)

# app/config/config.yml
   orm:
        entity_managers:
            default:
                mappings:
                    AppBundle: ~
                    ...
                    SimpleConfigurationBundle: ~

3. Update database, (*8)

app/console doctrine:schema:update --force

4. Clear cache, (*9)

app/console cache:clear

How to use

In your twig template you can call it like :, (*10)

{{ simple_configuration.getAll() }}
{{ simple_configuration.getValueFor('name') }}

if you want to use it in controller you can do :, (*11)

$this->get('simple_configuration.service.configuration')->getAll()
$this->get('simple_configuration.service.configuration')->getValueFor('name')

Add new type

If you want to add new types, you can do it like this, (*12)

# app/config/config.yml

simple_configuration:
    types: 
        newtype: YourBundle\Entity\NewType

Creating new Type

Your new type has to extend AbstractConfigurationType, you also have to specify template used for sonata list (it can be sonata template, or your own created), and how should field be rendered in form., (*13)

1. New type without new column, (*14)

namespace YourBundle\Entity;

use KunicMarko\SimpleConfigurationBundle\Entity\AbstractConfigurationType;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\Form\Extension\Core\Type\TextType;

class NewType extends AbstractConfigurationType
{
    /**
     * {@inheritDoc}
     */
    public function getTemplate() : string
    {
        return 'SonataAdminBundle:CRUD:list_string.html.twig';
    }

    /**
     * {@inheritDoc}
     */
    public function generateFormField(FormMapper $formMapper) : void
    {
        $formMapper->add('value', TextType::class, ['required' => false]);
    }
}

2. New type with new column, (*15)

As you can see from example code below, we added new $date field, the one thing that is necessary is to overwrite getValue() method with delegating to your getter for new field as shown below., (*16)


namespace YourBundle\Entity; use Doctrine\ORM\Mapping as ORM; use KunicMarko\SimpleConfigurationBundle\Entity\AbstractConfigurationType; use Sonata\AdminBundle\Form\FormMapper; use Symfony\Component\Form\Extension\Core\Type\DateType; class NewType extends AbstractConfigurationType { /** * @var \DateTime * * @ORM\Column(name="date", type="date", nullable=true) */ private $date; public function setDate(?\DateTime $date) : self { $this->date = $date; return $this; } public function getDate() : ?\DateTime { return $this->date; } public function getValue() : ?\DateTime { return $this->getDate(); } /** * {@inheritDoc} */ public function getTemplate() : string { //return 'SonataAdminBundle:CRUD:list_string.html.twig'; can also be used return 'SimpleConfigurationBundle:CRUD:list_field_date.html.twig'; } /** * {@inheritDoc} */ public function generateFormField(FormMapper $formMapper) : void { $formMapper->add('date', DateType::class, ['required' => false]); } }

Do not forget to update database after adding new field :, (*17)

app/console doctrine:schema:update --force

Additional stuff

When including this bundle you get access to some twig filters I needed., (*18)

Elapsed

In twig you can use |elapsed filter and you will get human readable time, it works with timestamps or DateTime objects., (*19)

{{ var|elapsed }}

#outputs "time" ago, 5 days ago, 5 minutes ago, just now, 1 month ago, etc.

The Versions

24/11 2017

v1.x-dev

1.9999999.9999999.9999999-dev https://github.com/kunicmarko20/simple-configuration-bundle

This is a Symfony Bundle that adds key value storage to your Sonata admin.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle symfony sonata sonata admin key value storage

24/11 2017

v1.0.2

1.0.2.0 https://github.com/kunicmarko20/simple-configuration-bundle

This is a Symfony Bundle that adds key value storage to your Sonata admin.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle symfony sonata sonata admin key value storage

31/10 2017

v1.0.1

1.0.1.0 https://github.com/kunicmarko20/simple-configuration-bundle

This is a Symfony Bundle that adds key value storage to your Sonata admin.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle symfony sonata sonata admin key value storage

29/10 2017

dev-master

9999999-dev https://github.com/kunicmarko20/simple-configuration-bundle

This is a Symfony Bundle that adds key value storage to your Sonata admin.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle symfony sonata sonata admin key value storage

28/10 2017

v1.0.0

1.0.0.0 https://github.com/kunicmarko20/simple-configuration-bundle

This is a Symfony Bundle that adds key value storage to your Sonata admin.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle symfony sonata sonata admin key value storage