Exemplo n.º 1
0
 protected function createComponentProviderForm()
 {
     $_this = $this;
     $this->providerFormFactory->setProvider($this->provider);
     $form = $this->providerFormFactory->invoke();
     $form['cancel']->onClick[] = function () use($_this) {
         $_this->redirect('this', array('provider' => NULL));
     };
     $form->onSuccess[] = $this->providerFormSuccess;
     return $form;
 }
Exemplo n.º 2
0
 protected function createComponentLoginTable()
 {
     $_this = $this;
     $data = array();
     foreach ($this->securityManager->getLoginProviders() as $name) {
         $data[] = array('id' => str_replace(' ', '_', $name), 'name' => $name);
     }
     $admin = new AdminGrid($this->loginRepository);
     // columns
     $table = $admin->getTable();
     $table->setModel(new ArraySource($data));
     $table->setTranslator($this->translator);
     $table->addColumnText('name', 'Name')->getCellPrototype()->width = '100%';
     /** @var UserEntity $user */
     $user = $this->user->identity;
     $securityManager = $this->securityManager;
     $providerFormFactory = $this->providerFormFactory;
     // actions
     $table->addAction('connect', 'Connect')->setCustomRender(function ($entity, $element) use($securityManager, $user) {
         if ($user->hasLoginProvider($entity['name'])) {
             $element->class[] = 'disabled';
         } else {
             $element->class[] = 'btn-primary';
         }
         return $element;
     });
     $table->getAction('connect')->onClick[] = function ($button, $name) use($_this, $securityManager, $providerFormFactory, $user) {
         if (!$securityManager->getLoginProviderByName(str_replace('_', ' ', $name))->getFormContainer()) {
             $_this->redirect('connect!', str_replace('_', ' ', $name));
         } else {
             $_this->provider = str_replace('_', ' ', $name);
             $providerFormFactory->setProvider($_this->provider);
         }
     };
     $table->getAction('connect');
     $this->providerFormFactory->setUser($user);
     if ($this->provider) {
         $this->providerFormFactory->setProvider($this->provider);
     }
     $this->providerFormFactory->onSave[] = function (Form $form) use($_this) {
         $_this->redirect('connect!', array($form['provider']->value, json_encode($form['parameters']->values)));
     };
     $this->providerFormFactory->onSuccess[] = function ($parameters) use($_this) {
         $_this->redirect('this');
     };
     $form = $admin->createForm($this->providerFormFactory, 'Provider');
     $admin->connectFormWithAction($form, $table->getAction('connect'));
     $table->addAction('disconnect', 'Disconnect')->setCustomRender(function ($entity, $element) use($securityManager, $user) {
         if (!$user->hasLoginProvider($entity['name'])) {
             $element->class[] = 'disabled';
         }
         return $element;
     })->setConfirm(function ($entity) {
         return "Really disconnect from '{$entity['name']}'?";
     });
     $table->getAction('disconnect')->onClick[] = function ($button, $name) use($_this) {
         $_this->handleDisconnect(str_replace('_', ' ', $name));
     };
     $table->getAction('disconnect')->getElementPrototype()->class[] = 'ajax';
     return $admin;
 }