Completed
Push — master ( 4284f6...258d83 )
by
unknown
09:47
created

GroupController::createAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace OroCRM\Bundle\ContactBundle\Controller;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
10
11
use Oro\Bundle\SecurityBundle\Annotation\Acl;
12
use Oro\Bundle\SecurityBundle\Annotation\AclAncestor;
13
14
use OroCRM\Bundle\ContactBundle\Entity\Group;
15
16
/**
17
 * @Route("/group")
18
 */
19
class GroupController extends Controller
20
{
21
    /**
22
     * Create group form
23
     *
24
     * @Route("/create", name="orocrm_contact_group_create")
25
     * @Template("OroCRMContactBundle:Group:update.html.twig")
26
     * @Acl(
27
     *      id="orocrm_contact_group_create",
28
     *      type="entity",
29
     *      permission="CREATE",
30
     *      class="OroCRMContactBundle:Group"
31
     * )
32
     */
33
    public function createAction()
34
    {
35
        return $this->update(new Group());
36
    }
37
38
    /**
39
     * Update group form
40
     *
41
     * @Route("/update/{id}", name="orocrm_contact_group_update", requirements={"id"="\d+"}, defaults={"id"=0})
42
     * @Template
43
     * @Acl(
44
     *      id="orocrm_contact_group_update",
45
     *      type="entity",
46
     *      permission="EDIT",
47
     *      class="OroCRMContactBundle:Group"
48
     * )
49
     */
50
    public function updateAction(Group $entity)
51
    {
52
        return $this->update($entity);
53
    }
54
55
    /**
56
     * @Route(
57
     *      "/{_format}",
58
     *      name="orocrm_contact_group_index",
59
     *      requirements={"_format"="html|json"},
60
     *      defaults={"_format" = "html"}
61
     * )
62
     * @Acl(
63
     *      id="orocrm_contact_group_view",
64
     *      type="entity",
65
     *      permission="VIEW",
66
     *      class="OroCRMContactBundle:Group"
67
     * )
68
     * @Template()
69
     */
70
    public function indexAction()
71
    {
72
        return [
73
            'entity_class' => $this->container->getParameter('orocrm_contact.group.entity.class')
74
        ];
75
    }
76
77
    /**
78
     * @param Group $entity
79
     *
80
     * @return array
81
     */
82
    protected function update(Group $entity)
83
    {
84
        if ($this->get('orocrm_contact.form.handler.group')->process($entity)) {
85
            $this->get('session')->getFlashBag()->add(
86
                'success',
87
                $this->get('translator')->trans('orocrm.contact.controller.contact_group.saved.message')
88
            );
89
90
            if (!$this->getRequest()->get('_widgetContainer')) {
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Bundle\Framework...ontroller::getRequest() has been deprecated with message: since version 2.4, to be removed in 3.0. Ask Symfony to inject the Request object into your controller method instead by type hinting it in the method's signature.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
91
                return $this->get('oro_ui.router')->redirect($entity);
92
            }
93
        }
94
95
        return array(
96
            'entity'           => $entity,
97
            'form'             => $this->get('orocrm_contact.form.group')->createView(),
98
            'showContactsGrid' => count($this->get('orocrm_contact.contact.manager')->getList()) ? true : false
99
        );
100
    }
101
}
102