Advertisement
Guest User

ArticleFactory

a guest
Aug 10th, 2012
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.55 KB | None | 0 0
  1. <?php
  2. namespace VKF\Info\FormFactories;
  3.  
  4. use TYPO3\FLOW3\Annotations as FLOW3;
  5. use TYPO3\Form\Core\Model\FormDefinition;
  6.  
  7. class ArticleFactory extends \TYPO3\Form\Factory\AbstractFormFactory {
  8.  
  9.     /**
  10.      * @FLOW3\Inject
  11.      * @var \VKF\Info\Domain\Repository\ArticleGroupRepository
  12.      */
  13.     protected $articleGroupRepository;
  14.  
  15.     /**
  16.      * @FLOW3\Inject
  17.      * @var \VKF\Info\Domain\Repository\BranchRepository
  18.      */
  19.     protected $branchRepository;
  20.  
  21.     /**
  22.      * @FLOW3\Inject
  23.      * @var \VKF\Info\Domain\Repository\ContactRepository
  24.      */
  25.     protected $contactRepository;
  26.  
  27.     /**
  28.      * @FLOW3\Inject
  29.      * @var \VKF\Info\Domain\Repository\CustomerRepository
  30.      */
  31.     protected $customerRepository;
  32.  
  33.     /**
  34.      * @FLOW3\Inject
  35.      * @var \VKF\Info\Domain\Repository\DepartmentRepository
  36.      */
  37.     protected $departmentRepository;
  38.  
  39.     /**
  40.      * @FLOW3\Inject
  41.      * @var \VKF\Info\Domain\Repository\MaterialRepository
  42.      */
  43.     protected $materialRepository;
  44.  
  45.     /**
  46.      * @param array $configuration
  47.      * @param type $presetName
  48.      * @return \TYPO3\Form\Core\Model\FormDefinition
  49.      */
  50.     public function build(array $configuration = null, $presetName = 'default') {
  51.         $formConfiguration = $this->getPresetConfiguration($presetName);
  52.         $form = new FormDefinition('articleForm', $formConfiguration);
  53.  
  54.         $basePage = $form->createPage('basePage');
  55.  
  56.         $name = $basePage->createElement('name', 'TYPO3.Form:SingleLineText');
  57.         $name->setLabel('name:');
  58.         $name->setProperty('placeholder', 'name of article...');
  59.         $name->addValidator(new \TYPO3\FLOW3\Validation\Validator\NotEmptyValidator());
  60.         $name->addValidator(new \TYPO3\FLOW3\Validation\Validator\StringLengthValidator(array(
  61.                 'minimum' => 3,
  62.                 'maximum' => 50
  63.             )));
  64.  
  65.         $description = $basePage->createElement('description', 'TYPO3.Form:MultiLineText');
  66.         $description->setLabel('description:');
  67.         $description->setProperty('placeholder', 'description of article...');
  68.         $description->addValidator(new \TYPO3\FLOW3\Validation\Validator\TextValidator());
  69.  
  70.         $articleGroup = $basePage->createElement('articleGroup', 'TYPO3.Form:SingleSelectDropdown');
  71.         $articleGroup->setLabel('article group:');
  72.         $articleGroup->setProperty('options', $this->articleGroupRepository->findAll());
  73.         $articleGroup->addValidator(new \TYPO3\FLOW3\Validation\Validator\NotEmptyValidator());
  74.         $articleGroup->setRenderingOption('templatePathPattern', 'resource://VKF.Info/Private/Form/Article/SingleSelectDropdown.html');
  75.  
  76.         $branch = $basePage->createElement('branch', 'TYPO3.Form:SingleSelectDropdown');
  77.         $branch->setLabel('branch:');
  78.         $branch->setProperty('options', $this->branchRepository->findAll());
  79.         $branch->addValidator(new \TYPO3\FLOW3\Validation\Validator\NotEmptyValidator());
  80.         $branch->setRenderingOption('templatePathPattern', 'resource://VKF.Info/Private/Form/Article/SingleSelectDropdown.html');
  81.  
  82.         $contact = $basePage->createElement('contact', 'TYPO3.Form:SingleSelectDropdown');
  83.         $contact->setLabel('contact:');
  84.         $contact->setProperty('options', $this->contactRepository->findAll());
  85.         $contact->addValidator(new \TYPO3\FLOW3\Validation\Validator\NotEmptyValidator());
  86.         $contact->setRenderingOption('templatePathPattern', 'resource://VKF.Info/Private/Form/Article/SingleSelectDropdown.html');
  87.  
  88.         $customer = $basePage->createElement('customer', 'TYPO3.Form:SingleSelectDropdown');
  89.         $customer->setLabel('customer:');
  90.         $customer->setProperty('options', $this->customerRepository->findAll());
  91.         $customer->addValidator(new \TYPO3\FLOW3\Validation\Validator\NotEmptyValidator());
  92.         $customer->setRenderingOption('templatePathPattern', 'resource://VKF.Info/Private/Form/Article/SingleSelectDropdown.html');
  93.  
  94.         $department = $basePage->createElement('department', 'TYPO3.Form:SingleSelectDropdown');
  95.         $department->setLabel('department');
  96.         $department->setProperty('options', $this->departmentRepository->findAll());
  97.         $department->addValidator(new \TYPO3\FLOW3\Validation\Validator\NotEmptyValidator());
  98.         $department->setRenderingOption('templatePathPattern', 'resource://VKF.Info/Private/Form/Article/SingleSelectDropdown.html');
  99.  
  100.         $materialPage = $form->createPage('materialPage');
  101.  
  102.         $materials = $materialPage->createElement('materials', 'TYPO3.Form:MultipleSelectCheckboxes');
  103.         $materials->setLabel('materials:');
  104.         $materials->setProperty('options', $this->materialRepository->findAll());
  105.         $materials->addValidator(new \TYPO3\FLOW3\Validation\Validator\NotEmptyValidator());
  106.         $materials->setRenderingOption('templatePathPattern', 'resource://VKF.Info/Private/Form/Article/MultipleSelectCheckboxes.html');
  107.  
  108.         return $form;
  109.     }
  110.  
  111. }
  112.  
  113. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement