Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Unique param name check & update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Mischa Braam committed Aug 31, 2018
1 parent edb5ce9 commit e324f47
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
15 changes: 13 additions & 2 deletions Admin/ConfigVariableAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

class ConfigVariableAdmin extends BaseAdmin
{
// TODO: name of config value is unique in database, prevent throw of exception when duplicate name is inserted
// TODO: maybe add filters, currently disabled
// TODO: when inserting and type is changed to or from 'choice' show or hide the choices sub-entity (ConfigVariableChoice)

Expand Down Expand Up @@ -52,7 +51,9 @@ protected function configureFormFields(FormMapper $formMapper)

$formMapper
->add('name')
->add('description');
->add('description', null, array(
'required' => false,
));

if ($configVariable->getId() === null) {
$formMapper
Expand Down Expand Up @@ -107,6 +108,16 @@ protected function configureShowFields(ShowMapper $showMapper)
*/
public function validate(ErrorElement $errorElement, $configVariable)
{
// Is name unique?
$other = $this->modelManager->findOneBy($this->getClass(), array('name' => $configVariable->getName()));
if (null !== $other && $other->getId() != $configVariable->getId()) {
$errorElement
->with('name')
->addViolation('The name field must be unique')
->end();
}

// Name according to Symfony's naming conventions?
if (!$configVariable->hasValidName()) {
$errorElement
->with('name')
Expand Down
Binary file added README-Screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 48 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
# We Provide Config Bundle

The We Provide Config Bundle for Symfony adds an interface into the Sonata/AdminBundle in which you can configure application parameters.
The We Provide Config Bundle for Symfony adds an interface into the Sonata/AdminBundle in which you can configure application parameters.

Your Symfony application has a dozen of config values and parameters set in your `app/config` folder, spread in different (or one) `yml` files. If you need to be able to change the value of these configs at runtime without manually editing these files you can use We Provide's Config Bundle.

Let's for example say that you want to enable or disable a maintenance mode. You can do this now without having to log into your server, change the yml file and clear the cache, simply by changing the value with We Provide's Config Bundle.


![ConfigBundle interface](README-Screenshot-1.png)


In the image shown above you'll see a couple of parameters configured with the interface. This will output a `parameters.yml` which looks like below.

```yaml
parameters:
boolean.param: true
integer.param: 13
string.param: 'This a test string value'
choice.param: choice-2
```
You can use these parameters like you normally would in your Symfony application. Either in a controller with
```
$this->getParameter('boolean.param');
```
or even in other parameters or config values with
```yaml
swiftmailer:
delivery_addresses: '%string.param%'
```
## Dependencies
This bundle is developed with a Symfony Standard Edition on PHP 7.1 using We Provide's version of valet+. Obviously it has dependencies to other projects and/or bundles. Below a list of dependencies, please use the installation guides of these bundles first.
This bundle is developed with a Symfony Standard Edition on PHP 7.1 using We Provide's Valet+. Obviously it has dependencies to other projects and/or bundles. Below a list of dependencies, please use the installation guides of these bundles first.
* [Symfony Standard Edition 3.3](https://symfony.com/doc/current/setup.html#creating-symfony-applications-with-composer)
* [Sonata Admin Bundle 3.23](https://sonata-project.org/bundles/admin/3-x/doc/getting_started/installation.html) (with [SonataDoctrineORMAdminBundle](https://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/installation.html))
Expand Down Expand Up @@ -40,17 +69,31 @@ class AppKernel extends Kernel
}
```

Include the `config.yml` and `parameters.yml` into your own under the section `imports`. You can choose in which order you include these files, depending on where you want to use the parameters.
```yaml
imports:
# ...
- { resource: "@WeProvideConfigBundle/Resources/config/config.yml" }
- { resource: "@WeProvideConfigBundle/Resources/config/parameters.yml", ignore_errors: true }
```
Update your database schema with the doctrine command.
```
bin/console doctrine:schema:update --force
```


## License

This bundle has been released under the MIT license and open for improvements, please share your thoughts which will be much appreciated.



## Authors

- Mischa Braam ([@mischabraam](https://github.com/mischabraam))

## TODO

- Add event listeners where the client application can hook onto.
## TODO's

- [ ] Add event listeners where the client application can hook onto.
- [ ] Add list type to be able to config an yml array.

0 comments on commit e324f47

Please sign in to comment.