Skip to content
Snippets Groups Projects
Commit 2353daf0 authored by Vladimir Pelipenko's avatar Vladimir Pelipenko
Browse files

Merge pull request #16 from magento-extensibility/MAGETWO-31776-add-parent-element-theme

[Extensibility] Magetwo 31776 add parent element theme
parents a3981957 e0bb974e
Branches
No related merge requests found
......@@ -6,4 +6,6 @@
-->
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../../../../lib/internal/Magento/Framework/Config/etc/theme.xsd">
<title>Test2</title>
<version>0.1.2</version>
<parent>default_test</parent>
</theme>
{
"name": "magento/theme-area-test_default",
"description": "N/A",
"require": {
"php": "~5.4.11|~5.5.0",
"magento/framework": "0.1.0-alpha103",
"magento/magento-composer-installer": "*"
},
"type": "magento2-theme",
"version": "0.1.3"
}
......@@ -6,6 +6,7 @@
-->
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../../../../lib/internal/Magento/Framework/Config/etc/theme.xsd">
<title>Default</title>
<version>0.1.3</version>
<media>
<preview_image>media/test_default.jpg</preview_image>
</media>
......
{
"name": "magento/theme-area-test_external_package_descendant",
"description": "N/A",
"require": {
"php": "~5.4.11|~5.5.0",
"magento/framework": "0.1.0-alpha103",
"magento/theme-area-default_test2": "0.1.0",
"magento/magento-composer-installer": "*"
},
"type": "magento2-theme",
"version": "0.1.4"
}
......@@ -6,4 +6,6 @@
-->
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../../../../lib/internal/Magento/Framework/Config/etc/theme.xsd">
<title>Default</title>
<version>0.1.4</version>
<parent>default_test2</parent>
</theme>
......@@ -6,4 +6,5 @@
-->
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../../lib/internal/Magento/Framework/Config/etc/theme.xsd">
<title>Default</title>
<version>0.1.0-alpha108</version>
</theme>
......@@ -28,13 +28,10 @@ class Theme
* Constructor
*
* @param string $configContent
* @param string $composerContent
*/
public function __construct(
$configContent = null,
$composerContent = null
) {
$this->_data = $this->_extractData($configContent, $composerContent);
public function __construct($configContent = null)
{
$this->_data = $this->_extractData($configContent);
}
/**
......@@ -48,13 +45,12 @@ class Theme
}
/**
* Extract configuration data from theme.xml and composer.json
* Extract configuration data from theme.xml
*
* @param string $configContent
* @param string $composerContent
* @return array
*/
protected function _extractData($configContent, $composerContent)
protected function _extractData($configContent)
{
$data = [
'version' => null,
......@@ -69,20 +65,16 @@ class Theme
// todo: validation of the document
/** @var $themeNode \DOMElement */
$themeNode = $dom->getElementsByTagName('theme')->item(0);
$data['title'] = $themeNode->getElementsByTagName('title')->item(0)->nodeValue;
$themeTitleNode = $themeNode->getElementsByTagName('title')->item(0);
$data['title'] = $themeTitleNode ? $themeTitleNode->nodeValue : null;
/** @var $mediaNode \DOMElement */
$mediaNode = $themeNode->getElementsByTagName('media')->item(0);
$previewImage = $mediaNode ? $mediaNode->getElementsByTagName('preview_image')->item(0)->nodeValue : '';
$data['media']['preview_image'] = $previewImage;
}
if (!empty($composerContent)) {
$json = json_decode($composerContent);
$package = new Package($json);
$data['version'] = $package->get('version');
$parents = (array)$package->get('require', '/.+\/theme-/');
$parents = empty($parents) ? null : array_keys($parents);
$data['parent'] = empty($parents) ? null : array_shift($parents);
$themeVersionNode = $themeNode->getElementsByTagName('version')->item(0);
$data['version'] = $themeVersionNode ? $themeVersionNode->nodeValue : null;
$themeParentNode = $themeNode->getElementsByTagName('parent')->item(0);
$data['parent'] = $themeParentNode ? $themeParentNode->nodeValue : null;
}
return $data;
......@@ -129,28 +121,6 @@ class Theme
if (!$parentTheme) {
return null;
}
$parent = $this->parseThemeName($parentTheme);
return [ucfirst($parent['vendor']), $parent['name']];
}
/**
* Parse theme name
*
* @param string $themeName
* @return array|null Return array if theme name is in the right format, otherwise null is returned, for example:
* [
* 'vendor' => 'magento',
* 'area' => 'frontend',
* 'name' => 'luma'
* ]
*/
private function parseThemeName($themeName)
{
preg_match('/(?<vendor>.+)\/theme-(?<area>.+)-(?<name>.+)/', $themeName, $matches);
return [
'vendor' => $matches['vendor'],
'area' => $matches['area'],
'name' => $matches['name'],
];
return explode(self::THEME_PATH_SEPARATOR, $parentTheme);
}
}
......@@ -15,6 +15,8 @@
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="title"/>
<xs:element name="version" type="version"/>
<xs:element name="parent" type="parent_theme" minOccurs="0"/>
<xs:element name="media" type="media" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
......@@ -26,6 +28,18 @@
</xs:restriction>
</xs:simpleType>
<!-- Short theme name: '<theme>'. Fully-qualified theme name: '<path>/<theme>'. -->
<xs:simpleType name="parent_theme">
<xs:restriction base="xs:string">
<xs:pattern value="([^/]+/)?[^/]+"></xs:pattern>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="version">
<xs:restriction base="xs:string">
<xs:pattern value="(\d+.\d+.\d+(\-[a-zA-Z0-9]+)?)|\*"></xs:pattern>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="media">
<xs:sequence>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment