/** * @return UserFiedlset */ public function addRoleCommunity() { $collectionRole = new Element\Collection('roles'); $collectionRole->setCount(2)->setAllowAdd(true)->setShouldCreateTemplate(true)->setTargetElement(new AssertRoleCommunityFiedlset()); $this->add($collectionRole); return $this; }
/** * Only render a template * * @param CollectionElement $collection * @return string */ public function renderTemplate(CollectionElement $collection) { if ($sElementLayout = $collection->getOption('twb-layout')) { $elementOrFieldset = $collection->getTemplateElement(); $elementOrFieldset->setOption('twb-layout', $sElementLayout); } return parent::renderTemplate($collection); }
/** * Only render a template * * @param Collection $collection * @param string $templatePartial * * @return string */ public function renderTemplate(Collection $collection, $templatePartial) { $escapeHtmlAttribHelper = $this->getEscapeHtmlAttrHelper(); $elementOrFieldset = $collection->getTemplateElement(); $partialHelper = $this->getPartialHelper(); $replaceIndex = $collection->getTemplatePlaceholder(); $templateMarkup = $partialHelper($templatePartial, ['collection' => $elementOrFieldset]); return sprintf($this->getTemplateWrapper(), $escapeHtmlAttribHelper($templateMarkup), $replaceIndex); }
/** * Only render a template * * @param CollectionElement $collection * @return string */ public function renderTemplate(CollectionElement $collection) { $escapeHtmlAttribHelper = $this->getEscapeHtmlAttrHelper(); $fieldsetHelper = $this->getFieldsetHelper(); $templateMarkup = ''; $elementOrFieldset = $collection->getTemplateElement(); if ($elementOrFieldset instanceof FieldsetInterface) { $templateMarkup .= $fieldsetHelper($elementOrFieldset, $this->shouldWrap()); } elseif ($elementOrFieldset instanceof ElementInterface) { $templateMarkup .= Form::row($elementOrFieldset); } return sprintf($this->getTemplateWrapper(), $escapeHtmlAttribHelper($templateMarkup)); }
public function renderTemplate(CollectionElement $collection) { $elementHelper = $this->getElementHelper(); $escapeHtmlAttribHelper = $this->getEscapeHtmlAttrHelper(); $templateMarkup = ''; $elementOrFieldset = $collection->getTemplateElement(); if ($elementOrFieldset instanceof FieldsetInterface) { $templateMarkup .= $this->render($elementOrFieldset, $collection->allowRemove()); } elseif ($elementOrFieldset instanceof ElementInterface) { $templateMarkup .= $elementHelper($elementOrFieldset); } return sprintf('<span data-template="%s"></span>', $escapeHtmlAttribHelper($templateMarkup)); }
public function addElements() { // File Input $file = new Element\File('file'); $file->setLabel('Multi File'); $fileCollection = new Element\Collection('file-collection'); $fileCollection->setOptions(array('count' => $this->numFileElements, 'allow_add' => false, 'allow_remove' => false, 'target_element' => $file)); $this->add($fileCollection); // Text Input $text = new Element\Text('text'); $text->setLabel('Text Entry'); $this->add($text); }
/** * @param \Phpro\AnnotatedForms\Event\FormEvent $event * @param \Zend\Form\Form $form * @param \Zend\Form\Element\Collection $collection * @param \Zend\Form\InputFilterProviderFieldset $fieldset * @param \Zend\InputFilter\InputFilter $inputFilter */ public function it_should_configure_collection_input_providers($event, $form, $collection, $fieldset, $inputFilter) { $event->getTarget()->willReturn($form); $form->getFieldsets()->willReturn(array($collection)); $form->getInputFilter()->willReturn($inputFilter); $collection->getName()->willReturn('collection'); $collection->getTargetElement()->willReturn($fieldset); $collection->getFieldsets()->willReturn(array($fieldset)); $fieldset->getFieldsets()->willReturn(array()); $fieldset->getInputFilterSpecification()->willReturn(array('name' => array('required' => true))); $this->configureCollectionInputFilter($event); $inputFilter->remove('collection')->shouldHaveBeenCalled(); $inputFilter->add(Argument::type('Zend\\InputFilter\\CollectionInputFilter'), 'collection')->shouldHaveBeenCalled(); }
public function __construct($name = null, $options = array()) { $defaults = array('count' => 0); $options = array_merge($defaults, $options); $this->setAttribute('class', 'template'); parent::__construct($name, $options); $this->setShouldCreateTemplate(true); }
/** * Set the target element * * @param ElementInterface|array|\Traversable $elementOrFieldset * @return Collection * @throws \Zend\Form\Exception\InvalidArgumentException */ public function setTargetElement($elementOrFieldset) { parent::setTargetElement($elementOrFieldset); if ($this->targetElement instanceof FieldsetInterface) { $this->targetElement->setHydrator(new Traversable()); } return $this; }
/** * @param Collection $collection */ protected function configureInputFilter(Collection $collection) { // Make it a collection input filter $inputFilter = new CollectionInputFilter(); $inputFilter->setIsRequired(false); // Add the input filter of the target document as the real input filter: $targetElement = $collection->getTargetElement(); if ($targetElement instanceof InputFilterProviderInterface) { $configuredFilter = $targetElement->getInputFilterSpecification(); $inputFilter->setInputFilter($configuredFilter); } // Replace the current input filter in the actual form: $collectionName = $collection->getName(); $formFilter = $this->form->getInputFilter(); $formFilter->remove($collectionName); $formFilter->add($inputFilter, $collectionName); }
/** * @param \Zend\Form\Element\Collection $collection * * @return string */ protected function renderTemplate($collection) { $templateMarkup = ''; $escapeHtmlAttribHelper = $this->getEscapeHtmlAttrHelper(); $elementOrFieldset = $collection->getTemplateElement(); if ($elementOrFieldset instanceof FieldsetInterface) { $templateMarkup .= $this->render($elementOrFieldset); } return sprintf('<span class="game-template" data-template="%s"></span>', $escapeHtmlAttribHelper($templateMarkup)); }
public function __construct() { parent::__construct('resp-resource'); $this->setAttribute('method', 'post'); $this->add(new Element\Hidden('id_resp')); $id_resource = new Element\Select('id_resource'); $id_resource->setLabel('Resource')->setAttributes(array('class' => 'medwhite')); $this->add($id_resource); $nid_lov_controltype = new Element\Collection('nid_lov_controltype'); $nid_lov_controltype->setLabel('Control Type')->setAttributes(array('class' => 'medwhite')); $this->add($nid_lov_controltype); $comment = new Element\Textarea('comment'); $comment->setLabel('Comment')->setAttributes(array('class' => 'smallwhite')); $this->add($comment); $back = new Element\Button('back'); $back->setLabel('Back')->setAttributes(array('id' => 'backbutton', 'class' => 'btn-success', 'style' => 'margin-right:100px;', 'onclick' => '')); $this->add($back); $submit = new Element\Submit('submit'); $submit->setValue('Go')->setAttributes(array('id' => 'submitbutton', 'class' => 'btn-success')); $this->add($submit); }
public function setObject($object) { if (!$object instanceof PermissionsInterface) { throw new \InvalidArgumentException('Object must be of type "\\Core\\Entity\\PermissionsInterface"'); } $assigned = $object->getAssigned(); $array = array(); foreach ($assigned as $resourceId => $spec) { } if (isset($assigned['groups'])) { foreach ($assigned['groups'] as $name => $spec) { $array[] = array('type' => 'group', 'id' => $name, 'permissions' => $spec['permissions']); } } if (isset($assigned['users'])) { foreach ($assigned['users'] as $id => $permission) { $array[] = array('type' => 'user', 'id' => $id, 'permissions' => $permissions); } } $this->permissionsObject = $object; return parent::setObject($array); }
/** * Only render a template * * @param CollectionElement $collection * @return string */ public function renderTemplate(CollectionElement $collection) { $templateMarkup = ''; $elementOrFieldset = $collection->getTemplateElement(); if ($elementOrFieldset instanceof FieldsetInterface) { $templateMarkup .= $this->render($elementOrFieldset); } return $templateMarkup; }
/** * @group ZF2-336 */ public function testCanAddFileEnctypeFromCollectionAttribute() { $file = new Element\File('file_resource'); $file ->setOptions(array()) ->setLabel('File'); $fileCollection = new Element\Collection('collection'); $fileCollection->setOptions(array( 'count' => 2, 'allow_add' => false, 'allow_remove' => false, 'target_element' => $file, )); $this->form->add($fileCollection); $this->form->prepare(); $enctype = $this->form->getAttribute('enctype'); $this->assertNotEmpty($enctype); $this->assertEquals($enctype, 'multipart/form-data'); }
public function createService(ServiceLocatorInterface $serviceLocator) { $collection = new Collection('educations'); $collection->setLabel('Education history')->setCount(0)->setShouldCreateTemplate(true)->setAllowAdd(true)->setTargetElement($serviceLocator->get('EducationFieldset')); return $collection; }
public function testRendersCollectionAsExpected() { $element = new Element\Collection(); $element->setLabel('foo'); $markup = $this->helper->render($element); $this->assertContains('<legend>foo</legend>', $markup); }
public function testDonNotApplyEmptyInputFiltersToSubFieldsetOfCollectionElementsWithCollectionInputFilters() { $collectionFieldset = new Fieldset('item'); $collectionFieldset->add(new Element('foo')); $collection = new Element\Collection('items'); $collection->setCount(3); $collection->setTargetElement($collectionFieldset); $this->form->add($collection); $inputFilterFactory = new InputFilterFactory(); $inputFilter = $inputFilterFactory->createInputFilter(array('items' => array('type' => 'Zend\\InputFilter\\CollectionInputFilter', 'input_filter' => new InputFilter()))); $this->form->setInputFilter($inputFilter); $this->assertInstanceOf('Zend\\InputFilter\\CollectionInputFilter', $this->form->getInputFilter()->get('items')); $this->assertCount(1, $this->form->getInputFilter()->get('items')->getInputs()); }
/** * @see Zend\Form\Element::__construct() */ public function __construct($name = null, $options = []) { parent::__construct($name, $options); $this->attributes['type'] = 'fieldset'; }
/** * Only render a template * * @param Collection $collection * @return string */ public function renderTemplate(Collection $collection) { $escapeHtmlAttribHelper = $this->getEscapeHtmlAttrHelper(); $fieldSetHelper = $this->getFieldsetHelper(); $templateMarkup = ''; $elementOrFieldSet = $collection->getTemplateElement(); if ($elementOrFieldSet instanceof AbstractLineFieldSet) { $templateMarkup .= sprintf($this->rowWrap, $this->getLineType(), $fieldSetHelper($elementOrFieldSet, $this->shouldWrap()), ucfirst($this->getLineType())); } return sprintf($this->getTemplateWrapper(), $this->getLineType(), $escapeHtmlAttribHelper($templateMarkup)); }
/** * @param Collection $collection * @return string */ protected function renderHiddenElement(Collection $collection) { if ($collection->getOption('count') == 0) { $hidden = $this->getView()->plugin('formHidden'); return $hidden($collection) . "\n"; } }
/** * {@inheritDoc} */ public function setObject($object) { return CollectionElement::setObject($object); }
public function testPopulateValuesWithFirstKeyGreaterThanZero() { $inputData = array(1 => array('name' => 'black'), 5 => array('name' => 'white')); // Standalone Collection element $collection = new Collection('fieldsets', array('count' => 1, 'target_element' => new \ZendTest\Form\TestAsset\CategoryFieldset())); $form = new Form(); $form->add(array('type' => 'Zend\\Form\\Element\\Collection', 'name' => 'collection', 'options' => array('count' => 1, 'target_element' => new \ZendTest\Form\TestAsset\CategoryFieldset()))); // Collection element attached to a form $formCollection = $form->get('collection'); $collection->populateValues($inputData); $formCollection->populateValues($inputData); $this->assertEquals(count($collection->getFieldsets()), count($inputData)); $this->assertEquals(count($formCollection->getFieldsets()), count($inputData)); }