Inheritance: extends Common\Core\Twig\BaseTwigTemplate
Exemplo n.º 1
0
 /**
  * Parses the html for this filefield.
  *
  * @param TwigTemplate $template The template to parse the element in.
  *
  * @return string
  * @throws \SpoonFormException
  */
 public function parse($template = null)
 {
     // name is required
     if ($this->attributes['name'] == '') {
         throw new \SpoonFormException('A name is required for a file field. Please provide a name.');
     }
     // start html generation
     $output = '<input type="file"';
     // add attributes
     $output .= $this->getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'])) . ' />';
     // add help txt if needed
     if (!$this->hideHelpTxt) {
         if (isset($this->attributes['extension'])) {
             $output .= '<p class="help-block">' . sprintf(BackendLanguage::getMessage('HelpFileFieldWithMaxFileSize', 'core'), $this->attributes['extension'], Form::getUploadMaxFileSize()) . '</p>';
         } else {
             $output .= '<p class="help-block">' . sprintf(BackendLanguage::getMessage('HelpMaxFileSize'), Form::getUploadMaxFileSize()) . '</p>';
         }
     }
     // parse to template
     if ($template !== null) {
         $template->assign('file' . SpoonFilter::toCamelCase($this->attributes['name']), $output);
         $template->assign('file' . SpoonFilter::toCamelCase($this->attributes['name']) . 'Error', $this->errors != '' ? '<span class="formError text-danger">' . $this->errors . '</span>' : '');
     }
     return $output;
 }
Exemplo n.º 2
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // add jquery, we will need this in every action, so add it globally
     $this->header->addJS('/bower_components/jquery/dist/jquery.min.js', 'Core', false, true);
     $this->header->addJS('/bower_components/jquery-migrate/jquery-migrate.min.js', 'Core', false, true);
     $this->header->addJS('/bower_components/jquery-ui/jquery-ui.min.js', 'Core', false, true);
     $this->header->addJS('/bower_components/bootstrap-sass/assets/javascripts/bootstrap.min.js', 'Core', false, true);
     $this->header->addJS('/bower_components/typeahead.js/dist/typeahead.bundle.min.js', 'Core', false, true);
     $this->header->addJS('/bower_components/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js', 'Core', false, true);
     $this->header->addJS('jquery/jquery.backend.js', 'Core');
     // add items that always need to be loaded
     $this->header->addJS('utils.js', 'Core', true, false, true);
     $this->header->addJS('backend.js', 'Core', true, false, true);
     // add module js
     if (is_file($this->getBackendModulePath() . '/Js/' . $this->getModule() . '.js')) {
         $this->header->addJS($this->getModule() . '.js', null, true, false, true);
     }
     // add action js
     if (is_file($this->getBackendModulePath() . '/Js/' . $this->getAction() . '.js')) {
         $this->header->addJS($this->getAction() . '.js', null, true, false, true);
     }
     // add core css files
     $this->header->addCSS('/bower_components/bootstrap-tagsinput/dist/bootstrap-tagsinput.css', 'Core', true);
     $this->header->addCSS('/bower_components/bootstrap-tagsinput/dist/bootstrap-tagsinput-typeahead.css', 'Core', true);
     $this->header->addCSS('screen.css', 'Core');
     $this->header->addCSS('debug.css', 'Core');
     // add module specific css
     if (is_file($this->getBackendModulePath() . '/Layout/Css/' . $this->getModule() . '.css')) {
         $this->header->addCSS($this->getModule() . '.css');
     }
     // store var so we don't have to call this function twice
     $var = array_map('strip_tags', $this->getParameter('var', 'array', array()));
     // is there a report to show?
     if ($this->getParameter('report') !== null) {
         // show the report
         $this->tpl->assign('report', true);
         // camelcase the string
         $messageName = strip_tags(\SpoonFilter::toCamelCase($this->getParameter('report'), '-'));
         // if we have data to use it will be passed as the var parameter
         if (!empty($var)) {
             $this->tpl->assign('reportMessage', vsprintf(BL::msg($messageName), $var));
         } else {
             $this->tpl->assign('reportMessage', BL::msg($messageName));
         }
         // highlight an element with the given id if needed
         if ($this->getParameter('highlight')) {
             $this->tpl->assign('highlight', strip_tags($this->getParameter('highlight')));
         }
     }
     // is there an error to show?
     if ($this->getParameter('error') !== null) {
         // camelcase the string
         $errorName = strip_tags(\SpoonFilter::toCamelCase($this->getParameter('error'), '-'));
         // if we have data to use it will be passed as the var parameter
         if (!empty($var)) {
             $this->tpl->assign('errorMessage', vsprintf(BL::err($errorName), $var));
         } else {
             $this->tpl->assign('errorMessage', BL::err($errorName));
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @param TwigTemplate $template
  */
 public function parse(TwigTemplate $template)
 {
     $template->assign('navigation', $this->navigation);
 }
Exemplo n.º 4
0
 /**
  * Returns the content from a given template
  *
  * @param  string $template  The template to use.
  * @param  array  $variables The variables to assign.
  *
  * @return string
  */
 private function getTemplateContent($template, $variables = null)
 {
     // with the strpos we check if it is a frontend template, in that case we use the frontend template to prevent
     // errors that the template could not be found. This way we don't have a backwards compatibility break.
     if (APPLICATION !== 'Backend' || strpos($template, FRONTEND_CORE_PATH) !== false) {
         return Model::get('templating')->render($template, $variables);
     }
     $tpl = new BackendTemplate(false);
     // variables were set
     if (!empty($variables)) {
         $tpl->assign($variables);
     }
     // grab the content
     return $tpl->getContent($template);
 }