Skip to content

Commit

Permalink
Merge pull request #6 from Jibbarth/fix/display-form-without-easyadmin
Browse files Browse the repository at this point in the history
Fix bug to display form without easyadmin
  • Loading branch information
Jibbarth authored Dec 15, 2018
2 parents 992275f + 6027efa commit 2003906
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 13 deletions.
19 changes: 14 additions & 5 deletions src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
use Barth\SimpleConfigBundle\Service\ExtensionConfigurationService;
use Barth\SimpleConfigBundle\Service\ExtensionLocatorService;
use Barth\SimpleConfigBundle\Service\FormConfigService;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* Class DefaultController.
*/
class DefaultController extends Controller
class DefaultController extends AbstractController
{
/**
* @var ConfigService
Expand Down Expand Up @@ -106,10 +106,9 @@ public function editAction(
}
}

$nameConverter = new SnakeCaseToCamelCaseNameConverter();
return $this->render('@BarthSimpleConfig/form.html.twig', [
return $this->render($this->getTemplate(), [
'config_form' => $form->createView(),
'extension' => $nameConverter->handle($extension->getAlias()),
'extension' => $extension->getAlias(),
'parent_template' => $this->getParentTemplate(),
]);
}
Expand All @@ -134,4 +133,14 @@ protected function getParentTemplate()
return '@BarthSimpleConfig/base.html.twig';
}
}

protected function getTemplate()
{
switch ($this->defaultAdminBundle) {
case 'easy_admin':
return '@BarthSimpleConfig/easy_admin_form.html.twig';
default:
return '@BarthSimpleConfig/base_form.html.twig';
}
}
}
2 changes: 1 addition & 1 deletion src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
$projectDir: '%kernel.project_dir%'

Barth\SimpleConfigBundle\:
resource: '../../{Service}/*'
resource: '../../{Service,Twig,NameConverter}/*'

Barth\SimpleConfigBundle\Controller\:
resource: '../../Controller'
Expand Down
4 changes: 4 additions & 0 deletions src/Resources/views/base_form.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% block main %}
{% set form_attr = {} %}
{% embed '@BarthSimpleConfig/form.html.twig' %}{% endembed %}
{% endblock %}
5 changes: 5 additions & 0 deletions src/Resources/views/easy_admin_form.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% block main %}
{% form_theme config_form with easyadmin_config('design.form_theme') %}
{% set form_attr = {'attr': {'class':'form-horizontal'}} %}
{% embed '@BarthSimpleConfig/form.html.twig' %}{% endembed %}
{% endblock %}
7 changes: 1 addition & 6 deletions src/Resources/views/form.html.twig
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{% extends parent_template %}

{% set form_attr = {} %}
{% if 'EasyAdmin' in parent_template %}
{% form_theme config_form with easyadmin_config('design.form_theme') %}
{% set form_attr = {'attr': {'class':'form-horizontal'}} %}
{% endif %}
{% block content_title %}Settings for {{ extension | snakeToCamel }}{% endblock %}

{% block content_title %}Settings for {{ extension }}{% endblock %}
{% block main %}
{{ form_start(config_form, form_attr) }}
<div class="row">
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<main class="col-xs-12 col-12 row m-2">
{% for bundle in bundles %}
<div class="col-xs-3 col-3 border text-center m-2 p-2">
<span class="h5 text-capitalize clearfix">{{ bundle }}</span>
<span class="h5 text-capitalize clearfix">{{ bundle | snakeToCamel}}</span>
<a href="{{ path('barth_simpleconfig_edit', {'package' : bundle}) }}" class="btn btn-primary btn-xs mt-3 mb-2" >
Edit configuration
</a>
Expand Down
33 changes: 33 additions & 0 deletions src/Twig/CamelizeExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Barth\SimpleConfigBundle\Twig;

use Barth\SimpleConfigBundle\NameConverter\SnakeCaseToCamelCaseNameConverter;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

class CamelizeExtension extends AbstractExtension
{
/**
* @var SnakeCaseToCamelCaseNameConverter
*/
private $nameConverter;

public function __construct(
SnakeCaseToCamelCaseNameConverter $nameConverter
) {
$this->nameConverter = $nameConverter;
}

public function getFilters(): array
{
return [
new TwigFilter('snakeToCamel', [$this, 'snakeToCamel']),
];
}

public function snakeToCamel(string $value): string
{
return $this->nameConverter->handle($value);
}
}

0 comments on commit 2003906

Please sign in to comment.