diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index 3f28a78..2cf18d8 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -120,13 +120,6 @@ protected $renderer; /** - * The 'system' channel logger service. - * - * @var \Psr\Log\LoggerInterface - */ - protected $logger; - - /** * {@inheritdoc} */ public function __construct(array $values, $entity_type) { @@ -139,7 +132,6 @@ public function __construct(array $values, $entity_type) { } $this->renderer = \Drupal::service('renderer'); - $this->logger = \Drupal::logger('system'); // A plugin manager and a context type needs to be set by extending classes. if (!isset($this->pluginManager)) { @@ -466,7 +458,7 @@ public function onDependencyRemoval(array $dependencies) { '@id' => $this->id(), '@name' => $name, ]; - $this->logger->warning("@display '@id': Component '@name' was disabled because its settings depend on removed dependencies.", $arguments); + $this->getLogger()->warning("@display '@id': Component '@name' was disabled because its settings depend on removed dependencies.", $arguments); $changed = TRUE; } } @@ -548,4 +540,14 @@ public function __wakeup() { $this->__construct($values, $this->entityTypeId); } + /** + * Provides the 'system' channel logger service. + * + * @return \Psr\Log\LoggerInterface + * The 'system' channel logger. + */ + protected function getLogger() { + return \Drupal::logger('system'); + } + } diff --git a/core/modules/field_ui/src/Tests/EntityDisplayTest.php b/core/modules/field_ui/src/Tests/EntityDisplayTest.php index efcc68f..0cafbb4 100644 --- a/core/modules/field_ui/src/Tests/EntityDisplayTest.php +++ b/core/modules/field_ui/src/Tests/EntityDisplayTest.php @@ -602,9 +602,12 @@ public function testComponentDependencies() { * The string to be checked. * @param \Drupal\Core\Entity\Display\EntityDisplayInterface $display * The entity display object to get dependencies from. + * + * @return bool + * TRUE if the assertion succeeded, FALSE otherwise. */ protected function assertDependency($type, $key, EntityDisplayInterface $display) { - $this->assertDependencyHelper(TRUE, $type, $key, $display); + return $this->assertDependencyHelper(TRUE, $type, $key, $display); } /** @@ -616,9 +619,12 @@ protected function assertDependency($type, $key, EntityDisplayInterface $display * The string to be checked. * @param \Drupal\Core\Entity\Display\EntityDisplayInterface $display * The entity display object to get dependencies from. + * + * @return bool + * TRUE if the assertion succeeded, FALSE otherwise. */ protected function assertNoDependency($type, $key, EntityDisplayInterface $display) { - $this->assertDependencyHelper(FALSE, $type, $key, $display); + return $this->assertDependencyHelper(FALSE, $type, $key, $display); } /** @@ -632,6 +638,9 @@ protected function assertNoDependency($type, $key, EntityDisplayInterface $displ * The string to be checked. * @param \Drupal\Core\Entity\Display\EntityDisplayInterface $display * The entity display object to get dependencies from. + * + * @return bool + * TRUE if the assertion succeeded, FALSE otherwise. */ protected function assertDependencyHelper($assertion, $type, $key, EntityDisplayInterface $display) { $all_dependencies = $display->getDependencies(); @@ -640,7 +649,7 @@ protected function assertDependencyHelper($assertion, $type, $key, EntityDisplay $value = $assertion ? in_array($key, $dependencies) : !in_array($key, $dependencies); $args = ['@context' => $context, '@id' => $display->id(), '@type' => $type, '@key' => $key]; $message = $assertion ? new FormattableMarkup("@context display '@id' depends on @type '@key'.", $args) : new FormattableMarkup("@context display '@id' do not depend on @type '@key'.", $args); - $this->assert($value, $message); + return $this->assert($value, $message); } }