-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
According to the documentation at http://devdocs.magento.com/guides/v1.0/frontend-dev-guide/themes/theme-create.html#fedg_create_theme_how-to_declare the theme should be registered using a theme.xml file.
From the next paragraph it seems that the theme composer.json file is optional and only required when then theme should be distributed and installable via composer.
Not too long ago creating a theme with just a theme.xml worked.
In the current release Magento ver. 0.42.0-beta1 however both the theme.xml AND the composer.json files are required.
There is no indication that is the case however. If one of the two files is missing, the theme simply does not show up in the admin.
This happens because the title
and media
attributes are read from the theme.xml and the version
and parent
are read from the composer.json.
Here the excerpt from \Magento\Framework\Config\Theme::_extractData()
:
if (!empty($configContent)) {
$dom = new \DOMDocument();
$dom->loadXML($configContent);
// todo: validation of the document
/** @var $themeNode \DOMElement */
$themeNode = $dom->getElementsByTagName('theme')->item(0);
$data['title'] = $themeNode->getElementsByTagName('title')->item(0)->nodeValue;
/** @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);
}
I would prefer to simply do a pull request, but I'm unsure about the intended behaviour. Is this a bug or is it the intended behavior?
The theme.xsd indeed only references the title
and media
types.
Probably the reasoning behind moving the version and the parent theme into the composer.json file was that otherwise both files might become inconsistent. That makes sense, but at least to me it is ugly to require a composer.json file, even if the theme should not be distributed.
I think the most developer friendly process would be to keep the composer.json optional.
Please allow setting the version
and the parent
via the theme.xml file.
Then merge the composer.json settings.
Should the version
or parent
be set to a different value in the files, throw an exception.
This would be easy to implement, too.
On a side note:
The validators logging a message
'Field can't be empty' in .../app/code/Magento/Core/Model/Theme.php:326
is not very helpful without even the name of the field that can't be empty....