Skip to content

Commit

Permalink
Add Entrada List and EntradaController
Browse files Browse the repository at this point in the history
  • Loading branch information
gerMdz committed Mar 26, 2022
1 parent 58cb5fd commit bc055a8
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/Controller/AdminEntradaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Form\EntradaComplexType;
use App\Form\EntradaType;
use App\Form\Step\Entrada\StepOneType;
use App\Form\Step\Entrada\StepThreeType;
use App\Form\Step\Entrada\StepTwoType;
use App\Repository\EntradaRepository;
use App\Repository\PrincipalRepository;
Expand All @@ -19,7 +20,6 @@
use Exception;
use Knp\Component\Pager\PaginatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand Down Expand Up @@ -266,6 +266,7 @@ public function newStepOne(Request $request): Response
]);
}


/**
* @Route("/admin/new/step2/{id}", name="admin_entrada_new_step2", methods={"GET","POST"})
* @param Request $request
Expand Down Expand Up @@ -294,6 +295,37 @@ public function newStepTwo(Request $request, Entrada $entrada): Response
]);
}

/**
* @Route("/admin/new/step3", name="admin_entrada_new_step3", methods={"GET","POST"})
* @param Request $request
* @return Response
* @throws Exception
* @IsGranted("ROLE_ESCRITOR")
*/
public function newStepThree(Request $request): Response
{
$entrada = new Entrada();
$form = $this->createForm(StepThreeType::class, $entrada);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$section = $form['section']->getData();
$entrada->addSection($section);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($entrada);
$entityManager->flush();

return $this->redirectToRoute('admin_entrada_index', [
'id' => $entrada->getId()
]);
}

return $this->render('admin_entrada/new_step3.html.twig', [
'entrada' => $entrada,
'entradaForm' => $form->createView(),
]);
}


/**
* @Route("/admin/entrada/{linkRoute}", name="entrada_admin_link")
Expand Down
98 changes: 98 additions & 0 deletions src/Form/Step/Entrada/StepThreeType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php


namespace App\Form\Step\Entrada;


use App\Entity\Entrada;
use App\Entity\Section;
use App\Entity\User;
use App\Repository\SectionRepository;
use App\Repository\UserRepository;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class StepThreeType extends AbstractType
{

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'titulo',
CKEditorType::class, [
'required' => true,
'config' => [
'uiColor' => '#ffffff',
// 'toolbar' => 'full',
'language' => 'es',
'input_sync' => true
],
'attr' => [
'required' => false,
'class' => 'form-control',
],
])
->add('contenido', CKEditorType::class, [
'required' => false,
'config' => [
'uiColor' => '#ffffff',
// 'toolbar' => 'full',
'language' => 'es',
],
'attr' => [
'required' => false,
'rows' => 10,
// 'class' => 'form-control',
],
])
->add(
'section',
EntityType::class,
[
'class' => Section::class,
'mapped' => false,
'label' => 'Sección?',
'choice_label' => 'identificador',
'placeholder' => 'Seleccione la sección donde se insertará la entrada',
'required' => false,
'help' => 'En qué sección estará esta entrada?',
'attr' => [
'class' => 'select2-enable form-control',
],
]
)
->add(
'autor',
EntityType::class,
[
'class' => User::class,
'query_builder' => function (UserRepository $ur) {
return $ur->findByRoleAutor();
},
'label' => 'Autor?',
'choice_label' => 'primerNombre',
'placeholder' => 'Seleccione autor',
'required' => false,
'help' => 'Autor de la entrada entrada?',
'attr' => [
'class' => 'select2-enable',
],
]
)
; // Fin del builder
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'data_class' => Entrada::class,
]
);
}
}
12 changes: 12 additions & 0 deletions templates/admin_entrada/new_step3.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends 'base_admin_board.html.twig' %}

{% block title %}

{% endblock %}

{% block content %}
<div class="col-sm-9 mx-auto">
<a class="btn btn-info" href="{{ path('admin_entrada_index') }}">Cancelar e ir al Listado</a>
</div>
{% endblock %}

0 comments on commit bc055a8

Please sign in to comment.