Skip to content

Commit

Permalink
[TASK] Add extension title to meta data and use it
Browse files Browse the repository at this point in the history
Instead of reading the composer.json / ext_emconf.php
of extensions at runtime just to retrieve the extension title,
use the existing package meta data API to store and retrieve this
information.

With these changes in place, the workaround for title handling can be
removed and CLI extension list can also use the new API and show the
(shorter) title instead of the description.

In the long run, it should be evaluated, whether the UI
can be changed to be able to show longer descriptions, or
whether a short description (aka title) is important enough
to introduce a public configuration for it.

Releases: master
Resolves: #95701
Change-Id: Iee51f200bb5017f3a6516ebf9e55b2c6eb125949
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/71888
Tested-by: core-ci <typo3@b13.com>
Tested-by: Simon Gilli <typo3@gilbertsoft.org>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Helmut Hummel <typo3@helhum.io>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Simon Gilli <typo3@gilbertsoft.org>
Reviewed-by: Helmut Hummel <typo3@helhum.io>
  • Loading branch information
helhum committed Oct 21, 2021
1 parent a167909 commit 3098465
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
6 changes: 3 additions & 3 deletions typo3/sysext/core/Classes/Command/ExtensionListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ protected function execute(InputInterface $input, OutputInterface $output)

$table->addRow([$package->getPackageKey(), $package->getPackageMetaData()->getVersion(), $type, $status]);

// Also show the description of the extension, if verbose option is set
// Also show the title of the extension, if verbose option is set
if ($output->isVerbose()) {
$description = (string)$package->getValueFromComposerManifest('description');
$table->addRow([new TableCell(' ' . $formatter->truncate($description, 80) . "\n\n", ['colspan' => 4])]);
$title = (string)$package->getPackageMetaData()->getTitle();
$table->addRow([new TableCell(' ' . $formatter->truncate($title, 80) . "\n\n", ['colspan' => 4])]);
}
}
$table->render();
Expand Down
20 changes: 20 additions & 0 deletions typo3/sysext/core/Classes/Composer/PackageArtifactBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function run(Event $event): bool
foreach ($this->extractPackageMapFromComposer() as [$composerPackage, $path, $extensionKey]) {
$packagePath = PathUtility::sanitizeTrailingSeparator($path);
$package = new Package($this, $extensionKey, $packagePath, true);
$this->setTitleFromExtEmConf($package);
$package->makePathRelative(new Filesystem(), $basePath);
$package->getPackageMetaData()->setVersion($composerPackage->getPrettyVersion());
$this->registerPackage($package);
Expand All @@ -98,6 +99,25 @@ public function run(Event $event): bool
return true;
}

/**
* Sets a title for the package from ext_emconf.php in case this file exists
* @todo deprecate or remove in TYPO3 v12
*
* @param Package $package
*/
private function setTitleFromExtEmConf(Package $package): void
{
$emConfPath = $package->getPackagePath() . '/ext_emconf.php';
if (file_exists($emConfPath)) {
$_EXTKEY = $package->getPackageKey();
$EM_CONF = null;
include $emConfPath;
if (!empty($EM_CONF[$_EXTKEY]['title'])) {
$package->getPackageMetaData()->setTitle($EM_CONF[$_EXTKEY]['title']);
}
}
}

/**
* Sorts all TYPO3 extension packages by dependency defined in composer.json file
*/
Expand Down
12 changes: 11 additions & 1 deletion typo3/sysext/core/Classes/Package/MetaData.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MetaData

/**
* Package title
* @var string
* @var ?string
*/
protected $title;

Expand Down Expand Up @@ -142,6 +142,16 @@ public function setVersion($version)
$this->version = $version;
}

public function getTitle(): ?string
{
return $this->title;
}

public function setTitle(?string $title): void
{
$this->title = $title;
}

/**
* @return string The package description
*/
Expand Down
9 changes: 3 additions & 6 deletions typo3/sysext/core/Classes/Package/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
*/
class Package implements PackageInterface
{
/**
* @var array
*/
protected $extensionManagerConfiguration = [];

/**
* If this package is part of factory default, it will be activated
* during first installation.
Expand Down Expand Up @@ -143,7 +138,9 @@ protected function loadFlagsFromComposerManifest()
protected function createPackageMetaData(PackageManager $packageManager)
{
$this->packageMetaData = new MetaData($this->getPackageKey());
$this->packageMetaData->setDescription($this->getValueFromComposerManifest('description'));
$description = $this->getValueFromComposerManifest('description');
$this->packageMetaData->setDescription($description);
$this->packageMetaData->setTitle($this->getValueFromComposerManifest('title') ?? $description);
$this->packageMetaData->setVersion($this->getValueFromComposerManifest('version'));
$this->packageMetaData->setPackageType($this->getValueFromComposerManifest('type'));
$requirements = $this->getValueFromComposerManifest('require');
Expand Down
2 changes: 2 additions & 0 deletions typo3/sysext/core/Classes/Package/PackageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,8 @@ protected function mapExtensionManagerConfigurationToComposerManifest($packageKe
$this->setComposerManifestValueIfEmpty($composerManifest, 'description', $extensionManagerConfiguration['title'] ?? '');
$this->setComposerManifestValueIfEmpty($composerManifest, 'authors', [['name' => $extensionManagerConfiguration['author'] ?? '', 'email' => $extensionManagerConfiguration['author_email'] ?? '']]);
$composerManifest->version = $extensionManagerConfiguration['version'] ?? '';
// "Invent" a new title attribute here for internal use in non Composer mode
$composerManifest->title = $extensionManagerConfiguration['title'] ?? null;
$composerManifest->require = new \stdClass();
$composerManifest->conflict = new \stdClass();
$composerManifest->suggest = new \stdClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function getAvailableExtensions(string $filter = ''): array
'version' => $version,
'state' => str_starts_with($version, 'dev-') ? 'alpha' : ($properties['state'] ?? 'stable'),
'icon' => $icon ? PathUtility::getAbsoluteWebPath($package->getPackagePath() . $icon) : '',
'title' => $package->getValueFromComposerManifest('description') ?? '',
'title' => $package->getPackageMetaData()->getTitle(),
];
$this->availableExtensions[$package->getPackageKey()] = $extensionData;
}
Expand Down Expand Up @@ -210,11 +210,6 @@ public function enrichExtensionsWithEmConfInformation(array $extensions)
continue;
}
$extensions[$extensionKey] = array_merge($emConf, $properties);
if (isset($emConf['title'])) {
// Prefer every property from package information, but allow title from
// ext_emconf.php to take precedence, as there is no appropriate property for this yet in composer.json
$extensions[$extensionKey]['title'] = $emConf['title'];
}
}
return $extensions;
}
Expand Down

0 comments on commit 3098465

Please sign in to comment.