Forms based on user data
We had previously defined our form type as a service, so now we will change its configuration for it to take the user_locator
service as the second argument, as shown in the following code:
khepin.form.type.coordinate: class: Khepin\BookBundle\Form\CoordinateType scope: prototype arguments: [@ivory_google_map.map, @user_locator] tags: - { name: form.type, alias: coordinate }
If you recall correctly, the user_locator
service was in the request
scope, but our form type is in the prototype
scope. Since the prototype
scope is more restrictive than the request
scope, we don't have any issues here.
We will also update the default values of CoordinateType
using the following code so that it always has a default value, which will be an empty coordinate:
public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults([ 'widget' => 'coordinate', 'compound' => false, 'data_class' => ...