/** * @param Request $request * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function fetchRemoteFilesAction(Request $request) { $provider = InputHelper::string($request->request->get('provider')); $path = InputHelper::string($request->request->get('path', '')); $dispatcher = $this->factory->getDispatcher(); $name = AssetEvents::ASSET_ON_REMOTE_BROWSE; if (!$dispatcher->hasListeners($name)) { return $this->sendJsonResponse(array('success' => 0)); } /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $integrationHelper */ $integrationHelper = $this->factory->getHelper('integration'); /** @var \Mautic\PluginBundle\Integration\AbstractIntegration $integration */ $integration = $integrationHelper->getIntegrationObject($provider); $event = new RemoteAssetBrowseEvent($integration); $dispatcher->dispatch($name, $event); if (!($adapter = $event->getAdapter())) { return $this->sendJsonResponse(array('success' => 0)); } $connector = new Filesystem($adapter); $output = $this->renderView('MauticAssetBundle:Remote:list.html.php', array('connector' => $connector, 'integration' => $integration, 'items' => $connector->listKeys($path))); return $this->sendJsonResponse(array('success' => 1, 'output' => $output)); }
/** * Gives a preview of the form * * @param int $id * * @return Response * @throws \Exception * @throws \Mautic\CoreBundle\Exception\FileNotFoundException */ public function previewAction($id = 0) { $objectId = empty($id) ? InputHelper::int($this->request->get('id')) : $id; $css = InputHelper::string($this->request->get('css')); $model = $this->getModel('form.form'); $form = $model->getEntity($objectId); $customStylesheets = !empty($css) ? explode(',', $css) : []; $template = null; if ($form === null || !$form->isPublished()) { $this->notFound(); } else { $html = $model->getContent($form); $model->populateValuesWithGetParameters($form, $html); $viewParams = array('content' => $html, 'stylesheets' => $customStylesheets, 'name' => $form->getName()); $template = $form->getTemplate(); if (!empty($template)) { $theme = $this->factory->getTheme($template); if ($theme->getTheme() != $template) { $config = $theme->getConfig(); if (in_array('form', $config['features'])) { $template = $theme->getTheme(); } else { $template = null; } } } } $viewParams['template'] = $template; if (!empty($template)) { $logicalName = $this->factory->getHelper('theme')->checkForTwigTemplate(':' . $template . ':form.html.php'); $assetsHelper = $this->factory->getHelper('template.assets'); $analytics = $this->factory->getHelper('template.analytics')->getCode(); if (!empty($customStylesheets)) { foreach ($customStylesheets as $css) { $assetsHelper->addStylesheet($css); } } $this->factory->getHelper('template.slots')->set('pageTitle', $form->getName()); if (!empty($analytics)) { $assetsHelper->addCustomDeclaration($analytics); } return $this->render($logicalName, $viewParams); } return $this->render('MauticFormBundle::form.html.php', $viewParams); }