Skip to content

Commit

Permalink
Merge pull request #1 from b13/v12
Browse files Browse the repository at this point in the history
[TASK] Add TYPO3 12 support
  • Loading branch information
brosua authored Nov 13, 2023
2 parents 54ba886 + d09b99d commit ff2efc1
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 41 deletions.
67 changes: 31 additions & 36 deletions Classes/Xclass/FormManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,44 @@
namespace Brosua\FormSearch\Xclass;

use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
use TYPO3\CMS\Core\Pagination\ArrayPaginator;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class FormManagerController extends \TYPO3\CMS\Form\Controller\FormManagerController
{
public function indexAction(int $page = 1, string $searchTerm = ''): ResponseInterface
public function indexAction(int $page = 1): ResponseInterface
{
$forms = $searchTerm ? $this->getAvailableFormDefinitionsBySearchTerm($searchTerm) : $this->getAvailableFormDefinitions();
$arrayPaginator = new ArrayPaginator($forms, $page, $this->limit);
$pagination = new SimplePagination($arrayPaginator);
if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) {
$searchTerm = $this->request->getQueryParams()['tx_form_web_formformbuilder']['searchTerm'] ?? null;
$this->view->assign('searchTerm', $searchTerm);
}
return parent::indexAction($page);
}

$this->view->assignMultiple(
[
'paginator' => $arrayPaginator,
'pagination' => $pagination,
'searchTerm' => $searchTerm,
'stylesheets' => $this->resolveResourcePaths($this->formSettings['formManager']['stylesheets']),
'dynamicRequireJsModules' => $this->formSettings['formManager']['dynamicRequireJsModules'],
'formManagerAppInitialData' => json_encode($this->getFormManagerAppInitialData()),
]
);
if (!empty($this->formSettings['formManager']['javaScriptTranslationFile'])) {
$this->pageRenderer->addInlineLanguageLabelFile($this->formSettings['formManager']['javaScriptTranslationFile']);
protected function initializeModuleTemplate(ServerRequestInterface $request): ModuleTemplate
{
$moduleTemplate = parent::initializeModuleTemplate($request);
if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() > 11) {
$searchTerm = $this->request->getQueryParams()['searchTerm'] ?? null;
$moduleTemplate->assign('searchTerm', $searchTerm);
}
return $moduleTemplate;
}

$requireJsModules = array_filter(
$this->formSettings['formManager']['dynamicRequireJsModules'],
fn (string $name) => in_array($name, self::JS_MODULE_NAMES, true),
ARRAY_FILTER_USE_KEY
);
$this->pageRenderer->getJavaScriptRenderer()->addJavaScriptModuleInstruction(
JavaScriptModuleInstruction::forRequireJS('TYPO3/CMS/Form/Backend/Helper', 'Helper')
->invoke('dispatchFormManager', $requireJsModules, $this->getFormManagerAppInitialData())
);
$moduleTemplate = $this->initializeModuleTemplate($this->request);
$moduleTemplate->setModuleClass($this->request->getPluginName() . '_' . $this->request->getControllerName());
$moduleTemplate->setFlashMessageQueue($this->getFlashMessageQueue());
$moduleTemplate->setTitle(
$this->getLanguageService()->sL('LLL:EXT:form/Resources/Private/Language/locallang_module.xlf:mlang_tabs_tab')
);
$moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($moduleTemplate->renderContent());
protected function getAvailableFormDefinitions(): array
{
if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) {
if (isset($this->request->getQueryParams()['tx_form_web_formformbuilder']['searchTerm'])) {
return $this->getAvailableFormDefinitionsBySearchTerm($this->request->getQueryParams()['tx_form_web_formformbuilder']['searchTerm']);
}
} else {
if (isset($this->request->getQueryParams()['searchTerm'])) {
return $this->getAvailableFormDefinitionsBySearchTerm($this->request->getQueryParams()['searchTerm']);
}
}
return parent::getAvailableFormDefinitions();
}

