/** * Builds the root selector with all the first level options * * @param null|LocationData $selectedLocation The selected option */ protected function buildRootSelector($selectedLocation = null) { $selectedOption = !is_null($selectedLocation) ? $selectedLocation->getId() : null; $rootLocations = $this->locationProvider->getRootLocations(); if (empty($rootLocations)) { throw new \RuntimeException('No locations loaded, please populate your locations'); } $locationExample = reset($rootLocations); $this->selects[] = $this->formatSelector($locationExample->getType(), $this->generateOptions($rootLocations), $selectedOption); }
/** * Test that we are returning the root locations */ public function testGetRootLocations() { $rootLocations = $this->locationProviderAdapter->getRootLocations(); $this->assertCount(1, $rootLocations, 'We only expect one zone to be root'); /** * @var LocationData $location */ $location = reset($rootLocations); $this->assertInstanceOf('Elcodi\\Component\\Geo\\ValueObject\\LocationData', $location, 'The response should be a LocationData'); $this->assertEquals('Spain', $location->getName(), 'Spain is the only root location'); }
/** * Get all the root locations. * * @return Response Data serialized in json */ public function getRootLocationsAction() { return $this->createResponseObject(function () { return $this->normalizeLocationDataArray($this->locationProvider->getRootLocations()); }); }