Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbieniek committed Jan 10, 2019
0 parents commit 13b8012
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => ['syntax' => 'short'],
'simplified_null_return' => false,
'phpdoc_align' => false,
'phpdoc_to_comment' => false,
'cast_spaces' => false,
'blank_line_after_opening_tag' => false,
'single_blank_line_before_namespace' => false,
'space_after_semicolon' => false,
'yoda_style' => false,
'no_break_comment' => false,
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->files()->name('*.php')
)
;
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2018 Mateusz Bieniek

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ezplatform-form-builder-country-field
## Description
Bundle provides country selection field for the Form Builder in eZ Platform EE.

## Installation
### 1. Enable EzPublishLegacyBundle and EzSystemsEzPlatformXmlTextFieldTypeBundle
Edit `app/AppKernel.php`, and add
```
new MateuszBieniek\EzPlatformFormBuilderCountryBundle\EzPlatformFormBuilderCountryBundle(),
```
at the end of the `$bundles` array.
### 2. Install `mateuszbieniek/ezplatform-form-builder-country-field`
```
composer require mateuszbieniek/ezplatform-form-builder-country-field
```
35 changes: 35 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "mateuszbieniek/ezplatform-form-builder-country-field",
"license": "MIT",
"type": "ezplatform-bundle",
"description": "Bundle providing Country select field for the eZ Platform EE Form Builder",
"repositories": [
{
"type": "composer",
"url": "https://updates.ez.no/ttl"
}
],
"autoload": {
"psr-4": {
"MateuszBieniek\\EzPlatformFormBuilderCountryBundle\\": "src/bundle/",
"MateuszBieniek\\EzPlatformFormBuilderCountry\\": "src/lib/"
}
},
"autoload-dev": {
"psr-4": {
"MateuszBieniek\\EzPlatformFormBuilderCountryBundle\\Tests\\": "src/bundle/Tests"
}
},
"require": {
"php": ">=7.1",
"ezsystems/ezpublish-kernel": "^7.3",
"ezsystems/ezplatform-form-builder": "^1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "2.7.*",
"phpunit/phpunit": "~7.0"
},
"scripts": {
"fix-cs": "@php ./vendor/bin/php-cs-fixer fix -v --show-progress=estimating"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace MateuszBieniek\EzPlatformFormBuilderCountryBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\Yaml\Yaml;

class EzPlatformFormBuilderCountryExtension extends Extension implements PrependExtensionInterface
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__ . '/../Resources/config')
);
$loader->load('services.yml');
}

/**
* {@inheritdoc}
*/
public function prepend(ContainerBuilder $container): void
{
$config = Yaml::parseFile(
__DIR__ . '/../Resources/config/config.yml'
);

foreach ($config as $extension => $settings) {
$container->prependExtensionConfig($extension, $settings);
}
}
}
18 changes: 18 additions & 0 deletions src/bundle/EzPlatformFormBuilderCountryBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace MateuszBieniek\EzPlatformFormBuilderCountryBundle;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class EzPlatformFormBuilderCountryBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container): void
{
}
}
12 changes: 12 additions & 0 deletions src/bundle/Resources/config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
twig:
form_themes:
- '@EzPlatformFormBuilderCountry/form/fields.html.twig'

ez_platform_form_builder:
fields:
country:
name: 'Country'
category: 'Basic form fields'
thumbnail: '/bundles/ezplatformadminui/img/ez-icons.svg#languages'
validators:
required: ~
12 changes: 12 additions & 0 deletions src/bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

MateuszBieniek\EzPlatformFormBuilderCountry\FormBuilder\Field\Mapper\CountryMapper:
arguments:
$fieldIdentifier: 'country'
$formType: 'MateuszBieniek\EzPlatformFormBuilderCountry\Form\Type\CountryFieldType'
tags:
- { name: ezplatform.form_builder.field_mapper }
3 changes: 3 additions & 0 deletions src/bundle/Resources/views/form/fields.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% block mateuszbieniek_country_widget %}
{{ form_widget(form) }}
{% endblock %}
27 changes: 27 additions & 0 deletions src/lib/Form/Type/CountryFieldType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace MateuszBieniek\EzPlatformFormBuilderCountry\Form\Type;

use EzSystems\EzPlatformFormBuilder\Form\Type\Field\AbstractFieldType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;

class CountryFieldType extends AbstractFieldType
{
public function getName()
{
return $this->getBlockPrefix();
}

public function getBlockPrefix()
{
return 'mateuszbieniek_country';
}

/**
* {@inheritdoc}
*/
public function getParent(): string
{
return CountryType::class;
}
}
23 changes: 23 additions & 0 deletions src/lib/FormBuilder/Field/Mapper/CountryMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace MateuszBieniek\EzPlatformFormBuilderCountry\FormBuilder\Field\Mapper;

use EzSystems\EzPlatformFormBuilder\FieldType\Field\Mapper\GenericFieldMapper;
use EzSystems\EzPlatformFormBuilder\FieldType\Model\Field;

class CountryMapper extends GenericFieldMapper
{
/**
* {@inheritdoc}
*/
protected function mapFormOptions(Field $field, array $constraints): array
{
$options = parent::mapFormOptions($field, $constraints);
$options['field'] = $field;
$options['label'] = $field->getName();

return $options;
}
}

0 comments on commit 13b8012

Please sign in to comment.