Commit a5fff2c8 authored by Benni Mack's avatar Benni Mack Committed by Christian Kuhn
Browse files

[TASK] Deprecate extbase's AbstractView

TemplateView does not use AbstractView, and
others do not need this as well, ViewInterface
is the one people should rely on.

Resolves: #94991
Releases: master
Change-Id: Ie09d6dcb3644b4e383bf67e7043765227b622948
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70726

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent a92d9430
.. include:: ../../Includes.txt
==========================================
Deprecation: #94991 - Extbase AbstractView
==========================================
See :issue:`94991`
Description
===========
To simplify and streamline fluid view related class inheritance,
the exbase class :php:`TYPO3\CMS\Extbase\Mvc\View\AbstractView`
has been marked as deprecated and will be removed in v12.
Impact
======
Extending the class should be avoided. Consuming classes should
directly implement :php:`TYPO3\CMS\Extbase\Mvc\View\ViewInterface`
instead.
Affected Installations
======================
Instances with own extbase view classes that extend :php:`AbstractView`
are affected, but this is rather uncommon. The extension scanner will
find class usages as a strong match.
Migration
=========
Affected extbase view classes should implement :php:`ViewInterface` instead
and not extend :php:`AbstractView` anymore. The most simple solution is to
copy the interface implementation from the deprecated :php:`AbstractView` class.
.. index:: Fluid, PHP-API, FullyScanned, ext:extbase
......@@ -19,6 +19,7 @@ use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
/**
* An abstract View
* @deprecated since TYPO3 v11, will be removed in TYPO3 v12.0. It is highly recommended to implement all needed logic of ViewInterface yourself
*/
abstract class AbstractView implements ViewInterface
{
......
......@@ -17,13 +17,14 @@ declare(strict_types=1);
namespace TYPO3\CMS\Extbase\Mvc\View;
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
/**
* A JSON view
*/
class JsonView extends AbstractView
class JsonView implements ViewInterface
{
/**
* Definition for the class name exposure configuration,
......@@ -158,6 +159,19 @@ class JsonView extends AbstractView
*/
protected $persistenceManager;
/**
* @var ControllerContext
*/
protected $controllerContext;
/**
* View variables and their values
*
* @var array
* @see assign()
*/
protected $variables = [];
/**
* @param PersistenceManagerInterface $persistenceManager
* @internal
......@@ -167,6 +181,67 @@ class JsonView extends AbstractView
$this->persistenceManager = $persistenceManager;
}
/**
* Sets the current controller context
*
* @param ControllerContext $controllerContext
*/
public function setControllerContext(ControllerContext $controllerContext)
{
$this->controllerContext = $controllerContext;
}
/**
* Add a variable to $this->viewData.
* Can be chained, so $this->view->assign(..., ...)->assign(..., ...); is possible
*
* @param string $key Key of variable
* @param mixed $value Value of object
* @return self an instance of $this, to enable chaining
*/
public function assign($key, $value)
{
$this->variables[$key] = $value;
return $this;
}
/**
* Add multiple variables to $this->viewData.
*
* @param array $values array in the format array(key1 => value1, key2 => value2).
* @return self an instance of $this, to enable chaining
*/
public function assignMultiple(array $values)
{
foreach ($values as $key => $value) {
$this->assign($key, $value);
}
return $this;
}
/**
* Tells if the view implementation can render the view for the given context.
*
* By default we assume that the view implementation can handle all kinds of
* contexts. Override this method if that is not the case.
*
* @param ControllerContext $controllerContext
* @return bool TRUE if the view has something useful to display, otherwise FALSE
*/
public function canRender(ControllerContext $controllerContext)
{
return true;
}
/**
* Initializes this view.
*
* Override this method for initializing your concrete view implementation.
*/
public function initializeView()
{
}
/**
* Specifies which variables this JsonView should render
* By default only the variable 'value' will be rendered
......
......@@ -16,6 +16,7 @@
namespace TYPO3\CMS\Extbase\Mvc\View;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
use TYPO3\CMS\Extbase\Mvc\Exception;
use TYPO3\CMS\Extbase\Mvc\Request;
......@@ -23,13 +24,26 @@ use TYPO3\CMS\Extbase\Mvc\Request;
* The not found view - a special case.
* @internal only to be used within Extbase, not part of TYPO3 Core API.
*/
class NotFoundView extends AbstractView
class NotFoundView implements ViewInterface
{
/**
* @var array
*/
protected $variablesMarker = ['errorMessage' => 'ERROR_MESSAGE'];
/**
* @var ControllerContext
*/
protected $controllerContext;
/**
* View variables and their values
*
* @var array
* @see assign()
*/
protected $variables = [];
/**
* Renders the not found view
*
......@@ -77,4 +91,65 @@ class NotFoundView extends AbstractView
public function __call($methodName, array $arguments)
{
}
/**
* Sets the current controller context
*
* @param ControllerContext $controllerContext
*/
public function setControllerContext(ControllerContext $controllerContext)
{
$this->controllerContext = $controllerContext;
}
/**
* Add a variable to $this->viewData.
* Can be chained, so $this->view->assign(..., ...)->assign(..., ...); is possible
*
* @param string $key Key of variable
* @param mixed $value Value of object
* @return NotFoundView an instance of $this, to enable chaining
*/
public function assign($key, $value)
{
$this->variables[$key] = $value;
return $this;
}
/**
* Add multiple variables to $this->viewData.
*
* @param array $values array in the format array(key1 => value1, key2 => value2).
* @return NotFoundView an instance of $this, to enable chaining
*/
public function assignMultiple(array $values)
{
foreach ($values as $key => $value) {
$this->assign($key, $value);
}
return $this;
}
/**
* Tells if the view implementation can render the view for the given context.
*
* By default we assume that the view implementation can handle all kinds of
* contexts. Override this method if that is not the case.
*
* @param ControllerContext $controllerContext
* @return bool TRUE if the view has something useful to display, otherwise FALSE
*/
public function canRender(ControllerContext $controllerContext)
{
return true;
}
/**
* Initializes this view.
*
* Override this method for initializing your concrete view implementation.
*/
public function initializeView()
{
}
}
......@@ -25,7 +25,7 @@ interface ViewInterface
/**
* Sets the current controller context
*
* @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext
* @param ControllerContext $controllerContext
* @internal
*/
public function setControllerContext(ControllerContext $controllerContext);
......@@ -36,7 +36,7 @@ interface ViewInterface
*
* @param string $key Key of variable
* @param mixed $value Value of object
* @return \TYPO3\CMS\Extbase\Mvc\View\ViewInterface an instance of $this, to enable chaining
* @return self an instance of $this, to enable chaining
*/
public function assign($key, $value);
......@@ -44,14 +44,14 @@ interface ViewInterface
* Add multiple variables to the view data collection
*
* @param array $values array in the format array(key1 => value1, key2 => value2)
* @return \TYPO3\CMS\Extbase\Mvc\View\ViewInterface an instance of $this, to enable chaining
* @return self an instance of $this, to enable chaining
*/
public function assignMultiple(array $values);
/**
* Tells if the view implementation can render the view for the given context.
*
* @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext
* @param ControllerContext $controllerContext
* @return bool TRUE if the view has something useful to display, otherwise FALSE
*/
public function canRender(ControllerContext $controllerContext);
......
......@@ -1774,4 +1774,9 @@ return [
'Deprecation-94953-EditPanelRelatedFrontendFunctionality.rst',
],
],
'TYPO3\CMS\Extbase\Mvc\View\AbstractView' => [
'restFiles' => [
'Deprecation-94991-ExtbaseAbstractView.rst',
],
],
];
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment