Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function addStylesheet($stylesheet, $type = self::TYPE_FILE)
 {
     $this->cache['stylesheets'][] = [$stylesheet, $type];
     switch ($type) {
         case static::TYPE_SOURCE:
             $GLOBALS['TL_HEAD'][] = sprintf('<style>%s</style>', $stylesheet);
             break;
         case static::TYPE_FILE:
         default:
             $this->assetsManager->addStylesheet($stylesheet);
     }
 }
 /**
  * Inject the form validation.
  *
  * It's not possible to use the getForm hook for it. It's not called.
  *
  * @param \FormFieldModel[] $fields Form field widgets.
  * @param string            $formId The form id.
  * @param \FormModel        $model  The form model.
  *
  * @see    https://github.com/contao/core/issues/7660
  * @return \FormFieldModel[]
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function injectFormValidation($fields, $formId, $model)
 {
     if (TL_MODE === 'FE' && $model->fv_active && $model->fv_setting && !isset($this->loaded[$model->id])) {
         $settings = ValidationModel::findByPk($model->fv_setting);
         $this->assetsManager->addStylesheet($this->assetPath . '/css/formValidation.min.css', 'screen');
         $this->assetsManager->addJavascript($this->assetPath . '/js/formValidation.min.js');
         if ($settings && in_array($settings->framework, $this->frameworks)) {
             $this->assetsManager->addJavascript(sprintf('%s/js/framework/%s.min.js', $this->assetPath, $settings->framework));
         }
         if ($this->locale) {
             $this->assetsManager->addJavascript(sprintf('%s/js/language/%s.js', $this->assetPath, $this->locale));
         }
         $this->assetsManager->addJavascript($this->getValidationJavascript($model, $fields, $settings), false);
         $this->loaded[$model->id] = true;
     }
     return $fields;
 }