<?php
namespace App\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Pimcore\Model\DataObject;
use Symfony\Component\Messenger\MessageBusInterface;
class SuccessStoriesController extends FrontendController
{
public function defaultAction(Request $request)
{
$slug = trim($request->get('slug'), '/');
if(str_contains($slug, 'ssid-')){
$successStory = DataObject\SuccessStories::getById(str_replace('ssid-', '', $slug), 1);
}else{
$successStory = DataObject\SuccessStories::getByURL($slug, 1);
}
if(is_null($successStory->getSnipped())){
throw new \Pimcore\Model\Element\ValidationException("This is your custom error message", 1234);
}
$this->document->setValue('title', $successStory->getMetaTitle());
$this->document->setValue('description', $successStory->getMetaDescription());
return $this->render('digitalwandler/DocumentType/snippedPage.html.twig', ['snipped' => $successStory->getSnipped()->getId()]);
}
public function menuAction(Request $request)
{
$successStories = DataObject\SuccessStories::getList([
'order' => 'desc'
]);
foreach ($successStories as $successStory){
foreach (explode('|', $successStory->getTags()) as $tag){
if(isset($tags[$tag])){
$tags[$tag]++;
}else{
$tags[$tag] = 1;
}
}
}
return $this->render('digitalwandler/DocumentType/menuSnippet.html.twig', ['tags' => $tags, 'page' => $request->get('page')]);
}
}