Exemple #1
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;
 }