protected function getAvailableFormDefinitionsBySearchTerm(string $searchTerm): array
Expand Down
1 change: 1 addition & 0 deletions Configuration/page.tsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
templates.typo3/cms-form.1698393052 = brosua/form-search:Resources/Private/TemplateOverrides
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<html
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:core="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:layout name="Module" />

<f:section name="Content">

<f:be.pageRenderer
includeCssFiles="{stylesheets}"
/>

<h1><f:translate key="LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.headline" /></h1>
<f:if condition="{paginator.paginatedItems}">
<f:then>
<form style="display:inline;"
data-global-event="submit"
data-action-navigate="$form=~s/$value/"
data-navigate-value="{f:uri.action(arguments:'{searchTerm: \'$[value]\'}')}"
data-value-selector="input[name='searchTerm']">
<div class="row mb-3">
<div class="col-6">
<div class="input-group">
<button class="btn btn-default" type="submit" name="search">
<core:icon identifier="actions-search" size="small" />
</button>
<label for="search_field" class="visually-hidden">
<f:translate id="LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.label.searchString"/>
</label>
<input type="search" id="search_field" name="searchTerm" class="form-control" value="{searchTerm}" placeholder="{f:translate(key: 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.enterSearchString')}" />
</div>
</div>
</div>
</form>
<div class="table-fit">
<table id="forms" class="table table-striped table-hover">
<thead>
<tr>
<th></th>
<th><f:translate key="LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.form_name" /></th>
<th><f:translate key="LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.location" /></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<f:for each="{paginator.paginatedItems}" as="form">
<tr>
<td class="col-icon">
<f:if condition="{form.invalid}">
<f:then>
<span title="{f:translate(key: 'LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.invalid')}">
<core:icon identifier="overlay-missing" />
</span>
</f:then>
<f:else if="{form.duplicateIdentifier}">
<span title="{f:translate(key: 'LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.duplicate_identifier')} {form.identifier}">
<core:icon identifier="overlay-missing" />
</span>
</f:else>
<f:else>
<span title="id={form.identifier}">
<core:icon identifier="content-form" />
</span>
</f:else>
</f:if>
</td>
<td class="col-title">
<f:if condition="{form.invalid} || {form.readOnly}">
<f:then>
<div title="{form.name}">{form.name}</div>
</f:then>
<f:else>
<f:link.action controller="FormEditor" action="index" arguments="{formPersistenceIdentifier: form.persistenceIdentifier}" title="{f:translate(key: 'LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.edit_form')}">{form.name}</f:link.action>
</f:else>
</f:if>
</td>
<td><code>{form.persistenceIdentifier}</code></td>
<td>
<f:if condition="{form.referenceCount}">
<f:then>
<a href="#" data-identifier="showReferences" data-form-persistence-identifier="{form.persistenceIdentifier}" data-form-name="{form.name}">
<span class="badge badge-info">
{form.referenceCount} <f:translate key="LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.references"/>
</span>
</a>
</f:then>
<f:else>
<span class="badge badge-default">
{form.referenceCount} <f:translate key="LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.references"/>
</span>
</f:else>
</f:if>
</td>
<td class="col-control">
<div class="btn-group" role="group">
<f:if condition="{form.invalid} || {form.readOnly}">
<f:then>
<button class="btn btn-default form-record-readonly" disabled="disabled" title="{f:translate(key: 'LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.edit_form_not_allowed')}"><core:icon identifier="actions-open" /></button>
</f:then>
<f:else>
<f:link.action controller="FormEditor" action="index" arguments="{formPersistenceIdentifier: form.persistenceIdentifier}" title="{f:translate(key: 'LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.edit_form')}" class="btn btn-default form-record-open"><core:icon identifier="actions-open" /></f:link.action>
</f:else>
</f:if>
<f:if condition="{form.invalid}">
<button class="btn btn-default form-record-readonly" disabled="disabled" title="{f:translate(key: 'LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.duplicate_form_not_allowed')}"><core:icon identifier="actions-duplicate" /></button>
</f:if>
<div class="btn-group dropdown">
<a href="#actions-{form.identifier}" class="btn btn-default dropdown-toggle dropdown-toggle-no-chevron" data-bs-toggle="dropdown" data-bs-boundary="window" aria-expanded="false"><core:icon identifier="actions-menu-alternative" /></a>
<ul id="actions-{form.identifier}" class="dropdown-menu">
<f:if condition="{form.invalid}">
<f:else>
<li>
<a href="#" class="dropdown-item" data-bs-original-title="{f:translate(key: 'LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.duplicate_this_form')}" data-identifier="duplicateForm" data-form-persistence-identifier="{form.persistenceIdentifier}" data-form-name="{form.name}">
<span class="dropdown-item-columns">
<span class="dropdown-item-column dropdown-item-column-icon text-{cacheAction.severity}">
<core:icon identifier="actions-duplicate" />
</span>
<span class="dropdown-item-column dropdown-item-column-text">
<f:translate key="LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.duplicate_this_form" />
</span>
</span>
</a>
</li>
</f:else>
</f:if>
<f:if condition="{form.referenceCount}">
<li>
<a href="#" class="dropdown-item" data-bs-original-title="{f:translate(key: 'LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.show_references')}" data-identifier="showReferences" data-form-persistence-identifier="{form.persistenceIdentifier}" data-form-name="{form.name}">
<core:icon identifier="actions-eye-link" />
<f:translate key="LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.show_references" />
</a>
</li>
</f:if>
<f:if condition="{form.removable} && ({form.invalid} == '0') && ({form.referenceCount} == '0')">
<li>
<a href="#" class="dropdown-item" data-bs-original-title="{f:translate(key: 'LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.delete_form')}" data-identifier="removeForm" data-form-persistence-identifier="{form.persistenceIdentifier}">
<core:icon identifier="actions-edit-delete" />
<f:translate key="LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.delete_form" />
</a>
</li>
</f:if>
</ul>
</div>
</div>
</td>
</tr>
</f:for>
</tbody>
</table>
</div>
<f:render partial="Backend/FormManager/Pagination" arguments="{_all}" />
</f:then>
<f:else>
<f:be.infobox state="-1" title="{f:translate(key: 'LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.forms_not_found.title')}">
<p><f:translate key="LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.forms_not_found.message" /></p>
<a class="btn btn-primary" href="#" data-identifier="newForm"><f:translate key="LLL:EXT:form/Resources/Private/Language/Database.xlf:formManager.create_new_form" /></a>
</f:be.infobox>
</f:else>
</f:if>


