public function execute(Location $location)
 {
     // Set HTML title as Location name.
     $location->setName('Form on ' . ParserUtil::getHTMLTitle($location->getUrl()));
     // Set the Website page module as the Location module.
     $locationModule = $this->locationService->getLocationModule('campaignchain/location-website', 'campaignchain-website-form');
     $location->setLocationModule($locationModule);
     // Set the image.
     $location->setImage($this->assetsHelper->getUrl('bundles/campaignchainlocationwebsite/images/icons/256x256/form.png', null));
     return $location;
 }
 public function newAction(Request $request)
 {
     $locationType = $this->get('campaignchain.core.form.type.location');
     $locationType->setBundleName('campaignchain/location-website');
     $locationType->setModuleIdentifier('campaignchain-website');
     $form = $this->createFormBuilder()->add('URL', 'url', array('label' => 'Website URL', 'constraints' => array(new Url(array('checkDNS' => true)))))->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $locationURL = $form->getData()['URL'];
         $locationName = ParserUtil::getHTMLTitle($locationURL, $locationURL);
         $locationService = $this->get('campaignchain.core.location');
         $locationModule = $locationService->getLocationModule('campaignchain/location-website', 'campaignchain-website');
         $location = new Location();
         $location->setLocationModule($locationModule);
         $location->setName($locationName);
         $location->setUrl($locationURL);
         // Get the Website's favicon as Channel image if possible.
         $favicon = ParserUtil::getFavicon($locationURL);
         if ($favicon) {
             $locationImage = $favicon;
         } else {
             //                $locationImage = $this->container->get('templating.helper.assets')
             //                    ->getUrl(
             //                        'bundles/campaignchainlocationwebsite/images/icons/256x256/website.png',
             //                        null
             //                    );
             $locationImage = null;
         }
         $location->setImage($locationImage);
         $wizard = $this->get('campaignchain.core.channel.wizard');
         $wizard->setName($location->getName());
         $repository = $this->getDoctrine()->getRepository('CampaignChainCoreBundle:Location');
         if (!$repository->findBy(array('url' => $location->getUrl()))) {
             $wizard->addLocation($location->getUrl(), $location);
             try {
                 $channel = $wizard->persist();
                 $wizard->end();
                 $this->get('session')->getFlashBag()->add('success', "The Website '" . $location->getUrl() . "' has been connected.");
                 return $this->redirect($this->generateUrl('campaignchain_core_location'));
             } catch (\Exception $e) {
                 $this->addFlash('warning', "An error occured during the creation of the website location");
                 $this->get('logger')->addError($e->getMessage());
             }
         } else {
             $this->addFlash('warning', "The website  '" . $location->getUrl() . "' already exists.");
         }
     }
     //return $this->redirect($this->generateUrl(
     //  'campaignchain_channel_website_page_new',
     //array('id' => $channel->getLocations()[0]->getId())));
     return $this->render('CampaignChainCoreBundle:Base:new.html.twig', array('page_title' => 'Connect Website', 'form' => $form->createView()));
 }