/** * {@inheritDoc} */ public function load($id = 0) { $this->subject = $this->contentManager->getRepository()->find($id); if (!$this->subject) { throw $this->createNotFoundException('No content found for id ' . $id); } return $this; }
/** * {@inheritdoc} */ public function load($id = 0) { $this->subject = $this->contentManager->getRepository()->find($id); if (!$this->subject) { throw new \Exception(sprintf('Trying to load a content item with ID %d that does not exist.', $id)); } return $this; }
/** * Transforms an id to entity * * @param integer $id * * @return object */ public function reverseTransform($id) { if (null == $id) { return null; } $entity = $this->contentManager->getRepository()->find($id); return $entity; }
/** * Builds the form and transforms the model data. * * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addModelTransformer(new CallbackTransformer(function ($original) { $ids = json_decode($original); $items = $this->contentManager->getRepository()->createQueryBuilder('c')->where('c.id IN (:ids)')->setParameter('ids', $ids)->getQuery()->getResult(); return $items; }, function ($submitted) { if (!$submitted instanceof ArrayCollection && !is_array($submitted)) { return null; } $ids = []; foreach ($submitted as $content) { $ids[] = $content->getId(); } return json_encode($ids); })); }
/** * Processes a POST request to subscribe. * * @param Block $block * * @return Response */ public function subscribeAction(Block $block) { $response = $this->execute($block); $properties = $block->getProperties(); if ($this->subscribed && isset($properties['responseType']) && $properties['responseType'] == 'redirect') { $content = $this->contentManager->getRepository()->find($properties['responseContent']); $response = new RedirectResponse($this->router->generate('_content', ['slug' => $content->getSlug()])); } return $response; }
public function getBreadcrumbs(ContentInterface $content) { $return = []; $breadcrumbs = $content->getBreadcrumbs(); if (sizeof($breadcrumbs) == 1 && key($breadcrumbs) == 'index') { return $return; } $index = 0; foreach ($breadcrumbs as $slug => $title) { if (substr($slug, -6) == '/index') { continue; } $indexSlug = sizeof($breadcrumbs) - 1 == $index ? $slug : $slug . '/index'; if ($content = $this->contentManager->getRepository()->findOneBy(['slug' => $indexSlug])) { $return[$slug . '/'] = $content->getTitle(); } $index++; } return $return; }