Example #1
0
 /**
  * Apply custom css
  *
  * @return  CustomCss
  */
 public function apply()
 {
     if (method_exists($this->view, 'plugin')) {
         $global = false;
         $roots = (array) $this->roots;
         $headLink = $this->getHeadLinkHelper();
         if (in_array(null, $roots)) {
             $global = true;
         }
         $roots = array_filter($roots);
         if ($global) {
             $roots[] = null;
         }
         $find = array();
         $urls = array();
         $preview = false;
         foreach ($roots as $root) {
             if ($this->cssPreview->hasPreviewById($root)) {
                 $urls[$root] = $this->cssPreview->getPreviewById($root);
             }
             if (empty($urls[$root])) {
                 $find[] = $root;
             } else {
                 $preview = true;
             }
         }
         if (!empty($find)) {
             $url = $this->getUrlHelper();
             $siteInfo = $this->getSiteInfo();
             $schema = $siteInfo->getSchema();
             $updated = $this->extraModel->findUpdated($find);
             foreach ($find as $root) {
                 if (isset($updated[$root])) {
                     $urls[$root] = $url('Grid\\Customize\\Render\\CustomCss', array('schema' => $schema, 'id' => $root ? (int) $root : 'global', 'hash' => $updated[$root]->toHash()));
                 }
             }
         }
         foreach ($roots as $root) {
             if (!empty($urls[$root])) {
                 $id = $root ? (int) $root : 'global';
                 $headLink->prependStylesheet($urls[$root], 'all', false, array('class' => 'customize-stylesheet', 'data-customize' => $id));
             }
         }
         if ($preview) {
             if (empty($url)) {
                 $url = $this->getUrlHelper();
             }
             $translate = $this->getTranslateHelper();
             $this->getMessengerHelper()->add(sprintf($translate('customize.preview.applied.reset-link.%s', 'customize'), $url('Grid\\Customize\\CssAdmin\\ResetPreviews', array('locale' => \Locale::getDefault()))), false, Message::LEVEL_WARN);
         }
         $this->roots = array();
     }
     return $this;
 }