Skip to content

Commit d94a581

Browse files
author
Leonid Poluyanov
committed
Merge remote-tracking branch 'origin/MAGETWO-43084' into develop
2 parents fa99128 + 00d1ab1 commit d94a581

File tree

7 files changed

+73
-110
lines changed

7 files changed

+73
-110
lines changed

app/code/Magento/CmsSampleData/Setup/Installer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
*/
66
namespace Magento\CmsSampleData\Setup;
@@ -17,7 +17,7 @@ class Installer implements Setup\SampleData\InstallerInterface
1717
/**
1818
* Setup class for css
1919
*
20-
* @var \Magento\CmsSampleData\Model\Css
20+
* @var \Magento\ThemeSampleData\Model\Css
2121
*/
2222
private $css;
2323

@@ -33,13 +33,13 @@ class Installer implements Setup\SampleData\InstallerInterface
3333

3434
/**
3535
* @param \Magento\CatalogSampleData\Model\Category $category
36-
* @param \Magento\CmsSampleData\Model\Css $css
36+
* @param \Magento\ThemeSampleData\Model\Css $css
3737
* @param \Magento\CmsSampleData\Model\Page $page
3838
* @param \Magento\CmsSampleData\Model\Block $block
3939
*/
4040
public function __construct(
4141
\Magento\CatalogSampleData\Model\Category $category,
42-
\Magento\CmsSampleData\Model\Css $css,
42+
\Magento\ThemeSampleData\Model\Css $css,
4343
\Magento\CmsSampleData\Model\Page $page,
4444
\Magento\CmsSampleData\Model\Block $block
4545
) {

app/code/Magento/CmsSampleData/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"php": "~5.5.0|~5.6.0|~7.0.0",
66
"magento/module-cms": "1.0.0-beta",
77
"magento/module-sample-data": "1.0.0-beta",
8+
"magento/module-theme-sample-data": "1.0.0-beta",
89
"magento/sample-data-media": "1.0.0-beta"
910
},
1011
"type": "magento2-module",

app/code/Magento/CmsSampleData/Model/Css.php renamed to app/code/Magento/ThemeSampleData/Model/Css.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © 2015 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\CmsSampleData\Model;
6+
namespace Magento\ThemeSampleData\Model;
77

88
use Magento\Framework\Setup\SampleData\Context as SampleDataContext;
99

app/code/Magento/CmsSampleData/Model/HeadStyle.php renamed to app/code/Magento/ThemeSampleData/Model/HeadStyle.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\CmsSampleData\Model;
7+
namespace Magento\ThemeSampleData\Model;
88

99
use Magento\Framework\Setup;
1010
use Magento\Framework\App\Config\ScopeConfigInterface;
@@ -16,13 +16,6 @@
1616
*/
1717
class HeadStyle
1818
{
19-
/**
20-
* Url configuration
21-
*
22-
* @var \Magento\Framework\UrlInterface
23-
*/
24-
protected $baseUrl;
25-
2619
/**
2720
* @var \Magento\Framework\App\Config\ScopeConfigInterface
2821
*/
@@ -44,21 +37,18 @@ class HeadStyle
4437
private $directoryList;
4538

4639
/**
47-
* @param \Magento\Framework\UrlInterface $baseUrl
4840
* @param ScopeConfigInterface $scopeConfig
4941
* @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter
5042
* @param \Magento\Framework\App\Cache\Type\Config $configCacheType
5143
* @param \Magento\Framework\App\Filesystem\DirectoryList $directoryList
5244
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
5345
*/
5446
public function __construct(
55-
\Magento\Framework\UrlInterface $baseUrl,
5647
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
5748
\Magento\Framework\App\Config\Storage\WriterInterface $configWriter,
5849
\Magento\Framework\App\Cache\Type\Config $configCacheType,
5950
\Magento\Framework\App\Filesystem\DirectoryList $directoryList
6051
) {
61-
$this->baseUrl = $baseUrl;
6252
$this->scopeConfig = $scopeConfig;
6353
$this->configWriter = $configWriter;
6454
$this->configCacheType = $configCacheType;
@@ -76,8 +66,7 @@ public function add($contentFile, $cssFile)
7666
file_put_contents("{$mediaDir}/{$cssFile}", $styleContent, FILE_APPEND);
7767

7868
$linkText = sprintf(
79-
'<link rel="stylesheet" type="text/css" media="all" href="%s%s" />',
80-
$this->baseUrl->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]),
69+
'<link rel="stylesheet" type="text/css" media="all" href="{{MEDIA_URL}}%s" />',
8170
$cssFile
8271
);
8372

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ThemeSampleData\Plugin\View\Page;
7+
8+
use Magento\Framework\UrlInterface;
9+
use Magento\Framework\View\Page\Config as PageConfig;
10+
11+
class Config
12+
{
13+
/**
14+
* Url configuration
15+
*
16+
* @var \Magento\Framework\UrlInterface
17+
*/
18+
protected $baseUrl;
19+
20+
/**
21+
* @param UrlInterface $baseUrl
22+
*/
23+
public function __construct(
24+
\Magento\Framework\UrlInterface $baseUrl
25+
) {
26+
$this->baseUrl = $baseUrl;
27+
}
28+
29+
/**
30+
* @param PageConfig $subject
31+
* @param string $result
32+
* @return string
33+
*
34+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
35+
*/
36+
public function afterGetIncludes(PageConfig $subject, $result)
37+
{
38+
$pattern = '{{MEDIA_URL}}';
39+
if (strpos($result, $pattern) !== false) {
40+
$url = $this->baseUrl->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]);
41+
$result = str_replace($pattern, $url, $result);
42+
}
43+
return $result;
44+
}
45+
}
Lines changed: 8 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
*/
66
namespace 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
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Framework\View\Page\Config">
10+
<plugin name="headIncludes" type="Magento\ThemeSampleData\Plugin\View\Page\Config" />
11+
</type>
12+
</config>

0 commit comments

Comments
 (0)