Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
984a2684
Unverified
Commit
984a2684
authored
Dec 27, 2017
by
larowlan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2931264
by markcarver, claudiu.cristea: Remove static \Drupal::$legacyMessenger property
parent
8946662d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
37 deletions
+22
-37
core/lib/Drupal.php
core/lib/Drupal.php
+1
-20
core/lib/Drupal/Core/Messenger/LegacyMessenger.php
core/lib/Drupal/Core/Messenger/LegacyMessenger.php
+21
-17
No files found.
core/lib/Drupal.php
View file @
984a2684
...
...
@@ -101,22 +101,6 @@ class Drupal {
*/
protected
static
$container
;
/**
* The LegacyMessenger instance.
*
* Note: this is merely used to ensure that the instance survives when
* \Drupal::messenger() is invoked. It is required to ensure that messages
* are properly transferred to the Messenger service once the container has
* been initialized. Do not store the Messenger service here.
*
* @todo Remove once LegacyMessenger has been removed before 9.0.0.
*
* @see https://www.drupal.org/node/2928994
*
* @var \Drupal\Core\Messenger\LegacyMessenger|null
*/
protected
static
$legacyMessenger
;
/**
* Sets a new global container.
*
...
...
@@ -783,10 +767,7 @@ public static function time() {
public
static
function
messenger
()
{
// @todo Replace with service once LegacyMessenger is removed in 9.0.0.
// @see https://www.drupal.org/node/2928994
if
(
!
isset
(
static
::
$legacyMessenger
))
{
static
::
$legacyMessenger
=
new
LegacyMessenger
();
}
return
static
::
$legacyMessenger
;
return
new
LegacyMessenger
();
}
}
core/lib/Drupal/Core/Messenger/LegacyMessenger.php
View file @
984a2684
...
...
@@ -26,9 +26,13 @@ class LegacyMessenger implements MessengerInterface {
/**
* The messages.
*
* Note: this property must remain static because it must behave in a
* persistent manner, similar to $_SESSION['messages']. Creating a new class
* each time would destroy any previously set messages.
*
* @var array
*/
protected
$messages
;
protected
static
$messages
;
/**
* {@inheritdoc}
...
...
@@ -46,8 +50,8 @@ public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE)
return
$messenger
->
addMessage
(
$message
,
$type
,
$repeat
);
}
if
(
!
isset
(
$this
->
messages
[
$type
]))
{
$this
->
messages
[
$type
]
=
[];
if
(
!
isset
(
static
::
$
messages
[
$type
]))
{
static
::
$
messages
[
$type
]
=
[];
}
if
(
!
(
$message
instanceof
Markup
)
&&
$message
instanceof
MarkupInterface
)
{
...
...
@@ -56,8 +60,8 @@ public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE)
// Do not use strict type checking so that equivalent string and
// MarkupInterface objects are detected.
if
(
$repeat
||
!
in_array
(
$message
,
$this
->
messages
[
$type
]))
{
$this
->
messages
[
$type
][]
=
$message
;
if
(
$repeat
||
!
in_array
(
$message
,
static
::
$
messages
[
$type
]))
{
static
::
$
messages
[
$type
][]
=
$message
;
}
return
$this
;
...
...
@@ -86,7 +90,7 @@ public function all() {
return
$messenger
->
all
();
}
return
$this
->
messages
;
return
static
::
$
messages
;
}
/**
...
...
@@ -104,15 +108,15 @@ protected function getMessengerService() {
$messenger
=
\
Drupal
::
service
(
'messenger'
);
// Transfer any messages into the service.
if
(
isset
(
$this
->
messages
))
{
foreach
(
$this
->
messages
as
$type
=>
$messages
)
{
if
(
isset
(
static
::
$
messages
))
{
foreach
(
static
::
$
messages
as
$type
=>
$messages
)
{
foreach
(
$messages
as
$message
)
{
// Force repeat to TRUE since this is merging existing messages to
// the Messenger service and would have already checked this prior.
$messenger
->
addMessage
(
$message
,
$type
,
TRUE
);
}
}
unset
(
$this
->
messages
)
;
static
::
$
messages
=
NULL
;
}
return
$messenger
;
...
...
@@ -128,18 +132,18 @@ protected function getMessengerService() {
// reasonable to assume that if the container becomes available in a
// subsequent request, a new instance of this class will be created and
// this code will never be reached. This is merely for BC purposes.
if
(
!
isset
(
$this
->
messages
))
{
if
(
!
isset
(
static
::
$
messages
))
{
// A "session" was already created, perhaps to simply allow usage of
// the previous method core used to store messages, use it.
if
(
isset
(
$_SESSION
))
{
if
(
!
isset
(
$_SESSION
[
'messages'
]))
{
$_SESSION
[
'messages'
]
=
[];
}
$this
->
messages
=
&
$_SESSION
[
'messages'
];
static
::
$
messages
=
&
$_SESSION
[
'messages'
];
}
// Otherwise, just set an empty array.
else
{
$this
->
messages
=
[];
static
::
$
messages
=
[];
}
}
}
...
...
@@ -153,7 +157,7 @@ public function messagesByType($type) {
return
$messenger
->
messagesByType
(
$type
);
}
return
$this
->
messages
[
$type
];
return
static
::
$
messages
[
$type
];
}
/**
...
...
@@ -165,8 +169,8 @@ public function deleteAll() {
return
$messenger
->
deleteAll
();
}
$messages
=
$this
->
messages
;
unset
(
$this
->
messages
)
;
$messages
=
static
::
$
messages
;
static
::
$
messages
=
NULL
;
return
$messages
;
}
...
...
@@ -179,8 +183,8 @@ public function deleteByType($type) {
return
$messenger
->
messagesByType
(
$type
);
}
$messages
=
$this
->
messages
[
$type
];
unset
(
$this
->
messages
[
$type
]);
$messages
=
static
::
$
messages
[
$type
];
unset
(
static
::
$
messages
[
$type
]);
return
$messages
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment