/** * {@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); }
/** * @expectedException Ivory\GoogleMap\Exception\HelperException * @expectedExceptionMessage The place autocomplete bound must have coordinates. */ public function testRenderJavascriptsWithInvalidBound() { $autocomplete = new Autocomplete(); $autocomplete->setBound(1, 2, 3, 4); $autocomplete->getBound()->setSouthWest(null); $autocomplete->getBound()->setNorthEast(null); $this->autocompleteHelper->renderJavascripts($autocomplete); }
/** * Renders the autocomplete. * * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. * * @return string The JS output. */ public function renderAutocomplete(Autocomplete $autocomplete) { $this->jsonBuilder->reset(); if ($autocomplete->hasTypes()) { $this->jsonBuilder->setValue('[types]', $autocomplete->getTypes()); } if ($autocomplete->hasBound()) { $this->jsonBuilder->setValue('[bounds]', $autocomplete->getBound()->getJavascriptVariable(), false); } if ($autocomplete->hasComponentRestrictions()) { $this->jsonBuilder->setValue('[componentRestrictions]', $autocomplete->getComponentRestrictions()); } if (!$this->jsonBuilder->hasValues()) { $this->jsonBuilder->setJsonEncodeOptions(JSON_FORCE_OBJECT); } return sprintf('%s = new google.maps.places.Autocomplete(document.getElementById(\'%s\'), %s);' . PHP_EOL, $autocomplete->getJavascriptVariable(), $autocomplete->getInputId(), $this->jsonBuilder->build()); }
public function testLanguage() { $this->autocomplete->setLanguage('fr'); $this->assertSame('fr', $this->autocomplete->getLanguage()); }
/** * Get autocomplete form * * @param null $value * * @return mixed * @throws \Ivory\GoogleMap\Exception\AssetException * @throws \Ivory\GoogleMap\Exception\PlaceException * @throws \Ivory\GoogleMap\Exception\TemplatingException */ public function getAutocomplete($value = null) : array { $autocomplete = new Autocomplete(); $autocompleteHelper = new AutocompleteHelper(); $autocomplete->setPrefixJavascriptVariable('location_autocomplete_'); $autocomplete->setInputId('location_input'); $autocomplete->setInputAttributes(['class' => 'form-control', 'name' => 'locationName', 'required' => 'required']); $autocomplete->setInputAttribute('value', $value); $autocomplete->setJavascriptVariable('location_autocomplete'); $autocomplete->setTypes([AutocompleteType::GEOCODE]); $autocomplete->setAsync(true); $autocomplete->setLanguage('en'); $js = str_replace('load_ivory_google_map_api', 'load_ivory_google_map_api_auto', $autocompleteHelper->renderJavascripts($autocomplete)); return ['html' => $autocompleteHelper->renderHtmlContainer($autocomplete), 'js' => $this->removeJsCaller($js)]; }