Sulu\Bundle\PreviewBundle\Preview\PreviewInterface::start PHP Method

start() public method

Starts a new preview session.
public start ( string $objectClass, string $id, integer $userId, string $webspaceKey, string $locale, array $data = [] ) : string
$objectClass string Class of object
$id string Identifier of object
$userId integer
$webspaceKey string
$locale string
$data array Initial data will be set on the object
return string Token can be used to reuse this preview-session
    public function start($objectClass, $id, $userId, $webspaceKey, $locale, array $data = []);

Usage Example

Example #1
0
 /**
  * Start preview with given parameters.
  *
  * @param MessageHandlerContext $context
  * @param array $message
  *
  * @return array
  */
 private function start(MessageHandlerContext $context, $message)
 {
     if ($context->has('previewToken') && $this->preview->exists($context->get('previewToken'))) {
         $this->preview->stop($context->get('previewToken'));
     }
     $token = $this->preview->start($message['class'], $message['id'], $message['user'], $message['webspaceKey'], $message['locale'], $message['data'] ?: []);
     $response = $this->preview->render($token, $message['webspaceKey'], $message['locale']);
     $context->set('previewToken', $token);
     $context->set('locale', $message['locale']);
     return ['command' => 'start', 'token' => $token, 'response' => $response, 'msg' => 'OK'];
 }