11<?php
22/**
3- * Copyright © 2015 Magento. All rights reserved.
3+ * Copyright � 2015 Magento. All rights reserved.
44 * See COPYING.txt for license details.
55 */
66namespace Magento \ThemeSampleData \Setup ;
@@ -22,75 +22,25 @@ class Installer implements Setup\SampleData\InstallerInterface
2222 private $ collectionFactory ;
2323
2424 /**
25- * Url configuration
25+ * Setup class for css
2626 *
27- * @var \Magento\Framework\UrlInterface
27+ * @var \Magento\ThemeSampleData\Model\Css
2828 */
29- protected $ baseUrl ;
30-
31- /**
32- * @var \Magento\Framework\App\Config\ScopeConfigInterface
33- */
34- protected $ scopeConfig ;
35-
36- /**
37- * @var \Magento\Framework\App\Config\Storage\WriterInterface
38- */
39- protected $ configWriter ;
40-
41- /**
42- * @var \Magento\Framework\App\Cache\Type\Config
43- */
44- protected $ configCacheType ;
45-
46- /**
47- * @var \Magento\Framework\App\Filesystem\DirectoryList
48- */
49- private $ directoryList ;
50-
51- /**
52- * @var \Magento\Framework\Module\ModuleListInterface
53- */
54- protected $ moduleList ;
55-
56- /**
57- * @var \Magento\Framework\Setup\SampleData\FixtureManager
58- */
59- protected $ fixtureManager ;
29+ private $ css ;
6030
6131 /**
6232 * @param \Magento\Theme\Model\Config $config
6333 * @param \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory $collectionFactory
64- * @param \Magento\Framework\UrlInterface $baseUrl
65- * @param ScopeConfigInterface $scopeConfig
66- * @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter
67- * @param \Magento\Framework\App\Cache\Type\Config $configCacheType
68- * @param \Magento\Framework\App\Filesystem\DirectoryList $directoryList
69- * @param \Magento\Framework\Module\ModuleListInterface $moduleList
70- * @param Setup\SampleData\Context $sampleDataContext
71- *
72- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
34+ * @param \Magento\ThemeSampleData\Model\Css $css
7335 */
7436 public function __construct (
7537 \Magento \Theme \Model \Config $ config ,
7638 \Magento \Theme \Model \ResourceModel \Theme \CollectionFactory $ collectionFactory ,
77- \Magento \Framework \UrlInterface $ baseUrl ,
78- \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
79- \Magento \Framework \App \Config \Storage \WriterInterface $ configWriter ,
80- \Magento \Framework \App \Cache \Type \Config $ configCacheType ,
81- \Magento \Framework \App \Filesystem \DirectoryList $ directoryList ,
82- \Magento \Framework \Module \ModuleListInterface $ moduleList ,
83- Setup \SampleData \Context $ sampleDataContext
39+ \Magento \ThemeSampleData \Model \Css $ css
8440 ) {
8541 $ this ->config = $ config ;
8642 $ this ->collectionFactory = $ collectionFactory ;
87- $ this ->baseUrl = $ baseUrl ;
88- $ this ->scopeConfig = $ scopeConfig ;
89- $ this ->configWriter = $ configWriter ;
90- $ this ->configCacheType = $ configCacheType ;
91- $ this ->directoryList = $ directoryList ;
92- $ this ->moduleList = $ moduleList ;
93- $ this ->fixtureManager = $ sampleDataContext ->getFixtureManager ();
43+ $ this ->css = $ css ;
9444 }
9545
9646 /**
@@ -99,7 +49,7 @@ public function __construct(
9949 public function install ()
10050 {
10151 $ this ->assignTheme ();
102- $ this ->addHeadInclude ( );
52+ $ this ->css -> install ([ ' Magento_CmsSampleData::fixtures/styles.css ' => ' styles.css ' ] );
10353 }
10454
10555 /**
@@ -121,38 +71,4 @@ protected function assignTheme()
12171 }
12272 }
12373 }
124-
125- /**
126- * Add Link to Head
127- *
128- * @return void
129- */
130- protected function addHeadInclude ()
131- {
132- $ styleContent = '' ;
133- foreach ($ this ->moduleList ->getNames () as $ moduleName ) {
134- $ fileName = $ moduleName . '::fixtures/styles.css ' ;
135- $ fileName = $ this ->fixtureManager ->getFixture ($ fileName );
136- if (!file_exists ($ fileName )) {
137- continue ;
138- }
139- $ style = file_get_contents ($ fileName );
140- $ styleContent .= preg_replace ('/^\/\*[\s\S]+\*\// ' , '' , $ style );
141- }
142- if (empty ($ styleContent )) {
143- return ;
144- }
145- $ mediaDir = $ this ->directoryList ->getPath (\Magento \Framework \App \Filesystem \DirectoryList::MEDIA );
146- file_put_contents ("$ mediaDir/styles.css " , $ styleContent );
147- $ linkTemplate = '<link rel="stylesheet" type="text/css" media="all" href="%sstyles.css" /> ' ;
148- $ baseUrl = $ this ->baseUrl ->getBaseUrl (['_type ' => \Magento \Framework \UrlInterface::URL_TYPE_MEDIA ]);
149- $ linkText = sprintf ($ linkTemplate , $ baseUrl );
150-
151- $ miscScriptsNode = 'design/head/includes ' ;
152- $ miscScripts = $ this ->scopeConfig ->getValue ($ miscScriptsNode );
153- if (!$ miscScripts || strpos ($ miscScripts , $ linkText ) === false ) {
154- $ this ->configWriter ->save ($ miscScriptsNode , $ miscScripts . $ linkText );
155- $ this ->configCacheType ->clean ();
156- }
157- }
15874}
0 commit comments