Skip to content

Commit

Permalink
Merge branch '11.5-42114-filelist-button' into '11.5'
Browse files Browse the repository at this point in the history
42114 - add button to generate image in filelist

See merge request typo3-commons/mkcontentai!10
  • Loading branch information
hannesbochmann committed Nov 9, 2023
2 parents a113bd7 + 0bc25a7 commit 4b0e19b
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ variables:
PHPUNIT_CONFIG_FILE: ./phpunit.xml
PHPUNIT_DIRECTORY: Tests
PHPUNIT_OPTIONS: -c $PHPUNIT_CONFIG_FILE --coverage-text --colors=never --log-junit=$JUNIT_LOG --coverage-clover=$COVERAGE_LOG --whitelist=$PHP_ANALYSE_PATHS $PHPUNIT_DIRECTORY
ANALYSE_COVERAGE_MIN: '2'
ANALYSE_COVERAGE_MIN: '1'
ANALYSE_COVERAGE_LAST_THRESHOLD: '5.0'
PHPCOMPATIBILITY_PHP_VERSIONS: '7.4,8.0,8.1,8.2'
76 changes: 76 additions & 0 deletions Classes/Backend/Hooks/ButtonBarHook.php
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;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"(test \"$(php -v | grep \"Xdebug v3\" | wc -l)\" = 0 && .Build/bin/phpcpd ./Classes) | true"
],
"test:phpunit": [
".Build/bin/phpunit -c phpunit.xml --whitelist=./Classes Tests"
"TYPO3_PATH_APP=$PWD/.Build TYPO3_PATH_WEB=$PWD/.Build/Web .Build/bin/phpunit -c phpunit.xml --whitelist=./Classes Tests"
],
"test:phpunit-coverage": [
"XDEBUG_MODE=coverage .Build/bin/phpunit --coverage-text --log-junit=.Build/junit.xml --coverage-clover=.Build/coverage.xml -c phpunit.xml --whitelist=./Classes Tests"
Expand Down
5 changes: 5 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@

defined('TYPO3') or exit;

use DMK\MkContentAi\Backend\Hooks\ButtonBarHook;

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Backend\Template\Components\ButtonBar']['getButtonsHook']['ButtonBarHook']
= ButtonBarHook::class.'->getButtons';

$GLOBALS['TYPO3_CONF_VARS']['BE']['ContextMenu']['ItemProviders'][1697195476] =
\DMK\MkContentAi\ContextMenu\ContentAiItemProvider::class;

0 comments on commit 4b0e19b

Please sign in to comment.