@param string $widgetType
@param User   $user

@return AbstractWidget
181021
public function getNewDataWidget($widgetType, User $user)
    {
        $widget = $this->widgetFactory->createDataWidget($widgetType);
        $widget
            ->setId(uniqid())
            ->setUser($user);

        return $widget;
    }
1222171
protected function createWidget()
    {
        $type   = $this->widgetData('type');
        $widget = $this->resolveWidget($type);

        if ($this instanceof ObjectContainerInterface && $widget instanceof ObjectContainerInterface) {
            if (empty($widget->objType())) {
                $widget->setObjType($this->objType());
            }

            if (empty($widget->objId()) && !empty($this->objId())) {
                $widget->setObjId($this->objId());
            }
        }

        $widget->setData($this->widgetData());
        $widget->setData($this->renderableData());

        return $widget;
    }
518181
public function createWidgetSession(array $allowedTypes = null, $recipient = null, $backupCodeIdentifier = null, $totpIdentifier = null, $issuer = null)
    {
        $widgetSession = $this->factory->createWidgetSession($allowedTypes, $recipient, $backupCodeIdentifier, $totpIdentifier, $issuer);

        return $widgetSession;
    }
616285
public function isWidgetTypeExists($widgetType)
    {
        $widgetsConfig = $this->getWidgetsConfig();
        $isWidgetTypeExists = false;

        if (isset($widgetsConfig[$widgetType])) {
            $isWidgetTypeExists = true;
        }

        return $isWidgetTypeExists;
    }
212660
public function create(User $user, $data)
    {
        $dashboard = new Dashboard();
        $dashboard->setCreator($user);
        $dashboard->setName($data['name']);
        $wId = $data['workspace']['id'];
        $dashboard->setWorkspace($this->workspaceManager->getWorkspaceById($wId));
        $this->em->persist($dashboard);
        $this->em->flush();

        return $this->exportDashboard($dashboard);
    }
938510
public function getAllAction(Request $request, User $loggedUser)
    {
        $this->checkPortfolioToolAccess();

        $widgets = $this->getWidgetsManager()->getWidgets($loggedUser);

        $data = [];

        foreach ($widgets as $widget) {
            $data[] = $this->getWidgetsManager()->getWidgetData($widget);
        }

        $response = new JsonResponse();
        $response->setData($data);

        return $response;
    }
334002
protected function CanEdit(User $user)
    {
        return self::Guard()->Allow(BackendAction::Edit(), $user)&&
            self::Guard()->Allow(BackendAction::UseIt(), new UserForm());
    }
943462
public function addUser(\FOM\UserBundle\Entity\User $user)
    {
        $this->users[] = $user;
        $user->addGroup($this);
        return $this;
    }
1187980
private function createRegisterForm(User $user)
    {
        $form = $this->createForm(new UserRegisterType(), $user, array(
            'action' => $this->generateUrl('amulen_user_register_do'),
            'method' => 'POST',
        ));

        $form->add('submit', 'submit', array('label' => 'Register'));

        return $form;
    }
663327
public function findByWidgetTypeAndUser($type, User $user, $executeQuery = true)
    {
        $queryBuilder = $this->createQueryBuilder('w')
            ->andWhere($this->getWigetInstanceString($type))
            ->andWhere('w.user = :user')
            ->setParameter('user', $user)
        ;

        return $executeQuery ? $queryBuilder->getQuery()->getResult() : $queryBuilder->getQuery();
    }
841808
protected <W extends Widget> W widget(WidgetFactory<W> factory,
      WidgetInitializer<W> initializers) {
    return widget(get(0), factory, initializers);
  }
221003
private function createAddLinkGroupCenterForm(User $user)
    {
        return $this->createFormBuilder()
                ->setAction($this->generateUrl('admin_user_add_group_center', 
                        array('uid' => $user->getId())))
                ->setMethod('POST')
                ->add(self::FORM_GROUP_CENTER_COMPOSED, new ComposedGroupCenterType())
                ->add('submit', 'submit', array('label' => 'Add a new groupCenter'))
                ->getForm()
                ;
    }
12895
public function putAction(Request $request, User $loggedUser, $type, $widgetId)
    {
        $this->checkPortfolioToolAccess($loggedUser);

        $widgetFindEvent = new WidgetFindEvent($widgetId, $type, $loggedUser);

        $this->get('event_dispatcher')->dispatch('icap_portfolio_widget_find_'.$type, $widgetFindEvent);

        $data = $this->getWidgetsManager()->handle($widgetFindEvent->getWidget(), $type, $request->request->all(), $this->get('kernel')->getEnvironment());

        $response = new JsonResponse();
        $response->setData($data);

        return $response;
    }
1267897
public function regenerateApiKey(User $user)
    {
        $user->api_key = User::generateApiKey();
        $user->save();

        event(new UserRegeneratedApiTokenEvent($user));

        return cachet_redirect('dashboard.user');
    }
390187
public function getFormView($widgetType)
    {
        $widgetFormViewEvent = new WidgetFormViewEvent($widgetType);

        $this->eventDispatcher->dispatch('icap_portfolio_widget_form_view_'.$widgetType, $widgetFormViewEvent);

        return $widgetFormViewEvent->getFormView();
    }
701028
public function removeUser(User $user)
    {
        if ($this->users->contains($user)) {
            $this->users->removeElement($user);
        }

        return $this;
    }
134654
public function createWidgetRegisterSession(array $allowedTypes = null, $recipient = null, $backupCodeIdentifier = null, $totpIdentifier = null, $issuer = null)
    {
        $widgetRegisterSession = $this->createEmptyWidgetRegisterSession();

        if ($allowedTypes !== null) {
            $widgetRegisterSession->setAllowedTypes($allowedTypes);
        }

        if ($recipient !== null) {
            $widgetRegisterSession->setRecipient($recipient);
        }
        if ($backupCodeIdentifier !== null) {
            $widgetRegisterSession->setBackupCodeIdentifier($backupCodeIdentifier);
        }

        if ($totpIdentifier !== null) {
            $widgetRegisterSession->setTotpIdentifier($totpIdentifier);
        }

        if ($issuer !== null) {
            $widgetRegisterSession->setIssuer($issuer);
        }

        return $widgetRegisterSession;
    }