-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '11.5-42114-filelist-button' into '11.5'
42114 - add button to generate image in filelist See merge request typo3-commons/mkcontentai!10
- Loading branch information
Showing
4 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright notice | ||
* | ||
* (c) DMK E-BUSINESS GmbH <dev@dmk-ebusiness.de> | ||
* All rights reserved | ||
* | ||
* This file is part of TYPO3 CMS-based extension "mkcontentai" by DMK E-BUSINESS GmbH. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
*/ | ||
|
||
namespace DMK\MkContentAi\Backend\Hooks; | ||
|
||
use TYPO3\CMS\Backend\Routing\UriBuilder; | ||
use TYPO3\CMS\Backend\Template\Components\ButtonBar; | ||
use TYPO3\CMS\Core\Http\ServerRequestFactory; | ||
use TYPO3\CMS\Core\Imaging\Icon; | ||
use TYPO3\CMS\Core\Imaging\IconFactory; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
class ButtonBarHook | ||
{ | ||
/** | ||
* Retrieves and returns buttons for the button bar. | ||
* | ||
* @param array<string, mixed> $params an array of parameters | ||
* @param ButtonBar $buttonBar the ButtonBar instance | ||
* | ||
* @return mixed Returns the buttons | ||
*/ | ||
public function getButtons(array $params, ButtonBar $buttonBar) | ||
{ | ||
$buttons = $params['buttons']; | ||
$url = $this->buildUriToControllerAction(); | ||
$request = ServerRequestFactory::fromGlobals(); | ||
$currentUri = $request->getUri()->getPath(); | ||
$route = $request->getQueryParams()['route'] ?? null; | ||
if ('/typo3/module/file/FilelistList' === $currentUri || '/module/file/FilelistList' === $route) { | ||
$iconFactory = GeneralUtility::makeInstance(IconFactory::class); | ||
$button = $buttonBar->makeLinkButton(); | ||
$button->setShowLabelText(true); | ||
$button->setIcon($iconFactory->getIcon('actions-image', Icon::SIZE_SMALL)); | ||
$button->setTitle('AI generation of image by text prompt'); | ||
$button->setHref($url); | ||
$buttons[ButtonBar::BUTTON_POSITION_LEFT][1][] = $button; | ||
|
||
return $buttons; | ||
} | ||
} | ||
|
||
public function buildUriToControllerAction(): string | ||
{ | ||
/** | ||
* @var UriBuilder $uriBuilder | ||
*/ | ||
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); | ||
$promptUrl = $uriBuilder->buildUriFromRoutePath( | ||
'/module/system/MkcontentaiContentai', | ||
[ | ||
'tx_mkcontentai_system_mkcontentaicontentai' => [ | ||
'action' => 'prompt', | ||
'controller' => 'AiImage', | ||
'target' => '1:/', | ||
], | ||
] | ||
); | ||
|
||
$url = $promptUrl->__toString(); | ||
|
||
return $url; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters