getViewType() public method

public getViewType ( )
コード例 #1
0
ファイル: Content.php プロジェクト: emodric/LegacyBridge
 /**
  * Returns a ContentView object corresponding to content info found within $view, or void if not applicable.
  *
  * @param \eZ\Publish\Core\MVC\Symfony\View\View $view
  *
  * @return \eZ\Publish\Core\MVC\Symfony\View\ContentView|void
  */
 public function getView(View $view)
 {
     if (!$view instanceof ContentView) {
         return null;
     }
     $viewType = $view->getViewType();
     $contentInfo = $view->getContent()->contentInfo;
     $legacyKernel = $this->getLegacyKernel();
     $legacyContentClosure = function (array $params) use($contentInfo, $viewType, $legacyKernel) {
         return $legacyKernel->runCallback(function () use($contentInfo, $viewType, $params) {
             $tpl = eZTemplate::factory();
             /**
              * @var \eZObjectForwarder
              */
             $funcObject = $tpl->fetchFunctionObject('content_view_gui');
             if (!$funcObject) {
                 return '';
             }
             // Used by XmlText field type
             if (isset($params['objectParameters'])) {
                 if (isset($params['linkParameters']) && $params['linkParameters'] !== null) {
                     $linkParameters = $params['linkParameters'];
                 }
                 $tpl->setVariable('object_parameters', $params['objectParameters'], 'ContentView');
             } elseif (isset($params['embedParams'])) {
                 if (isset($params['embedParams']['link'])) {
                     $linkParameters = $params['embedParams']['link'];
                 }
                 if (isset($params['embedParams']['config'])) {
                     $tpl->setVariable('object_parameters', $params['embedParams']['config'], 'ContentView');
                 }
             }
             // Convert link parameters to Legacy Stack format
             if (isset($linkParameters)) {
                 $tpl->setVariable('link_parameters', $this->legalizeLinkParameters($linkParameters), 'ContentView');
             }
             $children = array();
             $funcObject->process($tpl, $children, 'content_view_gui', false, array('content_object' => array(array(eZTemplate::TYPE_ARRAY, eZContentObject::fetch($contentInfo->id))), 'view' => array(array(eZTemplate::TYPE_STRING, $viewType))), array(), '', '');
             if (is_array($children) && isset($children[0])) {
                 return ezpEvent::getInstance()->filter('response/output', $children[0]);
             }
             return '';
         }, false);
     };
     $this->decorator->setContentView(new ContentView($legacyContentClosure));
     return $this->decorator;
 }
コード例 #2
0
 public function getView(View $view)
 {
     $viewType = $view->getViewType();
     if ($viewType !== 'full') {
         return null;
     }
     if (!$view instanceof ContentValueView) {
         return null;
     }
     if ($view->getContent()->contentInfo->sectionId !== $this->premiumSectionId) {
         return null;
     }
     if ($this->subscriptionChecker->userIsSubscriber($this->repository->getCurrentUser())) {
         return null;
     }
     return new ContentView("eZDemoBundle:{$viewType}:premium_content.html.twig");
 }
コード例 #3
0
ファイル: Location.php プロジェクト: emodric/LegacyBridge
 /**
  * Returns a ContentView object corresponding to location found within $view.
  * Will basically run content/view legacy module with appropriate parameters.
  *
  * @param \eZ\Publish\Core\MVC\Symfony\View\View $view
  *
  * @return \eZ\Publish\Core\MVC\Symfony\View\ContentView|void
  */
 public function getView(View $view)
 {
     if (!$view instanceof ContentView || !$view->getLocation() instanceof APILocation) {
         return null;
     }
     $logger = $this->logger;
     $legacyHelper = $this->legacyHelper;
     $currentViewProvider = $this;
     $viewParameters = array();
     $request = $this->getCurrentRequest();
     if (isset($request)) {
         $viewParameters = $request->attributes->get('viewParameters', array());
     }
     $viewType = $view->getViewType();
     $location = $view->getLocation();
     $legacyContentClosure = function (array $params) use($location, $viewType, $logger, $legacyHelper, $viewParameters, $currentViewProvider) {
         $content = isset($params['content']) ? $params['content'] : null;
         // Additional parameters (aka user parameters in legacy) are expected to be scalar
         foreach ($params as $paramName => $param) {
             if (!is_scalar($param)) {
                 unset($params[$paramName]);
                 if (isset($logger)) {
                     $logger->notice("'{$paramName}' is not scalar, cannot pass it to legacy content module. Skipping.", array(__METHOD__));
                 }
             }
         }
         // viewbaseLayout is useless in legacy views
         unset($params['viewbaseLayout']);
         $params += $viewParameters;
         // Render preview or published view depending on context.
         if (isset($params['isPreview']) && $params['isPreview'] === true && $content instanceof APIContent) {
             return $currentViewProvider->renderPreview($content, $params, $legacyHelper);
         } else {
             return $currentViewProvider->renderPublishedView($location, $viewType, $params, $legacyHelper);
         }
     };
     $this->decorator->setContentView(new ContentView($legacyContentClosure));
     return $this->decorator;
 }
コード例 #4
0
 /**
  * Checks if $valueObject has a usable configuration for $viewType.
  * If so, the configuration hash will be returned.
  * $valueObject can be for example a Location or a Content object.
  *
  * @param \eZ\Publish\Core\MVC\Symfony\View\View $view
  *
  * @return array|null The matched configuration as a hash, containing template or controller to use, or null if not matched.
  */
 public function match(View $view)
 {
     $viewType = $view->getViewType();
     if (!isset($this->matchConfig[$viewType])) {
         return null;
     }
     if (!isset($this->alreadyMatched[$viewType])) {
         $this->alreadyMatched[$viewType] = new SplObjectStorage();
     }
     // If we already matched, just returned the matched value.
     if (isset($this->alreadyMatched[$viewType][$view])) {
         return $this->alreadyMatched[$viewType][$view];
     }
     foreach ($this->matchConfig[$viewType] as $configHash) {
         $hasMatched = true;
         $matcher = null;
         foreach ($configHash['match'] as $matcherIdentifier => $value) {
             $matcher = $this->getMatcher($matcherIdentifier);
             $matcher->setMatchingConfig($value);
             if (!$matcher->match($view)) {
                 $hasMatched = false;
             }
         }
         if ($hasMatched) {
             return $this->alreadyMatched[$viewType][$view] = $configHash + array('matcher' => $matcher);
         }
     }
     return $this->alreadyMatched[$viewType][$view] = null;
 }
コード例 #5
0
 public function __construct(View $view)
 {
     $this->view = $view;
     parent::__construct(sprintf("No view template was set to render the view with the '%s' view type. Check your view configuration.", $view->getViewType()));
 }