Skip to content

Commit

Permalink
[TASK] Use ServerRequestInterface in EditDocumentController
Browse files Browse the repository at this point in the history
A controller reads information from the request object and creates
and returns a response object.

Backend controllers in TYPO3 however have a history of being messy:
They read information from GET/POST using these super globals
directly, or by calling helper methods like _GP(), getIndpEnv()
and others.
Some controllers don't even return a response object to be further
processable by PSR-15 middlewares, but call stuff like
HttpUtility::redirect() to write a response and die.
Furthermore, especially the old and most important backend
controllers have tons of public properties and methods. This makes
refactoring towards good controller code hard. But controllers
shouldn't expose much public API: They usually should not be called from
outside, except their main entry methods that take the request object
in order to turn it into a response object. Everything else should be
protected and used internally only.

The patch takes EditDocumentController as one of the most complex
and important backend controllers and refactors it:

* (Nearly) all methods and properties are protected.
* All request dependant data is read from $request->getParsedBody(),
  $request->getQueryParams() or $request->getAttribute('serverParams').

This patch is very careful and tries to be fully backwards compatible in
v9. In case some extension still uses properties or methods of this
controller, a series of different strategies have been used to retain
compatibility:

* Properties made protected use PublicPropertyDeprecationTrait
  to trigger_error() if accessed.
* Nearly all properties are kept, keep their state and type to not
  break a possible 3rd party usage.
* Nearly everything made protected or deprecated is configured to be
  scanned by extension scanner, except a couple of properties that
  would create too many false positives. Those are marked as not scanned
  in the deprecation ReST file.
* Various methods need $request now. They are always called with that
  argument, but fall back to $GLOBALS['TYPO3_REQUEST'] and
  trigger_error() if not given.
* Some methods are kept with their old signature as public and are
  set to deprecated, but trigger_error() to then call a new protected
  method with a better name and a more strict sigature.
* Some methods are kept public in v9, but test if they were called from
  outside to then trigger_error() telling they will be set to protected
  in v10.
* A couple of properties still must be public since other core
  functionality reads from them directly. Those are marked with
  an @todo and @internal to have freedom in v10 for further cleanup.
* Some (non core) hooks or signals may now trigger deprecation log
  entries if they try to set properties or call methods. Those need
  detailed handling later and may hand over specific properties instead
  of full "pObj". This will be a topic later if the main signal/hook
  handling gets more love. As a general alternative, some hooks or signal
  usages could also be turned into a PSR-15 middleware instead. In case
  of EditDocumentController, the write access of the two existing signal
  may eventually be removed altogether later, since an existing slot
  could probably better achieve the same job by being converted into a
  middleware that manipulates $request if it needs to write.

Changing controllers this way gives the core much more freedom
to refactor and significantly improve controller code in v10, after
now deprecated code from patches like these have been removed.

Change-Id: I3527c43c52f6e738f34ac0a21efc1ac904a3f6d2
Resolves: #84195
Releases: master
Reviewed-on: https://review.typo3.org/56018
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
  • Loading branch information
lolli42 authored and NeoBlack committed Mar 14, 2018
1 parent a69bf84 commit 6afc180
Show file tree
Hide file tree
Showing 7 changed files with 1,133 additions and 427 deletions.
1,119 changes: 703 additions & 416 deletions typo3/sysext/backend/Classes/Controller/EditDocumentController.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
.. include:: ../../Includes.txt

================================================================================
Deprecation: #84195 - Protected methods and properties in EditDocumentController
================================================================================

See :issue:`84195`

Description
===========

This file is about third party usage (consumer that call the class as well as
signals or hooks depending on it) of :php:`TYPO3\CMS\Backend\Controller\EditDocumentController`.

A series of class properties has been set to protected.
They will throw deprecation warnings if called public from outside:

* :php:`$editconf`
* :php:`$defVals`
* :php:`$overrideVals`
* :php:`$columnsOnly`
* :php:`$returnUrl`
* :php:`$closeDoc`
* :php:`$doSave`
* :php:`$returnEditConf`
* [not scanned] :php:`$uc`
* :php:`$retUrl`
* :php:`$R_URL_parts`
* :php:`$R_URL_getvars`
* :php:`$storeArray`
* :php:`$storeUrl`
* :php:`$storeUrlMd5`
* :php:`$docDat`
* :php:`$docHandler`
* [not scanned] :php:`$cmd`
* [not scanned] :php:`$mirror`
* :php:`$cacheCmd`
* :php:`$redirect`
* :php:`$returnNewPageId`
* :php:`$popViewId`
* :php:`$popViewId_addParams`
* :php:`$viewUrl`
* :php:`$recTitle`
* :php:`$noView`
* :php:`$MCONF`
* [not scanned] :php:`$doc`
* :php:`$perms_clause`
* [not scanned] :php:`$template`
* :php:`$content`
* :php:`$R_URI`
* :php:`$pageinfo`
* :php:`$storeTitle`
* :php:`$firstEl`
* :php:`$errorC`
* :php:`$newC`
* :php:`$viewId`
* :php:`$viewId_addParams`
* :php:`$modTSconfig`
* :php:`$dontStoreDocumentRef`

