Skip to content

Commit

Permalink
Merge pull request #27 from OpenForgeProject/list-themes
Browse files Browse the repository at this point in the history
add ListThemesCommand
  • Loading branch information
dermatz authored Dec 13, 2024
2 parents 78b6f46 + caadb45 commit b50645a
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file.
- changed Repository URLs
- added codacy code-quality badge to `README.md`
- moved to OpenForgeProject
- add ListThemesCommand

---

Expand Down
66 changes: 66 additions & 0 deletions src/Console/Command/ListThemesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace OpenForgeProject\MageForge\Console\Command;

use OpenForgeProject\MageForge\Model\ThemeList;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Framework\Console\Cli;

class ListThemesCommand extends Command
{
/**
* Constructor
*
* @param ThemeList $themeList
*/
public function __construct(
private readonly ThemeList $themeList,
) {
parent::__construct();
}

/**
* Configure the command
*/
protected function configure(): void
{
$this->setName('mageforge:themes:list');
$this->setDescription('Lists all available themes');
}

/**
* Execute the command
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(
InputInterface $input,
OutputInterface $output,
): int {
$themes = $this->themeList->getAllThemes();

if (empty($themes)) {
$output->writeln('<info>No themes found.</info>');
return Cli::RETURN_SUCCESS;
}

$output->writeln('<info>Available Themes:</info>');
foreach ($themes as $path => $theme) {
$output->writeln(
sprintf(
'<comment>%s</comment> - %s',
$path,
$theme->getThemeTitle(),
),
);
}

return Cli::RETURN_SUCCESS;
}
}
30 changes: 30 additions & 0 deletions src/Model/ThemeList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace OpenForgeProject\MageForge\Model;

use Magento\Framework\View\Design\Theme\ThemeList as MagentoThemeList;

class ThemeList
{
/**
* Constructor
*
* @param MagentoThemeList $magentoThemeList
*/
public function __construct(
private readonly MagentoThemeList $magentoThemeList
) {
}

/**
* Get all themes
*
* @return array
*/
public function getAllThemes(): array
{
return $this->magentoThemeList->getItems();
}
}
4 changes: 4 additions & 0 deletions src/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
name="openforgeproject_mageforge_system_check"
xsi:type="object"
>OpenForgeProject\MageForge\Console\Command\SystemCheckCommand</item>
<item
name="openforgeproject_mageforge_themes_list"
xsi:type="object"
>OpenForgeProject\MageForge\Console\Command\ListThemesCommand</item>
</argument>
</arguments>
</type>
Expand Down

0 comments on commit b50645a

Please sign in to comment.