Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions Classes/Command/PluginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;

class PluginCommand extends Command
{
Expand Down Expand Up @@ -110,7 +111,8 @@ private function askForPluginInformation(CommandContext $commandContext): Plugin
$referencedControllerActions = [];
$isTypoScriptCreation = false;
$typoScriptSet = null;
$templatePath = '';
$templatePath = sprintf('EXT:%s/Resources/Private/', $extensionInformation->getExtensionKey());
$templates = [];
if ($isExtbasePlugin) {
$referencedControllerActions = $this->askForReferencedControllerActions(
$commandContext,
Expand All @@ -130,9 +132,28 @@ private function askForPluginInformation(CommandContext $commandContext): Plugin

$templatePath = $io->ask(
'To which path do you want to add the Fluid templates?',
sprintf('EXT:%s/Resources/Private/', $extensionInformation->getExtensionKey())
$templatePath
);
}

$possibleTemplates = [];
foreach ($referencedControllerActions as $controller => $actions) {
foreach ($actions['cached'] as $action) {
$possibleTemplates[] =
sprintf(
'%sTemplates/%s/%s.fluid.html',
$templatePath,
ExtensionUtility::resolveControllerAliasFromControllerClassName($controller),
ucfirst(preg_replace('/Action$/', '', $action))
);
}
}
$templates = $io->choice(
'Which templates do you want to create? ',
$possibleTemplates,
null,
true
);
}

return new PluginInformation(
Expand All @@ -146,6 +167,7 @@ private function askForPluginInformation(CommandContext $commandContext): Plugin
$isTypoScriptCreation,
$typoScriptSet,
$templatePath,
$templates,
);
}

Expand Down
5 changes: 3 additions & 2 deletions Classes/Creator/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public function createFile(string $targetFile, string $content, CreatorInformati
$result = file_put_contents($targetFile, $content);
if ($result === false) {
$creatorInformation->writingFileFailed($targetFile);
} else {
$creatorInformation->fileAdded($targetFile);
return 0;
}
$creatorInformation->fileAdded($targetFile);

return $result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\NodeFinder;
Expand Down Expand Up @@ -145,10 +144,6 @@ private function getExpressionForConfigurePlugin(PluginInformation $pluginInform
$pluginInformation->getPluginName(),
new Array_($this->getReferencedControllerActions($pluginInformation, true)),
new Array_($this->getReferencedControllerActions($pluginInformation, false)),
new ClassConstFetch(
new Name('ExtensionUtility'),
'PLUGIN_TYPE_CONTENT_ELEMENT'
),
]
));
}
Expand Down
85 changes: 85 additions & 0 deletions Classes/Creator/Plugin/Extbase/TemplatesCreator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package friendsoftypo3/kickstarter.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace FriendsOfTYPO3\Kickstarter\Creator\Plugin\Extbase;

use FriendsOfTYPO3\Kickstarter\Creator\FileManager;
use FriendsOfTYPO3\Kickstarter\Information\PluginInformation;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Creates the templates for the actions of a plugin
*/
class TemplatesCreator implements ExtbasePluginCreatorInterface
{
public function __construct(
private readonly FileManager $fileManager,
) {}

public function create(PluginInformation $pluginInformation): void
{
$templatePath = str_replace(
'EXT:' . $pluginInformation->getExtensionInformation()->getExtensionKey() . '/',
$pluginInformation->getExtensionInformation()->getExtensionPath(),
$pluginInformation->getTemplatePath()
);
GeneralUtility::mkdir_deep($templatePath . 'Templates');
GeneralUtility::mkdir_deep($templatePath . 'Partials');
GeneralUtility::mkdir_deep($templatePath . 'Layouts');

$this->fileManager->createOrModifyFile($templatePath . 'Templates/.gitkeep', '', $pluginInformation->getCreatorInformation());
$this->fileManager->createOrModifyFile($templatePath . 'Partials/.gitkeep', '', $pluginInformation->getCreatorInformation());
$this->fileManager->createOrModifyFile($templatePath . 'Layouts/.gitkeep', '', $pluginInformation->getCreatorInformation());

if (count($pluginInformation->getTemplates()) > 0) {

$this->fileManager->createFile($templatePath . 'Layouts/Default.fluid.html', $this->getDefaultLayout($pluginInformation), $pluginInformation->getCreatorInformation());
}

foreach ($pluginInformation->getTemplates() as $template) {
$path = str_replace(
'EXT:' . $pluginInformation->getExtensionInformation()->getExtensionKey() . '/',
$pluginInformation->getExtensionInformation()->getExtensionPath(),
$template
);

GeneralUtility::mkdir_deep(dirname($path));
$this->fileManager->createFile($path, $this->getDefaultTemplate($template), $pluginInformation->getCreatorInformation());
}
}

private function getDefaultTemplate(string $template, string $layout = 'Default'): string
{
return sprintf(<<<'EOT'
<html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="%s"/>

<f:section name="content">
<p>TODO: Modify file <code>%s</code></p>
</f:section>
</html>
EOT, $layout, $template);
}

private function getDefaultLayout(PluginInformation $pluginInformation): string
{
return sprintf(<<<'EOT'
<html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<div class="%s">
<f:flashMessages />

<f:render section="content" />
</div>
</html>

EOT, $pluginInformation->getTypoScriptPluginNamespace());
}
}
41 changes: 41 additions & 0 deletions Classes/Information/PluginInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,44 @@ public function __construct(
private bool $typoScriptCreation = false,
private ?string $set = '',
private string $templatePath = '',
private array $templates = [],
) {}

