Sulu\Component\Webspace\Analyzer\RequestAnalyzerInterface::getCurrentLocalization PHP Method

getCurrentLocalization() public method

Returns the current localization for this Request.
public getCurrentLocalization ( ) : Localization
return Sulu\Component\Localization\Localization
    public function getCurrentLocalization();

Usage Example

Example #1
0
 /**
  * @param HitEvent $event
  */
 public function onHit(HitEvent $event)
 {
     if ($event->getMetadata()->reflection->getName() !== 'Sulu\\Bundle\\EventBundle\\Entity\\Event') {
         return;
     }
     $locale = $this->requestAnalyzer->getCurrentLocalization()->getLocalization();
     $document = $event->getHit()->getDocument();
     $eventApiEntity = $this->eventManager->findByIdAndLocale($document->getId(), $locale);
     if (!$eventApiEntity) {
         return;
     }
     $startDate = $eventApiEntity->getStartDate();
     $endDate = $eventApiEntity->getEndDate();
     $categories = $eventApiEntity->getCategories();
     $categoryTitles = array();
     foreach ($categories as $category) {
         $categoryTitles[] = $category->getName();
     }
     $startDateField = new Field('start_date', $startDate->format('c'), Field::TYPE_STRING);
     $document->addField($startDateField);
     if ($endDate) {
         $endDateField = new Field('end_date', $endDate->format('c'), Field::TYPE_STRING);
         $document->addField($endDateField);
     }
     $categoryTitleField = new Field('category_title', implode(', ', $categoryTitles), Field::TYPE_STRING);
     $document->addField($categoryTitleField);
     $url = $this->router->generate('sulu_events.detail', array('id' => $eventApiEntity->getId(), 'slug' => $eventApiEntity->getSlug()));
     $document->setUrl($url);
 }
All Usage Examples Of Sulu\Component\Webspace\Analyzer\RequestAnalyzerInterface::getCurrentLocalization