Some properties are set to :php:`@internal` and may vanish or be set to protected in v10 without further notice:

* [not scanned] :php:`$data`
* :php:`$elementsData`

All methods not used as entry points by :php:`TYPO3\CMS\Backend\Http\RouteDispatcher` will be
removed or set to protected in v10 and throw deprecation warnings if used from a third party:

* :php:`preInit()`
* :php:`doProcessData()`
* :php:`processData()`
* [not scanned] :php:`init()`
* [note scanned] :php:`main()`
* :php:`makeEditForm()`
* :php:`compileForm()`
* :php:`shortCutLink()`
* :php:`openInNewWindowLink()`
* :php:`languageSwitch()`
* :php:`localizationRedirect()`
* :php:`getLanguages()`
* :php:`fixWSversioningInEditConf()`
* :php:`getRecordForEdit()`
* :php:`compileStoreDat()`
* :php:`getNewIconMode()`
* :php:`closeDocument()`
* :php:`setDocument()`

Two slots retrieve a parent object that will throw deprecations if properties are read or
methods called. They receive a :php:`ServerRequestInterface $request` argument as second
argument instead:

* :php:`TYPO3\CMS\Backend\Controller\EditDocumentController::preInitAfter`
* :php:`TYPO3\CMS\Backend\Controller\EditDocumentController::preInit`


Impact
======

Calling one of the above methods or accessing one of the above properties on an instance of
:php:`EditDocumentController` will throw a deprecation warning in v9 and a PHP fatal in v10.


Affected Installations
======================

The extension scanner will find most usages, but may also find some false positives. The most
common property and method names like :php:`$data` are not registered and will not be found
if an extension uses that on an instance of :php:`EditDocumenController`. In general all extensions
that set properties or call methods except :php:`mainAction()` are affected.

Installations may alse be affected, if the two signals
:php:`TYPO3\CMS\Backend\Controller\EditDocumentController::preInitAfter` and
:php:`TYPO3\CMS\Backend\Controller\EditDocumentController::InitAfter`
are used and the slot write to or reads from first argument "parent object".


Migration
=========

In general, extensions should not instantiate and re-use controllers of the core. Existing
usages should be rewritten to be free of calls like these.
Registered slots for the two signals :php:`preInitAfter` and :php:`initAfter` should read
(not write!) from new second argument :php:`$request` instead.
Slots that currently write to "parent object" should instead be turned into a PSR-15 middleware
to manipulate :php:`$request` before :php:`EditDocumentController` is called.


.. index:: Backend, PHP-API, PartiallyScanned
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,6 @@ EXT:core/Resources/Public/Images/cshimages/core_31.png,</source>
<source>This is how a typical record is edited in TYPO3. The form display is standardized for all types of records. You will always see the same buttons in the top for saving or closing. In the blue bar you will see the type of record (table name) and the ID number that each record has (uid). Here the record is a page with ID "2" and the title "Content Elements".
The "additional fields" from the example above is located in a so called "palette". This is an example of three content elements being edited at the same time. You can edit multiple records by using the links from the Web&gt;List module in single-table mode. Notice that not only are three records shown at the same time - it is also a limited number of fields shown for editing, here "Header" and "Hide". You can combine this almost any way you like. This is of course very useful if you need to edit only the header of multiple records.</source>
</trans-unit>
<trans-unit id="TCEforms_docSelector.alttitle">
<source>Document Selector</source>
</trans-unit>
<trans-unit id="TCEforms_docSelector.description">
<source>Here you can switch between "open documents" in TYPO3.</source>
</trans-unit>
<trans-unit id="_TCEforms_docSelector.image">
<source>EXT:core/Resources/Public/Images/cshimages/core_35.png,</source>
<note from="developer">This string contains an internal text, which must not be changed. Just copy the original text into the translation field. For more information have a look at the Tutorial.</note>
</trans-unit>
<trans-unit id="TCEforms_cacheSelector.alttitle">
<source>Forms Menu</source>
</trans-unit>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -1794,4 +1794,116 @@
'Deprecation-84109-DeprecateDependencyResolver.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->preInit' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 1,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->doProcessData' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->processData' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 1,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->makeEditForm' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->compileForm' => [
'numberOfMandatoryArguments' => 1,
'maximumNumberOfArguments' => 1,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->shortCutLink' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->openInNewWindowLink' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->languageSwitch' => [
'numberOfMandatoryArguments' => 2,
'maximumNumberOfArguments' => 3,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->localizationRedirect' => [
'numberOfMandatoryArguments' => 1,
'maximumNumberOfArguments' => 1,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->getLanguages' => [
'numberOfMandatoryArguments' => 1,
'maximumNumberOfArguments' => 1,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->fixWSversioningInEditConf' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 1,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->getRecordForEdit' => [
'numberOfMandatoryArguments' => 2,
'maximumNumberOfArguments' => 2,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->compileStoreDat' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->getNewIconMode' => [
'numberOfMandatoryArguments' => 1,
'maximumNumberOfArguments' => 2,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->closeDocument' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 1,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\EditDocumentController->setDocument' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 2,
'restFiles' => [
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
];

0 comments on commit 6afc180

Please sign in to comment.