/**
  * Build the javascript.
  *
  * @param Validation $validation Form validation.
  *
  * @return string
  */
 private function buildJavascript($validation)
 {
     $template = new \FrontendTemplate('form_validation_js');
     $template->validation = $validation;
     $template->javascript = $this->builder->encode($validation);
     return $template->parse();
 }
Ejemplo n.º 2
0
 /**
  * Build map as a javascript resource.
  *
  * It always return the generated map no matter if an assets object is given or not. If you want to get the
  * combined generated assets, just use $assets->getHtml().
  *
  * @param Map    $map    The map being created.
  * @param Assets $assets Optional pass an assets instance which collects all required assets.
  *
  * @return string
  */
 public function build(Map $map, Assets $assets = null)
 {
     $prefix = 'var map, layers = {}, controls = {}, icons = {};' . "\n";
     if (!$assets) {
         return $prefix . $this->javascriptBuilder->encode($map, $this->jsonEncodeFlags);
     }
     $collector = new Collector($assets, $this->javascripts, $this->stylesheets);
     $this->eventDispatcher->addSubscriber($collector);
     $assets->setMap($prefix . $this->javascriptBuilder->encode($map, $this->jsonEncodeFlags));
     $this->eventDispatcher->removeSubscriber($collector);
     return $assets->getMap();
 }