Commit 2d62aefa authored by dj3c1t's avatar dj3c1t

fix deprecations

parent 9281dfa3
......@@ -7,6 +7,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Dj3c1t\SourceMLBundle\Entity\Author;
use Dj3c1t\SourceMLBundle\Form\Type\AuthorType;
class AuthorController extends Controller {
......@@ -36,7 +37,7 @@ class AuthorController extends Controller {
$author->setUseCaptcha(false);
$author->setUser($this->getUser());
$form = $this->createForm(
"sourceml_author",
AuthorType::class,
$author
);
$form->handleRequest($request);
......@@ -79,7 +80,7 @@ class AuthorController extends Controller {
}
$em = $this->get('doctrine')->getManager();
$form = $this->createForm(
"sourceml_author",
AuthorType::class,
$author
);
$form->handleRequest($request);
......
......@@ -8,6 +8,7 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Dj3c1t\SourceMLBundle\Entity\Source;
use Dj3c1t\SourceMLBundle\Entity\SourceType;
use Dj3c1t\SourceMLBundle\Form\Type\SourceType as SourceFormType;
class SourceController extends Controller {
......@@ -141,8 +142,11 @@ class SourceController extends Controller {
}
$source->setSourceType($SourceType);
$form = $this->createForm(
"sourceml_source",
$source
SourceFormType::class,
$source,
array(
"container" => $this,
)
);
$form->handleRequest($request);
if($form->isValid()) {
......@@ -219,9 +223,10 @@ class SourceController extends Controller {
}
$source->setSourceType($SourceType);
$form = $this->createForm(
"sourceml_source",
SourceFormType::class,
$source,
array(
"container" => $this,
"isReference" => true,
)
);
......@@ -263,9 +268,10 @@ class SourceController extends Controller {
$em = $this->get('doctrine')->getManager();
if($sm->userCan("edit", $source)) {
$form = $this->createForm(
"sourceml_source",
SourceFormType::class,
$source,
array(
"container" => $this,
"isReference" => $source->isReference(),
)
);
......
......@@ -6,6 +6,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Dj3c1t\SourceMLBundle\Entity\Licence;
use Dj3c1t\SourceMLBundle\Form\Type\LicenceType;
class LicenceController extends Controller {
......@@ -31,7 +32,7 @@ class LicenceController extends Controller {
$em = $this->get('doctrine')->getManager();
$licence = new Licence();
$form = $this->createForm(
"sourceml_licence",
LicenceType::class,
$licence
);
$form->handleRequest($request);
......@@ -71,7 +72,7 @@ class LicenceController extends Controller {
public function editAction(Request $request, Licence $licence) {
$em = $this->get('doctrine')->getManager();
$form = $this->createForm(
"sourceml_licence",
LicenceType::class,
$licence
);
$form->handleRequest($request);
......
......@@ -24,6 +24,5 @@ class Dj3c1tSourceMLExtension extends Extension
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$loader->load('services.forms.yml');
}
}
......@@ -5,30 +5,28 @@ namespace Dj3c1t\SourceMLBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
class AuthorType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add(
'name',
'text',
TextType::class,
array(
'label' => 'Name'
)
);
$builder->add(
'description',
'textarea',
TextareaType::class,
array(
'label' => 'Description'
)
);
}
public function getName() {
return 'sourceml_author';
}
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults(
array(
......
......@@ -5,30 +5,27 @@ namespace Dj3c1t\SourceMLBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class LicenceType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add(
'name',
'text',
TextType::class,
array(
'label' => 'Name'
)
);
$builder->add(
'url',
'text',
TextType::class,
array(
'label' => 'URL'
)
);
}
public function getName() {
return 'sourceml_licence';
}
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults(
array(
......
......@@ -2,7 +2,6 @@
namespace Dj3c1t\SourceMLBundle\Form\Type;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
......@@ -11,6 +10,9 @@ use Symfony\Component\Form\FormError;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Doctrine\Bundle\DoctrineBundle\Registry as Doctrine;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Dj3c1t\SourceMLBundle\Entity\SourceInfo;
use Dj3c1t\SourceMLBundle\Entity\SourceAuthor;
......@@ -29,8 +31,11 @@ class SourceType extends AbstractType {
private $options;
public function __construct(Container $container) {
$this->container = $container;
public function setContainer() {
if($this->options["container"] === null) {
throw new \Exception("container passed in options to SourceType is null");
}
$this->container = $this->options["container"];
$this->em = $this->container->get('doctrine')->getManager();
$this->sm = $this->container->get('sourceml.source_manager');
$this->sourceRepo = $this->em->getRepository("Dj3c1tSourceMLBundle:Source");
......@@ -42,6 +47,7 @@ class SourceType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$this->options = $options;
$this->setContainer();
$this->source = $builder->getData();
$this->isNew = ($this->source->getId()) === null;
if($this->isNew || $this->options["isReference"]) {
......@@ -61,14 +67,14 @@ class SourceType extends AbstractType {
}
$builder->add(
'author',
'entity',
EntityType::class,
$option
);
}
if($this->options["isReference"]) {
$builder->add(
'referenceUrl',
'text',
TextType::class,
array(
'label' => 'XML URL'
)
......@@ -80,14 +86,14 @@ class SourceType extends AbstractType {
}
$builder->add(
'title',
'text',
TextType::class,
array(
'label' => 'Title'
)
);
$builder->add(
'description',
'textarea',
TextareaType::class,
array(
'label' => 'Description',
'data' => $description,
......@@ -102,7 +108,7 @@ class SourceType extends AbstractType {
) {
$builder->add(
'licence',
'entity',
EntityType::class,
array(
'class' => 'Dj3c1tSourceMLBundle:Licence',
'label' => 'Licence',
......@@ -156,7 +162,7 @@ class SourceType extends AbstractType {
}
$builder->add(
'composition',
'entity',
EntityType::class,
$builderParams
);
}
......@@ -172,16 +178,13 @@ class SourceType extends AbstractType {
);
}
public function getName() {
return 'sourceml_source';
}
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults(
array(
'data_class' => 'Dj3c1t\SourceMLBundle\Entity\Source',
'translation_domain' => 'sourceml',
'isReference' => false,
'container' => null,
)
);
}
......
services:
sourceml.form.type.author:
class: Dj3c1t\SourceMLBundle\Form\Type\AuthorType
tags:
- { name: form.type, alias: sourceml_author }
sourceml.form.type.source:
class: Dj3c1t\SourceMLBundle\Form\Type\SourceType
tags:
- { name: form.type, alias: sourceml_source }
arguments: ['@service_container']
sourceml.form.type.licence:
class: Dj3c1t\SourceMLBundle\Form\Type\LicenceType
tags:
- { name: form.type, alias: sourceml_licence }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment