$packageUrl->value($packageArchive->getPackageInfo('packageurl'));
}
+ /** @var TextFormField $license */
+ $license = $this->form->getNodeById('license');
+ $xmlLicenses = $packageArchive->getPackageInfo('license');
+ if ($xmlLicenses !== null) {
+ if (count($xmlLicenses) === 1) {
+ $license->value(reset($xmlLicenses));
+ }
+ else {
+ $licenses = [];
+ foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
+ $licenses[$language->languageID] = '';
+
+ if (isset($xmlLicenses[$language->languageCode])) {
+ $licenses[$language->languageID] = $xmlLicenses[$language->languageCode];
+ }
+ else if (isset($xmlLicenses['default'])) {
+ $licenses[$language->languageID] = $xmlLicenses['default'];
+ }
+ }
+
+ $license->value($licenses);
+ }
+ }
+
/** @var TextFormField $author */
$author = $this->form->getNodeById('author');
if ($packageArchive->getAuthorInfo('author') !== null) {
}
/**
- * Writes the `packageinformation` element.
+ * Writes a child of the `packageinformation` element with i18n data.
+ *
+ * @param string $information
+ * @param null|string $elementName is set to lowercase version of `$information` if missing
*/
- protected function writePackageInformation() {
- $this->xmlWriter->startElement('packageinformation');
-
- $this->xmlWriter->writeComment(" {$this->packageXmlData['packageIdentifier']} ");
+ protected function writeI18nPackageInformation($information, $elementName = null) {
+ if ($elementName === null) {
+ $elementName = strtolower($information);
+ }
$english = LanguageFactory::getInstance()->getLanguageByCode('en');
- if (isset($this->packageXmlData['packageName_i18n'])) {
+ if (isset($this->packageXmlData[$information . '_i18n'])) {
$defaultLanguageID = null;
- if ($english !== null && isset($this->packageXmlData['packageName_i18n'][$english->languageID])) {
+ if ($english !== null && isset($this->packageXmlData[$information . '_i18n'][$english->languageID])) {
$defaultLanguageID = $english->languageID;
}
else {
- reset($this->packageXmlData['packageName_i18n']);
- $defaultLanguageID = key($this->packageXmlData['packageName_i18n']);
+ reset($this->packageXmlData[$information . '_i18n']);
+ $defaultLanguageID = key($this->packageXmlData[$information . '_i18n']);
}
$this->xmlWriter->writeElement(
- 'packagename',
- $this->packageXmlData['packageName_i18n'][$defaultLanguageID],
+ $elementName,
+ $this->packageXmlData[$information . '_i18n'][$defaultLanguageID],
[],
- $this->requiresCdata($this->packageXmlData['packageName_i18n'][$defaultLanguageID])
+ $this->requiresCdata($this->packageXmlData[$information . '_i18n'][$defaultLanguageID])
);
- foreach ($this->packageXmlData['packageName_i18n'] as $languageID => $packageName) {
+ foreach ($this->packageXmlData[$information . '_i18n'] as $languageID => $informationValue) {
if ($languageID !== $defaultLanguageID) {
$this->xmlWriter->writeElement(
- 'packagename',
- $packageName,
+ $elementName,
+ $informationValue,
['language' => LanguageFactory::getInstance()->getLanguage($languageID)->languageCode],
- $this->requiresCdata($packageName)
+ $this->requiresCdata($informationValue)
);
}
}
}
else {
$this->xmlWriter->writeElement(
- 'packagename',
- $this->packageXmlData['packageName'],
+ $elementName,
+ $this->packageXmlData[$information],
[],
- $this->requiresCdata($this->packageXmlData['packageName'])
+ $this->requiresCdata($this->packageXmlData[$information])
);
}
+ }
+
+ /**
+ * Writes the `packageinformation` element.
+ */
+ protected function writePackageInformation() {
+ $this->xmlWriter->startElement('packageinformation');
- if (isset($this->packageXmlData['packageDescription_i18n'])) {
- $defaultLanguageID = null;
- if (isset($this->packageXmlData['packageDescription_i18n'][$english->languageID])) {
- $defaultLanguageID = $english->languageID;
- }
- else {
- reset($this->packageXmlData['packageDescription_i18n']);
- $defaultLanguageID = key($this->packageXmlData['packageDescription_i18n']);
- }
-
- $this->xmlWriter->writeElement(
- 'packagedescription',
- $this->packageXmlData['packageDescription_i18n'][$defaultLanguageID],
- [],
- $this->requiresCdata($this->packageXmlData['packageDescription_i18n'][$defaultLanguageID])
- );
-
- foreach ($this->packageXmlData['packageDescription_i18n'] as $languageID => $packageDescription) {
- if ($languageID !== $defaultLanguageID) {
- $this->xmlWriter->writeElement(
- 'packagedescription',
- $packageDescription,
- ['language' => LanguageFactory::getInstance()->getLanguage($languageID)->languageCode],
- $this->requiresCdata($packageDescription)
- );
- }
- }
- }
- else {
- $this->xmlWriter->writeElement(
- 'packagedescription',
- $this->packageXmlData['packageDescription'],
- [],
- $this->requiresCdata($this->packageXmlData['packageDescription'])
- );
- }
+ $this->xmlWriter->writeComment(" {$this->packageXmlData['packageIdentifier']} ");
+
+ $this->writeI18nPackageInformation('packageName');
+ $this->writeI18nPackageInformation('packageDescription');
if (!empty($this->packageXmlData['isApplication'])) {
$this->xmlWriter->writeElement(
$this->requiresCdata($this->packageXmlData['packageUrl'])
);
}
+ $this->writeI18nPackageInformation('license');
$this->xmlWriter->endElement();
}