function it_does_not_remove_user_form_type_if_users_data_is_submitted(FormEvent $event, Form $form) { $event->getData()->willReturn(['user' => ['plainPassword' => 'test']]); $event->getForm()->shouldNotBeCalled(); $form->remove('user')->shouldNotBeCalled(); $this->preSubmit($event); }
/** * @param array $data * @param Form $form * @return string */ protected function aggregatePluralValues(&$data, $form) { $labelManager = $this->labelManager; $labelValue = ''; $standardRules = array(); $explicitRules = array(); foreach ($data as $property => $value) { if (0 === strpos($property, self::PLURAL_FIELD_PREFIX)) { $pluralForm = substr($property, strlen(self::PLURAL_FIELD_PREFIX)); if (is_numeric($pluralForm)) { $standardRules[$pluralForm] = $value; } else { $explicitRules[$pluralForm] = sprintf('%s %s', $labelManager->reverseTransformInterval($pluralForm), $value); } $form->remove($property); unset($data[$property]); } } if ($standardRules) { $labelValue = implode('|', $standardRules); if ($explicitRules) { $labelValue .= '|' . implode('|', $explicitRules); } } elseif ($explicitRules) { $labelValue = implode('|', $explicitRules); } return $labelValue; }
/** * Remove duplicate fields from the form * * @param Form $form * @param array &$existingFields */ protected function removeDuplicateFields(Form $form, array &$existingFields) { foreach (array_keys($form->all()) as $field) { if (in_array($field, $existingFields)) { $form->remove($field); } else { $existingFields[] = $field; } } }
/** * This function remove fields available if there are not present in the $data array * The data array might come from $request->request->all(). * * This can be usefull if you don't want to send all fields will building an api. As missing * fields will be threated like null values. * * @param array $data * @param Form $form */ public static function removeFields(array $data, Form $form) { $diff = array_diff(array_keys($form->all()), array_keys($data)); foreach ($diff as $key) { $form->remove($key); } foreach ($data as $name => $value) { if (!is_array($value)) { continue; } self::removeFields($value, $form[$name]); } }
public function __construct(Form $form, Request $request, UserManagerInterface $userManager) { // borrando campos no necesarios $form->remove('gender'); $form->remove('website'); $form->remove('biography'); $form->remove('timezone'); $form->remove('phone'); $form->remove('locale'); $form->remove('dateOfBirth'); // cargando nuevos campos $form->add('username', null, array('label' => 'Name of User')); $form->add('email'); $form->add('organization'); // $form->add('gravatar', 'file', array( // 'mapped' => false, // 'attr' => ['class' => 'filestyle','data-buttonBefore'=> 'true', 'data-buttonText' => 'Choose file' ] // )); parent::__construct($form, $request, $userManager); }
public function testRemoveUnsetsFieldParent() { $form = new Form('author'); $field = $this->createMockField('firstName'); $field->expects($this->exactly(2))->method('setParent'); // PHPUnit fails to compare subsequent method calls with different arguments $form->add($field); $form->remove('firstName'); }
/** * Remove unnecessary fields from form * * @param array $requestData * @param Form $form */ private function cleanForm($requestData, Form $form) { $allowedField = array_keys($requestData); /** @var FormInterface[] $formFields */ $formFields = $form->all(); foreach ($formFields as $formField) { $fieldName = $formField->getName(); if (!in_array($fieldName, $allowedField)) { $form->remove($fieldName); } } }
private function filterForm(Form $form, $array_path, $level = 0) { $formChildren = $form->all(); foreach ($formChildren as $formChild) { if ($formChild->getName() != $array_path[$level] && $formChild->getName() != '_token' && $formChild->getName() != 'submit') { $form->remove($formChild->getName()); } else { if (count($array_path) > $level + 1 && $formChild->getName() != '_token' && $formChild->getName() != 'submit') { $this->filterForm($formChild, $array_path, $level + 1); } } } }