public function testComponentRestrictionsWithValidComponentRestrictions() { $componentRestrictions = array(AutocompleteComponentRestriction::COUNTRY => 'fr'); $this->autocomplete->setComponentRestrictions($componentRestrictions); $this->assertSame($componentRestrictions, $this->autocomplete->getComponentRestrictions()); $this->assertTrue($this->autocomplete->hasComponentRestrictions()); $this->assertSame($componentRestrictions, $this->autocomplete->getComponentRestrictions()); $this->assertTrue($this->autocomplete->hasComponentRestriction(AutocompleteComponentRestriction::COUNTRY)); $this->assertSame($componentRestrictions[AutocompleteComponentRestriction::COUNTRY], $this->autocomplete->getComponentRestriction(AutocompleteComponentRestriction::COUNTRY)); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $autocomplete = new Autocomplete(); if ($options['prefix'] !== null) { $autocomplete->setPrefixJavascriptVariable($options['prefix']); } if ($options['bound'] !== null) { if (is_array($options['bound'])) { call_user_func_array(array($autocomplete, 'setBound'), $options['bound']); } else { $autocomplete->setBound($options['bound']); } } if (!empty($options['types'])) { $autocomplete->setTypes($options['types']); } if (!empty($options['component_restrictions'])) { $autocomplete->setComponentRestrictions($options['component_restrictions']); } if ($options['attr']) { foreach ($options['attr'] as $name => $value) { $autocomplete->setInputAttribute($name, $value); } } $autocomplete->setAsync($options['async']); $autocomplete->setLanguage($options['language']); $builder->setAttribute('autocomplete', $autocomplete); }
public function testRenderAutocompleteWithTypesAndComponentRestrictionsAndBound() { $autocomplete = new Autocomplete(); $autocomplete->setJavascriptVariable('autocomplete'); $autocomplete->setTypes(array(AutocompleteType::ESTABLISHMENT, AutocompleteType::CITIES)); $autocomplete->setComponentRestrictions(array(AutocompleteComponentRestriction::COUNTRY => 'fr')); $autocomplete->setBound(1, 2, 3, 4); $autocomplete->getBound()->setJavascriptVariable('bound'); $expected = <<<EOF autocomplete = new google.maps.places.Autocomplete(document.getElementById('place_input'), {"types":["establishment","(cities)"],"bounds":bound,"componentRestrictions":{"country":"fr"}}); EOF; $this->assertSame($expected, $this->autocompleteHelper->renderAutocomplete($autocomplete)); }