You are here

public function BackgroundImage::getSettings in Background Image 8

Same name and namespace in other branches
  1. 2.x src/Entity/BackgroundImage.php \Drupal\background_image\Entity\BackgroundImage::getSettings()
  2. 2.0.x src/Entity/BackgroundImage.php \Drupal\background_image\Entity\BackgroundImage::getSettings()

Retrieves the settings for this background image.

Return value

\Drupal\background_image\BackgroundImageSettings A custom fake immutable config object containing the current settings.

Overrides BackgroundImageInterface::getSettings

File

src/Entity/BackgroundImage.php, line 421

Class

BackgroundImage
Defines the Background Image entity.

Namespace

Drupal\background_image\Entity

Code

public function getSettings() {

  // In some cases (likely due to database serialization), the settings
  // property isn't a properly constructed BackgroundImageSettings object.
  // Instead of checking if the property is set, validate with instanceof.
  // @see https://www.drupal.org/project/background_image/issues/3103708
  // @see https://www.drupal.org/project/background_image/issues/2993568
  if (!$this->settings instanceof BackgroundImageSettings) {
    $settings = $this
      ->get('settings')
      ->first();
    $parent = $this
      ->getParent();
    $this->settings = new BackgroundImageSettings();
    $this->settings
      ->initWithData($parent ? $parent
      ->getSettings()
      ->get() : $this
      ->getBackgroundImageManager()
      ->getDefaultSettings());
    $this->settings
      ->merge($settings ? $settings
      ->getValue() : []);
  }
  return $this->settings;
}