</f:section>
</html>
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": ["typo3", "forms"],
"license": "GPL-2.0-or-later",
"require": {
"typo3/cms-form": "^11.5"
"typo3/cms-form": "^11.5 || ^12.4"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 2 additions & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

$EM_CONF[$_EXTKEY] = [
'title' => 'Form search backend',
'description' => 'Add search functionality to the TYPO3 backend form manager',
Expand All @@ -10,7 +11,7 @@
'version' => '1.1.0',
'constraints' => [
'depends' => [
'typo3' => '11.5.0-11.99.99',
'typo3' => '11.5.0-12.99.99',
],
'conflicts' => [
],
Expand Down
8 changes: 5 additions & 3 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
defined('TYPO3') or die();

(function () {
ExtensionManagementUtility::addTypoScriptSetup(
'module.tx_form {
if ((\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Information\Typo3Version::class))->getMajorVersion() < 12) {
ExtensionManagementUtility::addTypoScriptSetup(
'module.tx_form {
view {
partialRootPaths.1649789601 = EXT:form_search/Resources/Private/Backend/Partials/
templateRootPaths.1649789601 = EXT:form_search/Resources/Private/Backend/Templates/
}
}'
);
);
}

$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\Form\Controller\FormManagerController::class] = [
'className' => \Brosua\FormSearch\Xclass\FormManagerController::class,
Expand Down

0 comments on commit ff2efc1

Please sign in to comment.