Skip to content

Commit

Permalink
Config definition update
Browse files Browse the repository at this point in the history
  • Loading branch information
sadikoff committed Dec 26, 2017
1 parent b0979f3 commit a5561b7
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 23 deletions.
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -2,10 +2,10 @@ KoffI18nFormBundle
==================

[![Build Status](https://travis-ci.org/sadikoff/i18n-form-bundle.svg?branch=master)](https://travis-ci.org/sadikoff/i18n-form-bundle)
[![Latest Stable Version](https://poser.pugx.org/koff/i18n-form-bundle/v/stable.svg)](https://packagist.org/packages/koff/i18n-form-bundle)
[![Total Downloads](https://poser.pugx.org/koff/i18n-form-bundle/downloads.svg)](https://packagist.org/packages/koff/i18n-form-bundle)
[![Latest Unstable Version](https://poser.pugx.org/koff/i18n-form-bundle/v/unstable.svg)](https://packagist.org/packages/koff/i18n-form-bundle)
[![License](https://poser.pugx.org/koff/i18n-form-bundle/license.svg)](https://packagist.org/packages/koff/i18n-form-bundle)
[![Latest Stable Version](https://poser.pugx.org/koff/i18n-form-bundle/v/stable.svg?format=flat-square)](https://packagist.org/packages/koff/i18n-form-bundle)
[![Total Downloads](https://poser.pugx.org/koff/i18n-form-bundle/downloads.svg?format=flat-square)](https://packagist.org/packages/koff/i18n-form-bundle)
[![Latest Unstable Version](https://poser.pugx.org/koff/i18n-form-bundle/v/unstable.svg?format=flat-square)](https://packagist.org/packages/koff/i18n-form-bundle)
[![License](https://poser.pugx.org/koff/i18n-form-bundle/license.svg?format=flat-square)](https://packagist.org/packages/koff/i18n-form-bundle)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/sadikoff/i18n-form-bundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/sadikoff/i18n-form-bundle/?branch=master)
[![StyleCI](https://styleci.io/repos/114292466/shield?branch=master)](https://styleci.io/repos/114292466)

Expand All @@ -16,8 +16,8 @@ Requirements
* Symfony flex with Symfony 3.4|4.0
* i18n Doctrine strategy of your choice
* [KnpDoctrineExtension](https://github.com/KnpLabs/DoctrineBehaviors#translatable)
* [A2lixI18nDoctrineBundle](https://github.com/a2lix/I18nDoctrineBundle) [Deprecated - will be removed from bundle in v.4.0.5]
* [PrezentDoctrineTranslatableBundle](https://github.com/Prezent/doctrine-translatable-bundle/blob/master/Resources/doc/index.md) [Deprecated - will be removed from bundle in v.4.0.5]
* [A2lixI18nDoctrineBundle](https://github.com/a2lix/I18nDoctrineBundle) [Deprecated - will be removed from bundle in v.4.0.6]
* [PrezentDoctrineTranslatableBundle](https://github.com/Prezent/doctrine-translatable-bundle/blob/master/Resources/doc/index.md) [Deprecated - will be removed from bundle in v.4.0.6]

Installation
------------
Expand Down
83 changes: 66 additions & 17 deletions src/DependencyInjection/Configuration.php
Expand Up @@ -2,45 +2,94 @@

namespace Koff\Bundle\I18nFormBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* Class Configuration.
*
* @author David ALLIX
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk> . Reiss Clothing Ltd.
* @author Sadicov Vladimir <sadikoff@gmail.com>
*/
class Configuration implements ConfigurationInterface
{
private $convertStringToArray = null;
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$root = $treeBuilder->root('koff_i18n_form')->children();
$rootNode = $treeBuilder->root('i18n_form');

$convertStringToArray = function ($v) {
$this->convertStringToArray = function ($v) {
return preg_split('/\s*[,|]\s*/', $v);
};

$locales = $root->arrayNode('locales');
$locales->defaultValue(['en']);
$locales->beforeNormalization()->ifString()->then($convertStringToArray);
$locales->requiresAtLeastOneElement();
$locales->prototype('scalar');
$this->localesSection($rootNode);
$this->requiredLocalesSection($rootNode);
$this->excludedFieldsSection($rootNode);

$required = $root->arrayNode('required_locales');
$required->beforeNormalization()->ifString()->then($convertStringToArray);
$required->prototype('scalar');
return $treeBuilder;
}

$excluded = $root->arrayNode('excluded_fields');
$excluded->defaultValue(['id', 'locale', 'translatable']);
$excluded->beforeNormalization()->ifString()->then($convertStringToArray);
$excluded->prototype('scalar');
/**
* @param ArrayNodeDefinition $rootNode
*/
private function localesSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->arrayNode('locales')
->defaultValue(['en'])
->beforeNormalization()
->ifString()
->then($this->convertStringToArray)
->end()
->end()
->requiresAtLeastOneElement()
->prototype('scalar')
->end()
->end()
;
}

return $treeBuilder;
/**
* @param ArrayNodeDefinition $rootNode
*/
private function requiredLocalesSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->arrayNode('required_locales')
->beforeNormalization()
->ifString()
->then($this->convertStringToArray)
->end()
->end()
->prototype('scalar')
->end()
->end()
;
}

/**
* @param ArrayNodeDefinition $rootNode
*/
private function excludedFieldsSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->arrayNode('locales')
->defaultValue(['id', 'locale', 'translatable'])
->beforeNormalization()
->ifString()
->then($this->convertStringToArray)
->end()
->end()
->prototype('scalar')
->end()
->end()
;
}
}

0 comments on commit a5561b7

Please sign in to comment.