Sulu\Component\Content\Compat\Structure\PageBridge::getLanguageCode PHP Method

getLanguageCode() public method

public getLanguageCode ( )
    public function getLanguageCode()
    {
        if (!$this->document) {
            return $this->locale;
        }
        // return original locale for shadow or ghost pages
        if ($this->getIsShadow() || $this->getType() && $this->getType()->getName() === 'ghost') {
            return $this->inspector->getOriginalLocale($this->getDocument());
        }
        return parent::getLanguageCode();
    }

Usage Example

Esempio n. 1
0
 /**
  * renders content with the real website controller.
  *
  * @param PageBridge $content
  * @param bool       $partial
  *
  * @return string
  */
 public function render(PageBridge $content, $partial = false)
 {
     // set active theme
     $webspace = $this->webspaceManager->findWebspaceByKey($content->getWebspaceKey());
     $this->activeTheme->setName($webspace->getTheme()->getKey());
     // get controller and invoke action
     $request = new Request();
     $request->attributes->set('_controller', $content->getController());
     $controller = $this->controllerResolver->getController($request);
     // prepare locale for translator and request
     $request->setLocale($content->getLanguageCode());
     $localeBefore = $this->translator->getLocale();
     $this->translator->setLocale($content->getLanguageCode());
     $this->requestStack->push($request);
     /** @var Response $response */
     $response = $controller[0]->{$controller[1]}($content, true, $partial);
     // roll back
     $this->requestStack->pop();
     $this->translator->setLocale($localeBefore);
     return $response->getContent();
 }