diff --git a/Controller/SectionController.php b/Controller/SectionController.php
index fc2eeaa8b..412fc0b87 100644
--- a/Controller/SectionController.php
+++ b/Controller/SectionController.php
@@ -12,6 +12,8 @@
use eZ\Publish\API\Repository\Exceptions\UnauthorizedException;
use EzSystems\PlatformUIBundle\Entity\Section;
use eZ\Bundle\EzPublishCoreBundle\Controller;
+use EzSystems\PlatformUIBundle\Entity\SectionList;
+use EzSystems\PlatformUIBundle\Form\Type\SectionListType;
use EzSystems\PlatformUIBundle\Form\Type\SectionType;
use Symfony\Component\HttpFoundation\Request;
use EzSystems\PlatformUIBundle\Helper\SectionHelperInterface;
@@ -32,6 +34,11 @@ class SectionController extends Controller
*/
protected $sectionType;
+ /**
+ * @var \EzSystems\PlatformUIBundle\Form\Type\SectionListType
+ */
+ protected $sectionListType;
+
/**
* @var \Symfony\Component\Routing\RouterInterface
*/
@@ -46,13 +53,15 @@ public function __construct(
SectionHelperInterface $sectionHelper,
SectionType $sectionType,
RouterInterface $router,
- TranslatorInterface $translator
+ TranslatorInterface $translator,
+ SectionListType $sectionListType
)
{
$this->sectionHelper = $sectionHelper;
$this->sectionType = $sectionType;
$this->router = $router;
$this->translator = $translator;
+ $this->sectionListType = $sectionListType;
}
/**
@@ -67,8 +76,8 @@ public function listAction()
return $this->render(
'eZPlatformUIBundle:Section:list.html.twig',
array(
- 'sectionInfoList' => $this->sectionHelper->getSectionList(),
'canCreate' => $this->sectionHelper->canCreate(),
+ 'form' => $this->generateDeleteForm( new SectionList() )->createView()
)
);
}
@@ -78,6 +87,45 @@ public function listAction()
}
}
+ /**
+ * Deletes sections
+ *
+ * @param Request $request
+ *
+ * @return \Symfony\Component\HttpFoundation\RedirectResponse
+ */
+ public function deleteAction( Request $request )
+ {
+ $sectionListToDelete = new SectionList();
+ $form = $this->generateDeleteForm( $sectionListToDelete );
+ $form->handleRequest( $request );
+
+ if ( $form->isValid() )
+ {
+ $this->sectionHelper->deleteSectionList( $sectionListToDelete );
+ }
+
+ return $this->redirect( $this->generateUrl( 'admin_sectionlist' ) );
+ }
+
+ /**
+ * Generate the form object used to delete sections
+ *
+ * @param \EzSystems\PlatformUIBundle\Entity\SectionList $sectionListToDelete sections to be populated/deleted
+ *
+ * @return \Symfony\Component\Form\Form
+ */
+ private function generateDeleteForm( SectionList $sectionListToDelete )
+ {
+ return $this->createForm(
+ $this->sectionListType,
+ $sectionListToDelete,
+ array(
+ 'action' => $this->router->generate( 'admin_sectiondelete' )
+ )
+ );
+ }
+
/**
* Renders the view of a section
* @param mixed $sectionId
diff --git a/Entity/SectionList.php b/Entity/SectionList.php
new file mode 100644
index 000000000..b2498d6a3
--- /dev/null
+++ b/Entity/SectionList.php
@@ -0,0 +1,24 @@
+section = $section;
+ $this->id = $section->id;
+ $this->name = $section->name;
+ $this->identifier = $section->identifier;
$this->contentCount = $contentCount;
$this->canEdit = $canEdit;
$this->canDelete = $canDelete;
diff --git a/Form/Type/SectionListType.php b/Form/Type/SectionListType.php
new file mode 100644
index 000000000..074aeb3ef
--- /dev/null
+++ b/Form/Type/SectionListType.php
@@ -0,0 +1,78 @@
+sectionHelper = $sectionHelper;
+ $this->translator = $translator;
+ }
+
+ public function buildForm( FormBuilderInterface $builder, array $options )
+ {
+ $sectionList = $this->sectionHelper->getSectionList();
+
+ $submitLabel = $this->translator->trans(
+ 'section.remove.selected',
+ array(),
+ 'section'
+ );
+
+ $builder
+ ->add(
+ 'ids',
+ 'choice',
+ array(
+ 'choices' => array( $sectionList ),
+ 'multiple' => true,
+ 'expanded' => true
+ )
+ )
+ ->add( 'delete', 'submit', array( 'label' => $submitLabel ) );
+ }
+
+ public function getName()
+ {
+ return 'sectionlist';
+ }
+
+ public function setDefaultOptions( OptionsResolverInterface $resolver )
+ {
+ $resolver->setDefaults(
+ array( 'data_class' => 'EzSystems\PlatformUIBundle\Entity\SectionList' )
+ );
+ }
+}
diff --git a/Form/Type/SectionType.php b/Form/Type/SectionType.php
index 1f58ca614..67045ba71 100644
--- a/Form/Type/SectionType.php
+++ b/Form/Type/SectionType.php
@@ -12,15 +12,32 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+use Symfony\Component\Translation\TranslatorInterface;
class SectionType extends AbstractType
{
+ /**
+ * @var \Symfony\Component\Translation\TranslatorInterface
+ */
+ private $translator;
+
+ public function __construct( TranslatorInterface $translator )
+ {
+ $this->translator = $translator;
+ }
+
public function buildForm( FormBuilderInterface $builder, array $options )
{
+ $submitLabel = $this->translator->trans(
+ 'section.create.submit',
+ array(),
+ 'section'
+ );
+
$builder
->add( 'name', 'text' )
->add( 'identifier', 'text' )
- ->add( 'save', 'submit' );
+ ->add( 'save', 'submit', array( 'label' => $submitLabel ) );
}
public function getName()
diff --git a/Helper/SectionHelper.php b/Helper/SectionHelper.php
index 72cbd2d34..65e717499 100644
--- a/Helper/SectionHelper.php
+++ b/Helper/SectionHelper.php
@@ -11,6 +11,8 @@
use eZ\Publish\API\Repository\SectionService;
use eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute as AuthorizationAttribute;
use EzSystems\PlatformUIBundle\Entity\EnrichedSection;
+use EzSystems\PlatformUIBundle\Entity\SectionList;
+use EzSystems\PlatformUIBundle\Entity\SectionListItem;
use Symfony\Component\Security\Core\SecurityContextInterface;
use eZ\Publish\API\Repository\Values\Content\Section;
use EzSystems\PlatformUIBundle\Entity\Section as SectionEntity;
@@ -44,7 +46,8 @@ public function getSectionList()
$list = array();
foreach ( $sections as $section )
{
- $list[] = new EnrichedSection(
+ /** @var $section Section */
+ $list[$section->id] = new SectionListItem(
$section,
$this->sectionService->countAssignedContents( $section ),
$this->canUser( 'edit' ),
@@ -120,4 +123,26 @@ public function updateSection( Section $sectionToUpdate, SectionEntity $section)
return $this->sectionService->updateSection( $sectionToUpdate, $sectionUpdateStruct );
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public function deleteSectionList( SectionList $sectionList )
+ {
+ foreach ( $sectionList->ids as $sectionId )
+ {
+ $this->deleteSection( $sectionId );
+ }
+ }
+
+ /**
+ * Removes the section having a given section id
+ *
+ * @param mixed $sectionId to be deleted
+ */
+ private function deleteSection( $sectionId )
+ {
+ $section = $this->sectionService->loadSection( $sectionId );
+ $this->sectionService->deleteSection( $section );
+ }
}
diff --git a/Helper/SectionHelperInterface.php b/Helper/SectionHelperInterface.php
index 42d30ca14..8587394f0 100644
--- a/Helper/SectionHelperInterface.php
+++ b/Helper/SectionHelperInterface.php
@@ -10,6 +10,7 @@
use eZ\Publish\API\Repository\Values\Content\Section;
use EzSystems\PlatformUIBundle\Entity\Section as SectionEntity;
+use EzSystems\PlatformUIBundle\Entity\SectionList;
/**
* Interface SectionHelperInterface
@@ -23,7 +24,7 @@ interface SectionHelperInterface
/**
* Returns the section list
*
- * @return \EzSystems\PlatformUIBundle\Entity\EnrichedSection[]
+ * @return array[] key is section id and value a \EzSystems\PlatformUIBundle\Entity\SectionListItem
*/
public function getSectionList();
@@ -82,4 +83,12 @@ public function createSection( SectionEntity $section );
*/
public function updateSection( Section $sectionToUpdate, SectionEntity $section );
+ /**
+ * Removes sections
+ *
+ * @param \EzSystems\PlatformUIBundle\Entity\SectionList $sectionList sections to be deleted
+ *
+ */
+ public function deleteSectionList( SectionList $sectionList );
+
}
diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml
index 8a0815d4a..41c0f33a4 100644
--- a/Resources/config/routing.yml
+++ b/Resources/config/routing.yml
@@ -58,4 +58,9 @@ admin_sectionedit:
defaults:
_controller: ezsystems.platformui.controller.section:editAction
requirements:
- sectionId: \d+
+ sectionId: \d+
+
+admin_sectiondelete:
+ path: /pjax/section/delete
+ defaults:
+ _controller: ezsystems.platformui.controller.section:deleteAction
diff --git a/Resources/config/services.yml b/Resources/config/services.yml
index 5b36a977a..eea208777 100644
--- a/Resources/config/services.yml
+++ b/Resources/config/services.yml
@@ -7,6 +7,7 @@ parameters:
ezsystems.platformui.controller.section.class: EzSystems\PlatformUIBundle\Controller\SectionController
ezsystems.platformui.controller.template.class: EzSystems\PlatformUIBundle\Controller\TemplateController
ezsystems.platformui.form.type.section.class: EzSystems\PlatformUIBundle\Form\Type\SectionType
+ ezsystems.platformui.form.type.section_list.class: EzSystems\PlatformUIBundle\Form\Type\SectionListType
ezsystems.platformui.controller.pjax.class: EzSystems\PlatformUIBundle\Controller\PjaxController
services:
@@ -50,7 +51,7 @@ services:
- @ezsystems.platformui.form.type.section
- @router
- @translator
- - @session
+ - @ezsystems.platformui.form.type.section_list
parent: ezpublish.controller.base
ezsystems.platformui.helper.section:
@@ -63,3 +64,13 @@ services:
class: %ezsystems.platformui.form.type.section.class%
tags:
- { name: form.section, alias: section }
+ arguments:
+ - @translator
+
+ ezsystems.platformui.form.type.section_list:
+ class: %ezsystems.platformui.form.type.section_list.class%
+ tags:
+ - { name: form.section, alias: section_list }
+ arguments:
+ - @ezsystems.platformui.helper.section
+ - @translator
diff --git a/Resources/public/css/theme/modules/button.css b/Resources/public/css/theme/modules/button.css
index f46b1378c..eb180e5c5 100644
--- a/Resources/public/css/theme/modules/button.css
+++ b/Resources/public/css/theme/modules/button.css
@@ -37,3 +37,8 @@
{
border: 1px solid #bbb;
}
+
+.ez-button-delete:before {
+ content: "\E615";
+ padding-right: 0.5em;
+}
diff --git a/Resources/translations/section.en.xlf b/Resources/translations/section.en.xlf
index 1052d28e3..dee61a097 100644
--- a/Resources/translations/section.en.xlf
+++ b/Resources/translations/section.en.xlf
@@ -78,14 +78,18 @@
A section with this identifier already exists, please enter a different one
-
+
Section can not be found
-
+
The section with the id "%sectionId%" can not be found.
+
+
+ Save
+