Esempio n. 1
0
 /**
  * @param Form $form
  */
 public function configure(Form $form)
 {
     $form->addGroup();
     $langMode = $form->addSelect('langMode', 'Language mode', ElementEntity::getLangModes());
     $langMode->addCondition($form::EQUAL, ElementEntity::LANGMODE_SPLIT)->toggle('form-group-language');
     $form->setCurrentGroup($form->addGroup()->setOption('id', 'form-group-language'));
     $form->addManyToOne('language', 'Language')->addConditionOn($langMode, $form::EQUAL, ElementEntity::LANGMODE_SPLIT)->addRule($form::FILLED);
     $form->addGroup();
     $mode = $form->addSelect('mode', 'Share data with', ElementEntity::getModes());
     $mode->addCondition($form::IS_IN, array(1))->toggle('form-group-layout')->endCondition()->addCondition($form::IS_IN, array(2, 4))->toggle('form-group-page')->endCondition()->addCondition($form::EQUAL, 4)->toggle('form-group-route');
     $form->addGroup()->setOption('id', 'form-group-layout');
     $form->addManyToOne('layout', 'Layout')->addConditionOn($mode, $form::IS_IN, array(1))->addRule($form::FILLED);
     $form->addGroup()->setOption('id', 'form-group-page');
     $page = $form->addManyToOne('page', 'Page');
     $page->addConditionOn($mode, $form::IS_IN, array(2, 4))->addRule($form::FILLED);
     $form->addGroup()->setOption('id', 'form-group-route');
     $form->addManyToOne('route', 'Route')->setDependOn($page, 'page')->addConditionOn($mode, $form::EQUAL, 4)->addRule($form::FILLED);
     $form->setCurrentGroup();
     $form->addSaveButton('Save');
 }
Esempio n. 2
0
 /**
  * @return ElementEntity
  */
 public function getElement()
 {
     if (!$this->element) {
         $data = array(ElementEntity::LANGMODE_SPLIT => array('langMode' => ElementEntity::LANGMODE_SPLIT, 'language' => $this->languageEntity->id), ElementEntity::LANGMODE_SHARE => array('langMode' => ElementEntity::LANGMODE_SHARE));
         foreach ($data as $i) {
             if ($this->pageEntity && $this->routeEntity) {
                 $this->element = $this->getElementRepository()->findOneBy(array('name' => $this->name, 'page' => $this->pageEntity->id, 'route' => $this->routeEntity->id, 'mode' => ElementEntity::MODE_ROUTE) + $i);
                 if ($this->element) {
                     break;
                 }
             }
             if ($this->pageEntity) {
                 $this->element = $this->getElementRepository()->findOneBy(array('name' => $this->name, 'page' => $this->pageEntity->id, 'mode' => ElementEntity::MODE_PAGE) + $i);
                 if ($this->element) {
                     break;
                 }
             }
             $this->element = $this->getElementRepository()->findOneBy(array('name' => $this->name, 'layout' => $this->layoutEntity->id, 'mode' => ElementEntity::MODE_LAYOUT) + $i);
             if ($this->element) {
                 break;
             }
             $this->element = $this->getElementRepository()->findOneBy(array('name' => $this->name, 'mode' => ElementEntity::MODE_WEBSITE) + $i);
             if ($this->element) {
                 break;
             }
         }
         if (!$this->element) {
             $ret = $this->createEntity();
             $this->element = $ret->getElement();
             if ($entity = $this->getElementRepository()->findOneBy(array('name' => $this->name))) {
                 $this->element->setMode($entity->mode);
             }
             $this->entityManager->persist($ret);
             $this->entityManager->flush($ret);
         }
     }
     return $this->element;
 }
Esempio n. 3
0
 protected function createComponentElementTable()
 {
     $admin = new AdminGrid($this->elementRepository);
     // columns
     $table = $admin->getTable();
     $table->setTranslator($this->translator);
     $table->addColumnText('nameRaw', 'Name')->setSortable()->setFilterText()->setSuggestion();
     $table->getColumn('nameRaw')->getCellPrototype()->width = '23%';
     $table->addColumnText('mode', 'Mode')->setSortable()->setCustomRender(function ($entity) {
         $modes = ElementEntity::getModes();
         return $modes[$entity->mode];
     })->getCellPrototype()->width = '12%';
     $table->addColumnText('langMode', 'Language mode')->setSortable()->setCustomRender(function ($entity) {
         $modes = ElementEntity::getLangModes();
         return $modes[$entity->langMode];
     })->getCellPrototype()->width = '12%';
     $table->addColumnText('page', 'Page')->setSortable()->getCellPrototype()->width = '20%';
     $table->addColumnText('route', 'Route')->setSortable()->getCellPrototype()->width = '20%';
     $table->addColumnText('language', 'Language')->setSortable()->getCellPrototype()->width = '15%';
     // filters
     $table->addFilterSelect('mode', 'Mode', array('' => '') + ElementEntity::getModes());
     $table->addFilterSelect('langMode', 'Mode', array('' => '') + ElementEntity::getLangModes());
     // actions
     if ($this->isAuthorized('edit')) {
         $table->addAction('edit', 'Edit')->getElementPrototype()->class[] = 'ajax';
         $form = $admin->createForm($this->basicFormFactory, 'Element');
         $admin->connectFormWithAction($form, $table->getAction('edit'));
     }
     if ($this->isAuthorized('remove')) {
         $table->addAction('delete', 'Delete')->getElementPrototype()->class[] = 'ajax';
         $admin->connectActionAsDelete($table->getAction('delete'));
     }
     $admin->onRender[] = function (AdminGrid $admin) {
         $qb = $admin->getRepository()->createQueryBuilder('a');
         if (!$admin->parentFloor->floorId) {
             $qb = $qb->andWhere('a.layout IS NULL');
         } else {
             $qb = $qb->andWhere('a.layout = :id')->setParameter('id', $admin->getParentFloor()->floorId);
         }
         $admin->getTable()->setModel(new Doctrine($qb));
     };
     return $admin;
 }