Esempio n. 1
0
File: Save.php Progetto: Boorj/bolt
 /**
  * Commit the record to the database.
  *
  * @param Entity\Content      $content
  * @param Entity\Content|null $oldContent
  * @param array               $contentType
  * @param boolean             $new
  * @param string              $comment
  * @param string              $returnTo
  * @param string              $editReferrer
  *
  * @return Response
  */
 private function saveContentRecord(Entity\Content $content, $oldContent, array $contentType, $new, $comment, $returnTo, $editReferrer)
 {
     // Save the record
     $repo = $this->em->getRepository($contentType['slug']);
     // Update the date modified timestamp
     $content->setDatechanged('now');
     $repo->save($content);
     $id = $content->getId();
     // Create the change log entry if configured
     $this->logChange($contentType, $content->getId(), $content, $oldContent, $comment);
     // Log the change
     if ($new) {
         $this->loggerFlash->success(Trans::__('contenttypes.generic.saved-new', ['%contenttype%' => $contentType['slug']]));
         $this->loggerSystem->info('Created: ' . $content->getTitle(), ['event' => 'content']);
     } else {
         $this->loggerFlash->success(Trans::__('contenttypes.generic.saved-changes', ['%contenttype%' => $contentType['slug']]));
         $this->loggerSystem->info('Saved: ' . $content->getTitle(), ['event' => 'content']);
     }
     /*
      * We now only get a returnto parameter if we are saving a new
      * record and staying on the same page, i.e. "Save {contenttype}"
      */
     if ($returnTo) {
         if ($returnTo === 'new') {
             return new RedirectResponse($this->generateUrl('editcontent', ['contenttypeslug' => $contentType['slug'], 'id' => $id, '#' => $returnTo]));
         } elseif ($returnTo === 'saveandnew') {
             return new RedirectResponse($this->generateUrl('editcontent', ['contenttypeslug' => $contentType['slug'], '#' => $returnTo]));
         } elseif ($returnTo === 'ajax') {
             return $this->createJsonUpdate($content, true);
         } elseif ($returnTo === 'test') {
             return $this->createJsonUpdate($content, false);
         }
     }
     // No returnto, so we go back to the 'overview' for this contenttype.
     // check if a pager was set in the referrer - if yes go back there
     if ($editReferrer) {
         return new RedirectResponse($editReferrer);
     } else {
         return new RedirectResponse($this->generateUrl('overview', ['contenttypeslug' => $contentType['slug']]));
     }
 }