public function install() { \DoctrineHelper::createSchema($this->entityManager, static::getEntities()); $this->createLicenses(); $temporaryUploadCollection = new CollectionEntity(); $temporaryUploadCollection->setTitle($this->__('Temporary Upload Collection'))->setDescription($this->__('This collection is needed as temporary storage for uploaded files. Do not edit or delete!')); $this->entityManager->persist($temporaryUploadCollection); $exampleCollection = new CollectionEntity(); $exampleCollection->setTitle($this->__('Example collection'))->setDescription($this->__('Edit or delete this example collection')); $this->entityManager->persist($exampleCollection); $this->entityManager->flush(); if ($temporaryUploadCollection->getId() != CollectionEntity::TEMPORARY_UPLOAD_COLLECTION_ID) { \LogUtil::registerError($this->__('The id of the generated "temporary upload collection" must be 1, but has a different value. This should not have happened. Please report this error.')); } \HookUtil::registerProviderBundles($this->version->getHookProviderBundles()); \HookUtil::registerSubscriberBundles($this->version->getHookSubscriberBundles()); $this->setVar('descriptionEscapingStrategyForCollection', 'text'); $this->setVar('descriptionEscapingStrategyForMedia', 'text'); $this->setVar('defaultCollectionTemplate', 'cards'); $this->setVar('slugEditable', true); $this->setVar('lastNewVersionCheck', 0); $this->setVar('newVersionAvailable', false); $this->createUploadDir(); return true; }
/** * @param CollectionEntity|AbstractMediaEntity $entity * * @return string */ public function escapeDescription($entity) { $description = $entity->getDescription(); $strategy = null; $hookName = null; if ($entity instanceof CollectionEntity) { $strategy = \ModUtil::getVar('CmfcmfMediaModule', 'descriptionEscapingStrategyForCollection'); $hookName = 'collections'; } elseif ($entity instanceof AbstractMediaEntity) { $strategy = \ModUtil::getVar('CmfcmfMediaModule', 'descriptionEscapingStrategyForMedia'); $hookName = 'media'; } else { throw new \LogicException(); } $eventName = "cmfcmfmediamodule.filter_hooks.{$hookName}.filter"; $hook = new \Zikula_FilterHook($eventName, $description); $description = $this->hookDispatcher->dispatch($eventName, $hook)->getData(); switch ($strategy) { case 'raw': return $description; case 'text': return htmlentities($description); case 'markdown': return $this->markdownExtra->transform($description); default: throw new \LogicException(); } }
public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); $escapingStrategy = \ModUtil::getVar('CmfcmfMediaModule', 'descriptionEscapingStrategyForCollection'); switch ($escapingStrategy) { case 'raw': $descriptionHelp = $this->__('You may use HTML.'); break; case 'text': $descriptionHelp = $this->__('Only plaintext allowed.'); break; case 'markdown': $descriptionHelp = $this->__('You may use MarkDown.'); break; default: throw new \LogicException(); } /** @var CollectionEntity $theCollection */ $theCollection = $options['data']; $builder->add('title', 'text', ['label' => $this->__('Title')]); // If enabled, breaks slug generation of children when the slug is changed. //if (\ModUtil::getVar('CmfcmfMediaModule', 'slugEditable')) { // $builder // ->add('slug', 'text', [ // 'label' => $this->__('Slug'), // 'required'=> false, // 'attr' => [ // 'placeholder' => $this->__('Leave empty to autogenerate') // ] // ]) // ; //} $builder->add('description', 'textarea', ['label' => $this->__('Description'), 'required' => false, 'attr' => ['help' => $descriptionHelp]])->add('defaultTemplate', 'choice', ['label' => $this->__('Template'), 'required' => false, 'placeholder' => $this->__('Default'), 'choices' => $this->templateCollection->getCollectionTemplateTitles()])->add('parent', 'entity', ['class' => 'Cmfcmf\\Module\\MediaModule\\Entity\\Collection\\CollectionEntity', 'required' => false, 'label' => $this->__('Parent'), 'query_builder' => function (EntityRepository $er) use($theCollection) { $qb = $er->createQueryBuilder('c'); $qb->orderBy('c.root', 'ASC')->addOrderBy('c.lft', 'ASC')->where($qb->expr()->not($qb->expr()->eq('c.id', ':uploadCollectionId')))->setParameter('uploadCollectionId', CollectionEntity::TEMPORARY_UPLOAD_COLLECTION_ID); if ($theCollection->getId() != null) { // The collection is currently edited. $qb->andWhere($qb->expr()->neq('c.id', ':id'))->setParameter('id', $theCollection->getId()); } return $qb; }, 'data' => $this->parent, 'placeholder' => $this->__('[No parent]'), 'property' => 'indentedTitle'])->add('watermark', 'entity', ['class' => 'CmfcmfMediaModule:Watermark\\AbstractWatermarkEntity', 'required' => false, 'label' => $this->__('Watermark'), 'data' => $theCollection->getId() !== null ? $theCollection->getWatermark() : (isset($this->parent) ? $this->parent->getWatermark() : null), 'placeholder' => $this->__('No watermark'), 'property' => 'title']); }
/** * @Route("/show/{slug}", requirements={"slug"=".+"}, options={"expose" = true}) * @Method("GET") * @ParamConverter("entity", class="Cmfcmf\Module\MediaModule\Entity\Collection\CollectionEntity", options={"slug" = "slug"}) * @Template() * * @param Request $request * @param CollectionEntity $entity * * @return array */ public function displayAction(Request $request, CollectionEntity $entity) { if (!$this->get('cmfcmf_media_module.security_manager')->hasPermission($entity !== null ? $entity : 'collection', 'display')) { throw new AccessDeniedException(); } if ($entity->getId() == CollectionEntity::TEMPORARY_UPLOAD_COLLECTION_ID) { throw new NotFoundHttpException(); } $template = $request->query->get('template', $entity->getDefaultTemplate() != null ? $entity->getDefaultTemplate() : \ModUtil::getVar('CmfcmfMediaModule', 'defaultCollectionTemplate')); $collectionTemplateCollection = $this->get('cmfcmf_media_module.collection_template_collection'); if (!$collectionTemplateCollection->hasTemplate($template)) { throw new NotFoundHttpException(); } $templateVars = ['collection' => $entity, 'breadcrumbs' => $entity->getBreadcrumbs($this->get('router'))]; if ($entity->isVirtualRoot()) { $hookUrl = new RouteUrl('cmfcmfmediamodule_collection_displayroot'); } else { $hookUrl = new RouteUrl('cmfcmfmediamodule_collection_display', ['slug' => $entity->getSlug()]); } $templateVars['hook'] = $this->getDisplayHookContent('collection', 'display_view', $entity->getId(), $hookUrl); $templateVars['renderRaw'] = $isHook = $request->query->get('isHook', false); $templateVars['content'] = $collectionTemplateCollection->getCollectionTemplate($template)->render($entity, $this->get('cmfcmf_media_module.media_type_collection'), !$isHook); return $this->render('CmfcmfMediaModule:Collection:Display.html.twig', $templateVars); }