Deprecation: #94956 - Public $cObj
See forge#94956
Description
Frontend plugins receive an instance of
\TYPO3\
when
called via
Content
. This is
typically the case for plugins called as
USER
or indirectly
as
USER_
type.
The instance of
Content
has previously been set by
declaring a public (!) property
c
in the consuming class.
Handing a
Content
instance around this way is hard to
follow and has thus been deprecated: Declaring
public $c
should
be avoided. Frontend plugins that need the current
Content
should have a public
set
method instead.
Impact
Declaring
public $c
in a class called by
Content
triggers a PHP
E_
error.
Affected Installations
Frontend extension classes that neither extend
\TYPO3\
("pibase") nor Extbase
\TYPO3\
and have a public property
c
are affected.
Migration
When instantiating the frontend plugin,
Content
now checks for a public method
set
to explicitly set
an instance of the
Content
.
Many plugins may not need this instance at all. If the ContentObjectRenderer instance
used within the plugin does not rely on further ContentObjectRenderer state, for instance
if it only calls
std
or similar without using state like
LOAD_
,
the
c
class property should be avoided and an own instance of ContentObjectRenderer
should be created.
Classes that do rely on current ContentObjectRenderer state should adapt their code.
Before:
class Foo
{
public $cObj;
}
After:
class Foo
{
protected $cObj;
public function setContentObjectRenderer(ContentObjectRenderer $cObj): void
{
$this->cObj = $cObj;
}
}