src/Component/Frontend/StructureModal/StructureModal.php
protected function createComponentFormMain() : Form
    {
        $recipeSlug = $this->getRecipeSlug();
        $structure = $this->getStructure();
        $parents = $this->getParentsExceptSubParents();

        $categories = $this->getCategories();

        $form = new Form;

        $form->addText('createdAt')
            ->setRequired('Datum vytvoření je povinný.')
            ->addRule(Form::PATTERN, "Datum vytvoření musí být ve formátu: 24.8.2018 08:59:01.", self::REGEX_DATETIME);

        $form->addText('updatedAt')
            ->setDisabled(TRUE);

        $form->addCheckboxList('categories', NULL, $categories)
            ->setRequired(FALSE);
            //->setRequired('Minimálně jedna kategorie je povinná.');

        if ($recipeSlug->getRecipe()->getMaxCategories() > 0)
        {
            $form->getComponent('categories')
                ->addRule(Form::MAX_LENGTH, 'Maximální počet kategorií je %d.', $recipeSlug->getRecipe()->getMaxCategories());
        }

        $form->addSelect('parent', NULL, $parents)
            ->setRequired(FALSE);

        $form->addSubmit('save');

        if (!$this->getStructure())
        {
            foreach ($form->getComponents() as $component)
            {
                $component->setDisabled(TRUE);
            }
        }

        if ($structure)
        {
            $parent = $structure->getParent();

            $parentId = $parent && !$parent->isRoot() ? $parent->getId() : -1;

            //$parentId = key_exists($parentId, $parents) ? $parentId : -1;

            $form->setDefaults([
                'createdAt' => $structure->getCreatedAt()->format(self::FORMAT_DATETIME),
                'updatedAt' => $structure->getUpdatedAt()->format(self::FORMAT_DATETIME),
                'categories' => array_keys(
                    $this->structureInCategoryRepository
                        ->findByStructure($structure)
                        ->toKeyIndex('CategoryId')
                ),
                'parent' => $parentId,
            ]);
        }

        $form->onValidate[] = function (Form $form) { $this->validate($form); };
        $form->onSuccess[] = function (Form $form) { $this->successMain($form); };

        if (!$this->presenter->user->isAllowed(StructureAuthorizator::RES_STRUCTURE_MODAL))
        {
            $this->setDisabledForm($form, TRUE);
        }

        return $form;
    }
protected function createComponentFormMain() : Form
    {
        $recipeSlug = $this->getRecipeSlug();
        $structure = $this->getStructure();
        $parents = $this->getParentsExceptSubParents();

        $categories = $this->getCategories();

        $form = new Form;

        $form->addText('createdAt')
            ->setRequired('Datum vytvoření je povinný.')
            ->addRule(Form::PATTERN, "Datum vytvoření musí být ve formátu: 24.8.2018 08:59:01.", self::REGEX_DATETIME);

        $form->addText('updatedAt')
            ->setDisabled(TRUE);

        $form->addCheckboxList('categories', NULL, $categories)
            ->setRequired(FALSE);
            //->setRequired('Minimálně jedna kategorie je povinná.');

        if ($recipeSlug->getRecipe()->getMaxCategories() > 0)
        {
            $form->getComponent('categories')
                ->addRule(Form::MAX_LENGTH, 'Maximální počet kategorií je %d.', $recipeSlug->getRecipe()->getMaxCategories());
        }

        $form->addSelect('parent', NULL, $parents)
            ->setRequired(FALSE);

        $form->addSubmit('save');

        if (!$this->getStructure())
        {
            foreach ($form->getComponents() as $component)
            {
                $component->setDisabled(TRUE);
            }
        }

        if ($structure)
        {
            $parent = $structure->getParent();

            $parentId = $parent && !$parent->isRoot() ? $parent->getId() : -1;

            //$parentId = key_exists($parentId, $parents) ? $parentId : -1;

            $form->setDefaults([
                'createdAt' => $structure->getCreatedAt()->format(self::FORMAT_DATETIME),
                'updatedAt' => $structure->getUpdatedAt()->format(self::FORMAT_DATETIME),
                'categories' => array_keys(
                    $this->structureInCategoryRepository
                        ->findByStructure($structure)
                        ->toKeyIndex('CategoryId')
                ),
                'parent' => $parentId,
            ]);
        }

        $form->onValidate[] = function (Form $form) { $this->validate($form); };
        $form->onSuccess[] = function (Form $form) { $this->successMain($form); };

        if (!$this->presenter->user->isAllowed(StructureAuthorizator::RES_STRUCTURE_MODAL))
        {
            $this->setDisabledForm($form, TRUE);
        }

        return $form;
    }
protected function createComponentFormMain ( ) : Form { $ recipeSlug = $ this -> getRecipeSlug ( ) ; $ structure = $ this -> getStructure ( ) ; $ parents = $ this -> getParentsExceptSubParents ( ) ; $ categories = $ this -> getCategories ( ) ; $ form = new Form ; $ form -> addText ( 'createdAt' ) -> setRequired ( 'Datum vytvoření je povinný.') -> addRule ( Form :: PATTERN , "Datum vytvoření musí být ve formátu: 24.8.2018 08:59:01.", sel f :REG EX _DATETIME); $ form -> addText ( 'updatedAt' ) -> setDisabled ( TRUE ) ; $ form -> addCheckboxList ( 'categories' , NULL , $ categories ) -> setRequired ( FALSE ) ; //->setRequired('Minimálně jedna kategorie je povinná.'); if ( $ recipeSlug -> getRecipe ( ) -> getMaxCategories ( ) > 0 ) { $ form -> getComponent ( 'categories' ) -> addRule ( Form :: MAX_LENGTH , 'Maximální počet kategorií je %d.', $r e i peSlug->ge tR ecipe()-> g e tM axCategories()); } $ form -> addSelect ( 'parent' , NULL , $ parents ) -> setRequired ( FALSE ) ; $ form -> addSubmit ( 'save' ) ; if ( ! $ this -> getStructure ( ) ) { foreach ( $ form -> getComponents ( ) as $ component ) { $ component -> setDisabled ( TRUE ) ; } } if ( $ structure ) { $ parent = $ structure -> getParent ( ) ; $ parentId = $ parent && ! $ parent -> isRoot ( ) ? $ parent -> getId ( ) : - 1 ; //$parentId = key_exists($parentId, $parents) ? $parentId : -1; $ form -> setDefaults ( [ 'createdAt' => $ structure -> getCreatedAt ( ) -> format ( self :: FORMAT_DATETIME ) , 'updatedAt' => $ structure -> getUpdatedAt ( ) -> format ( self :: FORMAT_DATETIME ) , 'categories' => array_keys ( $ this -> structureInCategoryRepository -> findByStructure ( $ structure ) -> toKeyIndex ( 'CategoryId' ) ) , 'parent' => $ parentId , ] ) ; } $ form -> onValidate [ ] = function ( Form $ form ) { $ this -> validate ( $ form ) ; } ; $ form -> onSuccess [ ] = function ( Form $ form ) { $ this -> successMain ( $ form ) ; } ; if ( ! $ this -> presenter -> user -> isAllowed ( StructureAuthorizator :: RES_STRUCTURE_MODAL ) ) { $ this -> setDisabledForm ( $ form , TRUE ) ; } return $ form ; }
Main form
@return Form
@throws \Propel\Runtime\Exception\PropelException
Main form