/**
* Convenience factory for tests
* Unknown keys are ignored.
*/
public static function fromArray(
array $info,
ExtensionInformation $extensionInformation
): self {
$extbasePlugin = array_key_exists('extbasePlugin', $info) && (bool)$info['extbasePlugin'];
$pluginLabel = $info['pluginLabel'] ?? '';
$pluginName = $info['pluginName'] ?? '';
$pluginDescription = $info['pluginDescription'] ?? '';
$referencedControllerActions = $info['referencedControllerActions'] ?? [];

$creatorInformation = $info['creatorInformation'] ?? new CreatorInformation();
$typoScriptCreation = array_key_exists('typoScriptCreation', $info) && (bool)$info['typoScriptCreation'];
$set = array_key_exists('set', $info) ? (string)$info['set'] : '';
$templatePath = $info['templatePath'] ?? '';
$templates = $info['templates'] ?? [];

return new self(
extensionInformation: $extensionInformation,
extbasePlugin: $extbasePlugin,
pluginLabel: $pluginLabel,
pluginName: $pluginName,
pluginDescription: $pluginDescription,
referencedControllerActions: $referencedControllerActions,
creatorInformation: $creatorInformation,
typoScriptCreation: $typoScriptCreation,
set: $set,
templatePath: $templatePath,
templates: $templates,
);
}

public function getExtensionInformation(): ExtensionInformation
{
return $this->extensionInformation;
Expand Down Expand Up @@ -139,4 +175,9 @@ public function getTemplatePath(): string
{
return $this->templatePath;
}

public function getTemplates(): array
{
return $this->templates;
}
}
50 changes: 25 additions & 25 deletions Classes/Information/ServicesConfigInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@ public function __construct(
private CreatorInformation $creatorInformation = new CreatorInformation()
) {}

/**
* Convenience factory for tests
* Accepts either enum or string for "type" (e.g. 'yaml', 'php').
* Unknown keys are ignored.
*/
public static function fromArray(
array $info,
ExtensionInformation $extensionInformation,
): self {
$type = $info['type'] ?? ServicesType::YAML;
$autowire = array_key_exists('autowire', $info) ? (bool)$info['autowire'] : true;
$autoconfigure = array_key_exists('autoconfigure', $info) ? (bool)$info['autoconfigure'] : true;
$public = array_key_exists('public', $info) && (bool)$info['public'];
$excludeModels = array_key_exists('excludeModels', $info) ? (bool)$info['excludeModels'] : true;

return new self(
extensionInformation: $extensionInformation,
type: $type,
autowire: $autowire,
autoconfigure: $autoconfigure,
public: $public,
excludeModels: $excludeModels,
);
}

public function getType(): ServicesType
{
return $this->type;
Expand Down Expand Up @@ -103,29 +128,4 @@ public function toServicesArray(): array
],
];
}

/**
* Convenience factory for tests
* Accepts either enum or string for "type" (e.g. 'yaml', 'php').
* Unknown keys are ignored.
*/
public static function fromArray(
array $info,
ExtensionInformation $extensionInformation,
): self {
$type = $info['type'] ?? ServicesType::YAML;
$autowire = array_key_exists('autowire', $info) ? (bool)$info['autowire'] : true;
$autoconfigure = array_key_exists('autoconfigure', $info) ? (bool)$info['autoconfigure'] : true;
$public = array_key_exists('public', $info) && (bool)$info['public'];
$excludeModels = array_key_exists('excludeModels', $info) ? (bool)$info['excludeModels'] : true;

return new self(
extensionInformation: $extensionInformation,
type: $type,
autowire: $autowire,
autoconfigure: $autoconfigure,
public: $public,
excludeModels: $excludeModels,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugin.tx_myextension_newslist {
view {
templateRootPath = EXT:my_extension/Resources/Private/Templates/
partialRootPath = EXT:my_extension/Resources/Private/Partials/
layoutRootPath = EXT:my_extension/Resources/Private/Layouts/
}
persistence {
storagePid = 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugin.tx_myextension_newslist {
view {
templateRootPaths.0 = EXT:my_extension/Resources/Private/Templates/
templateRootPaths.10 = {$plugin.tx_myextension_newslist.view.templateRootPath}
partialRootPaths.0 = EXT:my_extension/Resources/Private/Partials/
partialRootPaths.10 = {$plugin.tx_myextension_newslist.view.partialRootPath}
layoutRootPaths.0 = EXT:my_extension/Resources/Private/Layouts/
layoutRootPaths.10 = {$plugin.tx_myextension_newslist.view.layoutRootPath}
}
persistence {
storagePid = {$plugin.plugin.tx_myextension_newslist.persistence.storagePid}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;
ExtensionUtility::registerPlugin(
'MyExtension',
'NewsList',
'News Listing',
'ext-my-extension-plugin',
'plugins',
'Displays a list of news records with filtering options.',
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<div class="tx_myextension_newslist">
<f:flashMessages />

<f:render section="content" />
</div>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default"/>

<f:section name="content">
<p>TODO: Modify file <code>EXT:my_extension/Resources/Private/Templates/Test/List.fluid.html</code></p>
</f:section>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default"/>

<f:section name="content">
<p>TODO: Modify file <code>EXT:my_extension/Resources/Private/Templates/Test/Show.fluid.html</code></p>
</f:section>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);
use MyVendor\MyExtension\Controller\TestController;
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;
ExtensionUtility::configurePlugin(
'MyExtension',
'NewsList',
[
TestController::class => 'list, show',
],
[
TestController::class => 'list',
],
);
Loading