Skip to content

Commit 36d8dad

Browse files
committed
Merge pull request #155 from magento-mpi/develop
[MPI] Sprint 59
2 parents f8533bc + 41a87dd commit 36d8dad

File tree

92 files changed

+2269
-1024
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+2269
-1024
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ atlassian*
2020
/lib/internal/flex/varien/.project
2121
/lib/internal/flex/varien/.settings
2222
/node_modules
23+
/.grunt
2324

2425
/pub/media/*.*
2526
!/pub/media/.htaccess

app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ protected function _getGroupsForSave()
7272
$groups = $this->getRequest()->getPost('groups');
7373
$files = $this->getRequest()->getFiles('groups');
7474

75-
if (isset($files['name']) && is_array($files['name'])) {
75+
if ($files && is_array($files)) {
7676
/**
7777
* Carefully merge $_FILES and $_POST information
7878
* None of '+=' or 'array_merge_recursive' can do this correct
7979
*/
80-
foreach ($files['name'] as $groupName => $group) {
80+
foreach ($files as $groupName => $group) {
8181
$data = $this->_processNestedGroups($group);
8282
if (!empty($data)) {
8383
if (!empty($groups[$groupName])) {

app/code/Magento/Config/Test/Unit/Controller/Adminhtml/System/Config/_files/files_array.php

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,33 @@
55
*/
66

77
return [
8-
'name' => [
9-
'group.1' => [
10-
'fields' => ['f1.1' => ['value' => 'f1.1.val'], 'f1.2' => ['value' => 'f1.2.val']],
8+
'group.1' => [
9+
'fields' => ['f1.1' => ['value' => 'f1.1.val'], 'f1.2' => ['value' => 'f1.2.val']],
10+
],
11+
'group.2' => [
12+
'fields' => [
13+
'f2.1' => ['value' => 'f2.1.val'],
14+
'f2.2' => ['value' => 'f2.2.val'],
15+
'f2.3' => ['value' => ''],
1116
],
12-
'group.2' => [
13-
'fields' => [
14-
'f2.1' => ['value' => 'f2.1.val'],
15-
'f2.2' => ['value' => 'f2.2.val'],
16-
'f2.3' => ['value' => ''],
17-
],
18-
'groups' => [
19-
'group.2.1' => [
20-
'fields' => [
21-
'f2.1.1' => ['value' => 'f2.1.1.val'],
22-
'f2.1.2' => ['value' => 'f2.1.2.val'],
23-
'f2.1.3' => ['value' => ''],
24-
],
25-
'groups' => [
26-
'group.2.1.1' => [
27-
'fields' => [
28-
'f2.1.1.1' => ['value' => 'f2.1.1.1.val'],
29-
'f2.1.1.2' => ['value' => 'f2.1.1.2.val'],
30-
'f2.1.1.3' => ['value' => ''],
31-
],
17+
'groups' => [
18+
'group.2.1' => [
19+
'fields' => [
20+
'f2.1.1' => ['value' => 'f2.1.1.val'],
21+
'f2.1.2' => ['value' => 'f2.1.2.val'],
22+
'f2.1.3' => ['value' => ''],
23+
],
24+
'groups' => [
25+
'group.2.1.1' => [
26+
'fields' => [
27+
'f2.1.1.1' => ['value' => 'f2.1.1.1.val'],
28+
'f2.1.1.2' => ['value' => 'f2.1.1.2.val'],
29+
'f2.1.1.3' => ['value' => ''],
3230
],
3331
],
3432
],
3533
],
3634
],
37-
'group.3' => 'some.data',
38-
]
35+
],
36+
'group.3' => 'some.data',
3937
];
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\Developer\Model\Config\Source;
7+
8+
use Magento\Framework\App\State;
9+
use Magento\Framework\Option\ArrayInterface;
10+
11+
/**
12+
* Class WorkflowType
13+
*
14+
* @package Magento\Developer\Model\Config\Source
15+
*/
16+
class WorkflowType implements ArrayInterface
17+
{
18+
/**
19+
* Constant for
20+
*/
21+
const CONFIG_NAME_PATH = 'dev/front_end_development_workflow/type';
22+
23+
/**
24+
* Constant for server side compilation workflow
25+
*/
26+
const SERVER_SIDE_COMPILATION = 'server_side_compilation';
27+
28+
/**
29+
* Constant for client side compilation workflow
30+
*/
31+
const CLIENT_SIDE_COMPILATION = 'client_side_compilation';
32+
33+
/**
34+
* Return list of Workflow types
35+
*
36+
* @return array Format: array(array('value' => '<value>', 'label' => '<label>'), ...)
37+
*/
38+
public function toOptionArray()
39+
{
40+
return [
41+
['value' => self::CLIENT_SIDE_COMPILATION, 'label' => __('Client side less compilation')],
42+
['value' => self::SERVER_SIDE_COMPILATION, 'label' => __('Server side less compilation')]
43+
];
44+
}
45+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Developer\Model\View\Asset\PreProcessor;
7+
8+
use Magento\Framework\View\Asset\PreProcessor\Chain;
9+
use Magento\Framework\View\Asset\LocalInterface;
10+
11+
class DeveloperChain extends Chain
12+
{
13+
/**
14+
* @param LocalInterface $asset
15+
* @param string $origContent
16+
* @param string $origContentType
17+
* @param null $origAssetPath
18+
*/
19+
public function __construct(
20+
LocalInterface $asset,
21+
$origContent,
22+
$origContentType,
23+
$origAssetPath = null
24+
) {
25+
parent::__construct(
26+
$asset,
27+
$origContent,
28+
$origContentType
29+
);
30+
31+
$this->targetContentType = $this->origContentType;
32+
$this->targetAssetPath = $origAssetPath;
33+
}
34+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Developer\Model\View\Asset\PreProcessor;
7+
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use Magento\Framework\View\Asset\PreProcessor\ChainFactory;
10+
use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Developer\Model\Config\Source\WorkflowType;
13+
14+
class DeveloperChainFactory implements ChainFactoryInterface
15+
{
16+
/**
17+
* Object manager
18+
*
19+
* @var ObjectManagerInterface
20+
*/
21+
private $_objectManager;
22+
23+
/**
24+
* @var ChainFactory
25+
*/
26+
private $chainFactory;
27+
28+
/**
29+
* @var ScopeConfigInterface
30+
*/
31+
private $scopeConfig;
32+
33+
/**
34+
* @param ObjectManagerInterface $objectManager
35+
* @param ChainFactory $chainFactory
36+
* @param ScopeConfigInterface $scopeConfig
37+
*/
38+
public function __construct(
39+
ObjectManagerInterface $objectManager,
40+
ChainFactory $chainFactory,
41+
ScopeConfigInterface $scopeConfig
42+
) {
43+
$this->_objectManager = $objectManager;
44+
$this->chainFactory = $chainFactory;
45+
$this->scopeConfig = $scopeConfig;
46+
}
47+
48+
/**
49+
* {inheritdoc}
50+
*/
51+
public function create(array $arguments = [])
52+
{
53+
if (WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH)) {
54+
return $this->_objectManager->create(
55+
'Magento\Developer\Model\View\Asset\PreProcessor\DeveloperChain',
56+
$arguments
57+
);
58+
}
59+
return $this->chainFactory->create($arguments);
60+
}
61+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Developer\Model\View\Page\Config\ClientSideLessCompilation;
7+
8+
use Magento\Framework\View\Page\Config;
9+
10+
/**
11+
* Page config Renderer model
12+
*/
13+
class Renderer extends Config\Renderer
14+
{
15+
/**
16+
* @var \Magento\Framework\View\Asset\Repository
17+
*/
18+
private $assetRepo;
19+
20+
/**
21+
* @param Config $pageConfig
22+
* @param \Magento\Framework\View\Asset\MinifyService $assetMinifyService
23+
* @param \Magento\Framework\View\Asset\MergeService $assetMergeService
24+
* @param \Magento\Framework\UrlInterface $urlBuilder
25+
* @param \Magento\Framework\Escaper $escaper
26+
* @param \Magento\Framework\Stdlib\String $string
27+
* @param \Psr\Log\LoggerInterface $logger
28+
* @param \Magento\Framework\View\Asset\Repository $assetRepo
29+
*/
30+
public function __construct(
31+
Config $pageConfig,
32+
\Magento\Framework\View\Asset\MinifyService $assetMinifyService,
33+
\Magento\Framework\View\Asset\MergeService $assetMergeService,
34+
\Magento\Framework\UrlInterface $urlBuilder,
35+
\Magento\Framework\Escaper $escaper,
36+
\Magento\Framework\Stdlib\String $string,
37+
\Psr\Log\LoggerInterface $logger,
38+
\Magento\Framework\View\Asset\Repository $assetRepo
39+
) {
40+
$this->assetRepo = $assetRepo;
41+
42+
parent::__construct(
43+
$pageConfig,
44+
$assetMinifyService,
45+
$assetMergeService,
46+
$urlBuilder,
47+
$escaper,
48+
$string,
49+
$logger
50+
);
51+
}
52+
53+
/**
54+
* @param string $contentType
55+
* @param string $attributes
56+
* @return string
57+
*/
58+
protected function addDefaultAttributes($contentType, $attributes)
59+
{
60+
$taggedAttributes = parent::addDefaultAttributes($contentType, $attributes);
61+
62+
if ($taggedAttributes !== $attributes) {
63+
return $taggedAttributes;
64+
}
65+
66+
switch ($contentType) {
67+
case 'less':
68+
$taggedAttributes = ' rel="stylesheet/less" type="text/css" ' . ($attributes ?: ' media="all"');
69+
break;
70+
71+
}
72+
return $taggedAttributes;
73+
}
74+
75+
/**
76+
* Returns rendered HTML for all Assets (CSS before)
77+
*
78+
* @param array $resultGroups
79+
*
80+
* @return string
81+
*/
82+
public function renderAssets($resultGroups = [])
83+
{
84+
return parent::renderAssets($this->renderLessJsScripts($resultGroups));
85+
}
86+
87+
/**
88+
* Injecting less.js compiler
89+
*
90+
* @param array $resultGroups
91+
*
92+
* @return mixed
93+
*/
94+
private function renderLessJsScripts($resultGroups)
95+
{
96+
// less js have to be injected before any *.js in developer mode
97+
$lessJsConfigAsset = $this->assetRepo->createAsset('less/config.less.js');
98+
$resultGroups['js'] .= sprintf('<script src="%s"></script>' . "\n", $lessJsConfigAsset->getUrl());
99+
$lessJsAsset = $this->assetRepo->createAsset('less/less.min.js');
100+
$resultGroups['js'] .= sprintf('<script src="%s"></script>' . "\n", $lessJsAsset->getUrl());
101+
102+
return $resultGroups;
103+
}
104+
105+
/**
106+
* Render HTML tags referencing corresponding URLs
107+
*
108+
* @param string $template
109+
* @param array $assets
110+
* @return string
111+
*/
112+
protected function renderAssetHtml($template, $assets)
113+
{
114+
$result = '';
115+
try {
116+
foreach ($assets as $asset) {
117+
/** @var $asset \Magento\Framework\View\Asset\File */
118+
if ($asset instanceof \Magento\Framework\View\Asset\File
119+
&& $asset->getSourceUrl() != $asset->getUrl()
120+
) {
121+
$attributes = $this->addDefaultAttributes('less', []);
122+
$groupTemplate = $this->getAssetTemplate($asset->getContentType(), $attributes);
123+
$result .= sprintf($groupTemplate, $asset->getSourceUrl());
124+
} else {
125+
$result .= sprintf($template, $asset->getUrl());
126+
}
127+
}
128+
} catch (\Magento\Framework\Exception $e) {
129+
$this->logger->critical($e);
130+
$result .= sprintf($template, $this->urlBuilder->getUrl('', ['_direct' => 'core/index/notFound']));
131+
}
132+
return $result;
133+
}
134+
}

0 commit comments

Comments
 (0)