You are here

class BackgroundImage in Background Image 8

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

Defines the Background Image entity.

Plugin annotation


@ContentEntityType(
  id = "background_image",
  label = @Translation("Background Image"),
  label_collection = @Translation("Background Image"),
  label_singular = @Translation("background image"),
  label_plural = @Translation("background images"),
  label_count = @PluralTranslation(
    singular = "@count background image",
    plural = "@count background images"
  ),
  handlers = {
    "access" = "Drupal\background_image\BackgroundImageAccessControlHandler",
    "list_builder" = "Drupal\background_image\BackgroundImageListBuilder",
    "translation" = "Drupal\content_translation\ContentTranslationHandler",
    "view_builder" = "Drupal\background_image\BackgroundImageViewBuilder",
    "views_data" = "Drupal\views\EntityViewsData",
    "form" = {
      "add" = "Drupal\background_image\Form\BackgroundImageHandlerForm",
      "edit" = "Drupal\background_image\Form\BackgroundImageHandlerForm",
      "delete" = "Drupal\background_image\Form\BackgroundImageDeleteForm",
    },
  },
  admin_permission = "administer background image",
  base_table = "background_image",
  data_table = "background_image_field_data",
  translatable = TRUE,
  entity_keys = {
    "id" = "bid",
    "label" = "label",
    "uuid" = "uuid",
    "langcode" = "langcode",
  },
  links = {
    "canonical" = "/admin/config/media/background_image/{background_image}/edit",
    "edit-form" = "/admin/config/media/background_image/{background_image}/edit",
    "delete-form" = "/admin/config/media/background_image/{background_image}/delete",
    "collection" = "/admin/config/media/background_image"
  },
)

Hierarchy

Expanded class hierarchy of BackgroundImage

1 file declares its use of BackgroundImage
BackgroundImageForm.php in src/Form/BackgroundImageForm.php

File

src/Entity/BackgroundImage.php, line 68

Namespace

Drupal\background_image\Entity
View source
class BackgroundImage extends ContentEntityBase implements BackgroundImageInterface {
  use ContainerAwareTrait;
  use EntityChangedTrait;
  use StringTranslationTrait;

  /**
   * @var \Drupal\background_image\BackgroundImageManagerInterface
   */
  protected $backgroundImageManager;

  /**
   * @var string
   */
  protected $cssSelector;

  /**
   * @var \Drupal\Core\Entity\EntityRepositoryInterface
   */
  protected $entityRepository;

  /**
   * @var string
   */
  protected $settingsHash;

  /**
   * @var string
   */
  protected $imageHash;

  /**
   * @var \Drupal\background_image\BackgroundImageSettings
   */
  protected $settings;

  /**
   * @var \Drupal\background_image\BackgroundImageInterface|null
   */
  protected $parent;

  /**
   * {@inheritdoc}
   */
  public function __sleep() {

    // Don't use unset() here because the magic method
    // \Drupal\Core\Entity\ContentEntityBase::__get can cause the value to be
    // set as a FieldItemList object. Instead, always explicitly set to NULL.
    $this->cssSelector = NULL;
    $this->settingsHash = NULL;
    $this->imageHash = NULL;
    $this->parent = NULL;
    $this->settings = NULL;
    return parent::__sleep();
  }

  /**
   * {@inheritdoc}
   */
  public function associateEntity(EntityInterface $entity = NULL, $save = TRUE) {

    // Immediately return if not a valid entity.
    if (!$this
      ->getBackgroundImageManager()
      ->validEntity($entity)) {
      return;
    }
    $this
      ->set('type', self::TYPE_ENTITY)
      ->set('target', $entity
      ->getEntityTypeId() . ':' . $entity
      ->uuid())
      ->set('label', NULL);
    if ($save) {
      $this
        ->save();
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {

    /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
    $fields = parent::baseFieldDefinitions($entity_type);
    $fields['created'] = BaseFieldDefinition::create('created')
      ->setLabel(t('Authored on'))
      ->setDescription(t('The time that the background image was created.'))
      ->setDisplayOptions('view', [
      'region' => 'hidden',
    ]);
    $fields['changed'] = BaseFieldDefinition::create('changed')
      ->setLabel(t('Changed'))
      ->setDescription(t('The time that the background image was last edited.'))
      ->setDisplayOptions('view', [
      'region' => 'hidden',
    ]);
    $fields['image'] = BaseFieldDefinition::create('image')
      ->setLabel(t('Image'))
      ->setDescription(t('The background image to display.'))
      ->setSettings([
      'file_directory' => 'background_image',
      'alt_field' => 0,
      'alt_field_required' => 0,
      'title_field' => 0,
      'title_field_required' => 0,
      'max_resolution' => '',
      'min_resolution' => '',
      'default_image' => [
        'uuid' => NULL,
        'alt' => '',
        'title' => '',
        'width' => NULL,
        'height' => NULL,
      ],
    ])
      ->setDisplayOptions('form', [
      'type' => 'image_image',
      'weight' => 1,
    ])
      ->setDisplayOptions('view', [
      'label' => 'hidden',
      'weight' => 0,
    ]);
    $fields['label'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Label'))
      ->setDescription(t('An administrative description to help identify this specific background image.'))
      ->setRequired(TRUE)
      ->setTranslatable(TRUE)
      ->setDefaultValue('');
    $fields['settings'] = BaseFieldDefinition::create('map')
      ->setLabel(t('Settings'))
      ->setDescription(t('Specific settings for this background image.'))
      ->setTranslatable(TRUE);
    $fields['type'] = BaseFieldDefinition::create('list_integer')
      ->setLabel(t('Type'))
      ->setDescription(t('Choose when this background image should be displayed.'))
      ->setRequired(TRUE)
      ->setDefaultValue(self::TYPE_GLOBAL)
      ->setSettings([
      'allowed_values' => self::getTypes(),
    ]);
    $fields['target'] = BaseFieldDefinition::create('string_long')
      ->setLabel(t('Target'))
      ->setDescription(t('A target, if any.'))
      ->setDefaultValue('');
    $fields['uid'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('User'))
      ->setDescription(t('An entity reference to the user who created this background image.'))
      ->addConstraint('ReferenceAccess')
      ->addConstraint('ValidReference')
      ->setRequired(TRUE)
      ->setSettings([
      'target_type' => 'user',
    ]);
    return $fields;
  }

  /**
   * {@inheritdoc}
   */
  protected function getBackgroundImageManager() {
    if (!isset($this->backgroundImageManager)) {
      $this->backgroundImageManager = $this
        ->getContainer()
        ->get('background_image.manager');
    }
    return $this->backgroundImageManager;
  }

  /**
   * {@inheritdoc}
   */
  public function getBlur() {
    return $this
      ->getSetting('blur');
  }

  /**
   * {@inheritdoc}
   */
  public function getBlurRadius() {
    return $this
      ->getSetting('blur_radius');
  }

  /**
   * {@inheritdoc}
   */
  public function getBlurSpeed() {
    return $this
      ->getSetting('blur_speed');
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheTags() {
    $tags = parent::getCacheTags();

    // Make sure to get
    if ($this
      ->hasEntityToken() && ($entity = $this
      ->getBackgroundImageManager()
      ->getEntityFromCurrentRoute())) {
      $tags[] = "{$entity->getEntityTypeId()}:{$entity->id()}";
    }
    return $tags;
  }

  /**
   * Retrieves the Container.
   *
   * @return \Symfony\Component\DependencyInjection\ContainerInterface
   */
  protected function getContainer() {
    if (!isset($this->container)) {
      $this
        ->setContainer(\Drupal::getContainer());
    }
    return $this->container;
  }

  /**
   * {@inheritdoc}
   */
  public function getCreatedTime() {
    return $this
      ->get('created')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function getCssClass() {
    if (!isset($this->cssSelector)) {
      $this->cssSelector = $this
        ->getBackgroundImageManager()
        ->getBaseClass() . '--' . Html::cleanCssIdentifier($this
        ->getImageHash());
    }
    return $this->cssSelector;
  }

  /**
   * {@inheritdoc}
   */
  public function getCssUri() {
    $default_scheme = file_default_scheme();
    $min = $this
      ->getBackgroundImageManager()
      ->useMinifiedCssUri() ? '.min' : '';
    return "{$default_scheme}://background_image/css/{$this->id()}/{$default_scheme}/{$this->getImageHash()}{$min}.css";
  }

  /**
   * Retrieves the Entity Repository service.
   *
   * @return \Drupal\Core\Entity\EntityRepositoryInterface|mixed
   */
  protected function getEntityRepository() {
    if (!isset($this->entityRepository)) {
      $this->entityRepository = $this
        ->getContainer()
        ->get('entity.repository');
    }
    return $this->entityRepository;
  }

  /**
   * {@inheritdoc}
   */
  public function getImageHash() {
    if (!isset($this->imageHash)) {
      $image = $this
        ->getImageFile();
      $data = [
        'preload.background_color' => $this
          ->getSetting('preload.background_color'),
        'file' => $image ? $image
          ->getFileUri() : '',
      ];
      $this->imageHash = Crypt::hashBase64(serialize($data));
    }
    return $this->imageHash;
  }

  /**
   * {@inheritdoc}
   */
  public function getImageFile($parents = TRUE) {
    $file = $this
      ->get('image')->entity;
    if (!$file && $parents && ($parent = $this
      ->getParent())) {
      $file = $parent
        ->getImageFile($parents);
    }
    return $file;
  }

  /**
   * {@inheritdoc}
   */
  public function getImageUrl($styleName = NULL, array $options = [], $parents = TRUE) {
    if ($styleName === '_empty image_') {

      // The smallest data URI for a 1px square transparent GIF image.
      // http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever
      return 'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
    }
    $fileUri = $this
      ->getImageFile($parents)
      ->getFileUri();
    if ($styleName && ($imageStyle = ImageStyle::load($styleName)) && $imageStyle instanceof ImageStyle) {
      $uri = $imageStyle
        ->buildUrl($fileUri);
    }
    else {
      $uri = file_create_url($fileUri);
    }
    $options += [
      'absolute' => TRUE,
    ];
    return Url::fromUri($uri, $options)
      ->toString();
  }

  /**
   * {@inheritdoc}
   */
  public function getParent() {
    if (!isset($this->parent)) {
      $this->parent = FALSE;
      if (($target_entity = $this
        ->getTargetEntity()) && ($this->parent = $this
        ->getBackgroundImageManager()
        ->getEntityBundleBackgroundImage($target_entity))) {
        return $this->parent;
      }
      else {
        if ($this
          ->getType() !== self::TYPE_GLOBAL) {
          $this->parent = $this
            ->getBackgroundImageManager()
            ->getGlobalBackgroundImage() ?: FALSE;
        }
      }
    }
    return $this->parent;
  }

  /**
   * {@inheritdoc}
   */
  public function getOwner() {
    return $this
      ->get('uid')->entity;
  }

  /**
   * {@inheritdoc}
   */
  public function getOwnerId() {
    return $this
      ->get('uid')->target_id;
  }

  /**
   * {@inheritdoc}
   */
  public function getSetting($name, $default = NULL) {
    $value = $this
      ->getSettings()
      ->get($name);
    return isset($value) ? $value : $default;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  public function getSettingsHash($name = NULL) {
    if (!isset($this->settingsHash)) {
      $data = [];
      if (isset($name)) {
        $data[$name] = $this
          ->getSetting($name);
      }
      else {
        $data['settings'] = $this
          ->getSettings()
          ->get();
      }

      // Add entity specific target.
      if ((!isset($name) || $name === 'text' || $name === 'text.value') && $this
        ->hasEntityToken() && ($entity = $this
        ->getBackgroundImageManager()
        ->getEntityFromCurrentRoute())) {
        $data['entity'] = $entity;
      }
      $serialized = serialize($data);
      $this->settingsHash = Crypt::hashBase64($serialized);
    }
    return $this->settingsHash;
  }

  /**
   * {@inheritdoc}
   */
  public function getTarget($explode = FALSE) {
    $target = $this
      ->get('target')->value;
    return $target && $explode ? explode(':', $target) : $target;
  }

  /**
   * {@inheritdoc}
   */
  public function getTargetEntity($type = NULL, $target = NULL, $langcode = NULL, array $context = []) {
    if (!isset($type)) {
      $type = $this
        ->getType();
    }
    if (!isset($target)) {
      $target = $this
        ->getTarget();
    }
    $entity = NULL;
    if ($type === self::TYPE_ENTITY && isset($target)) {
      list($entity_type, $entity_id) = explode(':', $target);
      if (isset($entity_type) && isset($entity_id)) {
        $entity = $this
          ->getEntityRepository()
          ->loadEntityByUuid($entity_type, $entity_id);
      }
    }

    // Load entity with translation context.
    if ($entity instanceof EntityInterface) {
      return $this
        ->getEntityRepository()
        ->getTranslationFromContext($entity, $langcode ?: $this
        ->getLanguageCode(), $context);
    }
    return $entity;
  }

  /**
   * Returns the currently set langcode for the entity.
   *
   * @todo Remove if https://www.drupal.org/project/drupal/issues/2303877 lands.
   *
   * @return string
   *   The currently set langcode.
   */
  public function getLanguageCode() {
    if ($this->activeLangcode !== LanguageInterface::LANGCODE_DEFAULT) {
      return $this->activeLangcode;
    }
    return $this->defaultLangcode;
  }

  /**
   * {@inheritdoc}
   */
  public function getTargetEntityBundle($type = NULL, $target = NULL) {
    if (!isset($type)) {
      $type = $this
        ->getType();
    }
    if (!isset($target)) {
      $target = $this
        ->getTarget();
    }
    $entity = NULL;
    if ($type === self::TYPE_ENTITY_BUNDLE && $target) {
      list($entity_type_id, $entity_bundle) = explode(':', $target);
      if (isset($entity_type_id) && isset($entity_bundle) && ($entity_type = $this
        ->entityTypeManager()
        ->getDefinition($entity_type_id))) {
        if ($bundle_entity_type = $entity_type
          ->getBundleEntityType()) {
          $entity = $this
            ->entityTypeManager()
            ->getStorage($bundle_entity_type)
            ->load($entity_bundle);
        }
        else {
          $entity = $entity_type;
        }
      }
    }
    return $entity;
  }

  /**
   * {@inheritdoc}
   */
  public function getTargetView($type = NULL, $target = NULL) {
    if (!isset($type)) {
      $type = $this
        ->getType();
    }
    if (!isset($target)) {
      $target = $this
        ->getTarget();
    }

    /** @var \Drupal\views\ViewEntityInterface $view */
    $view = NULL;
    if ($type === self::TYPE_VIEW) {
      list($view_id, $display_id) = explode(':', $target);
      if (isset($view_id) && isset($display_id) && ($view = $this
        ->entityTypeManager()
        ->getStorage('view')
        ->load($view_id))) {
        $view_executable = $view
          ->getExecutable();
        $view_executable
          ->setDisplay($display_id);
        if (!$this
          ->getBackgroundImageManager()
          ->validView($view)) {
          $view = NULL;
        }
      }
    }
    return $view;
  }

  /**
   * {@inheritdoc}
   */
  public function getType() {
    return (int) $this
      ->get('type')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function getTypeLabel($link = FALSE) {
    if (!isset($type)) {
      $type = $this
        ->getType();
    }
    $types = self::getTypes();
    if (!isset($types[$type])) {
      return $this
        ->t('Unknown');
    }
    if ($label = $this
      ->label($link)) {
      if ($type === self::TYPE_ENTITY || $type === self::TYPE_ENTITY_BUNDLE || $type === self::TYPE_VIEW) {
        return $label;
      }
      return new FormattableMarkup('@type: @label', [
        '@type' => $types[$type],
        '@label' => $label,
      ]);
    }
    return $types[$type];
  }

  /**
   * {@inheritdoc}
   */
  public static function getTypes() {
    return [
      self::TYPE_GLOBAL => t('Global'),
      self::TYPE_ENTITY => t('Entity'),
      self::TYPE_ENTITY_BUNDLE => t('Entity Bundle'),
      // @todo Re-enable once support has been properly done.
      // self::TYPE_PATH => t('Path'),
      // self::TYPE_ROUTE => t('Route'),
      self::TYPE_VIEW => t('View'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getText() {
    return $this
      ->getSetting('text.value');
  }

  /**
   * {@inheritdoc}
   */
  public function hasEntityToken($entity_type = NULL, $property = NULL) {
    $entity_type = isset($entity_type) ? (array) $entity_type : '[^:]+';
    if (is_array($entity_type)) {
      $types = [];
      foreach ($entity_type as $type) {
        $types[] = preg_quote($type);
      }
      $entity_type = '(' . implode('|', $types) . ')';
    }
    $property = isset($property) ? (array) $property : '[^\\]]+';
    if (is_array($property)) {
      $properties = [];
      foreach ($property as $value) {
        $properties[] = preg_quote($value);
      }
      $property = '(' . implode('|', $properties) . ')';
    }
    $text = $this
      ->getSetting('text.value', '');
    $matched = !!preg_match_all("/\\[{$entity_type}:{$property}\\]/", $text);
    return $matched;
  }

  /**
   * {@inheritdoc}
   */
  public function label($link = FALSE) {
    if ($entity = $this
      ->getTargetEntity()) {
      return $this
        ->t('%entity_type (@entity_id): @entity_label', [
        '%entity_type' => $this
          ->getBackgroundImageManager()
          ->getEntityBundleLabel($entity) ?: $entity
          ->getEntityType()
          ->getLabel(),
        '@entity_label' => $link ? $entity
          ->toLink()
          ->toString() : $entity
          ->label(),
        '@entity_id' => $entity
          ->id(),
      ]);
    }
    else {
      if ($entity_bundle = $this
        ->getTargetEntityBundle()) {
        if ($entity_bundle instanceof EntityInterface) {
          return $this
            ->t('%entity_type (@entity_id): @entity_label', [
            '%entity_type' => $entity_bundle
              ->getEntityType()
              ->getLabel(),
            '@entity_label' => $link && $entity_bundle
              ->hasLinkTemplate('edit-form') ? $entity_bundle
              ->toLink(NULL, 'edit-form')
              ->toString() : $entity_bundle
              ->label(),
            '@entity_id' => $entity_bundle
              ->id(),
          ]);
        }
        else {
          if ($entity_bundle instanceof EntityTypeInterface) {
            return $this
              ->t('%entity_type (@entity_id)', [
              '%entity_type' => $entity_bundle
                ->getLabel(),
              '@entity_id' => $entity_bundle
                ->id(),
            ]);
          }
        }
      }
      else {
        if ($view = $this
          ->getTargetView()) {
          $executable = $view
            ->getExecutable();
          $display = $executable
            ->getDisplay();
          $path = FALSE;
          if ($display
            ->hasPath()) {
            $path = '/' . $display
              ->getPath();
            if ($view
              ->status() && strpos($path, '%') === FALSE) {
              $path = \Drupal::l($path, Url::fromUserInput($path));
            }
          }
          return $this
            ->t('View (@entity_id): @entity_label', [
            '@entity_label' => $link && $path ? $path : $view
              ->label(),
            '@entity_id' => "{$view->id()}:{$executable->current_display}",
          ]);
        }
      }
    }
    $label = parent::label();
    return isset($label) ? trim($label) : NULL;
  }

  /**
   * {@inheritdoc}
   */
  public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
    parent::preCreate($storage_controller, $values);
    $values += [
      'uid' => \Drupal::currentUser()
        ->id(),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function save() {

    // Only save overridden settings.
    $this
      ->set('settings', $this
      ->getSettings()
      ->getOverridden());
    return parent::save();
  }

  /**
   * {@inheritdoc}
   */
  public function setOwnerId($uid) {
    $this
      ->set('uid', $uid);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setOwner(UserInterface $account) {
    $this
      ->set('uid', $account
      ->id());
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BackgroundImage::$backgroundImageManager protected property
BackgroundImage::$cssSelector protected property
BackgroundImage::$entityRepository protected property
BackgroundImage::$imageHash protected property
BackgroundImage::$parent protected property
BackgroundImage::$settings protected property
BackgroundImage::$settingsHash protected property
BackgroundImage::associateEntity public function Associates a specific entity with the background image. Overrides BackgroundImageInterface::associateEntity
BackgroundImage::baseFieldDefinitions public static function Provides base field definitions for an entity type. Overrides ContentEntityBase::baseFieldDefinitions
BackgroundImage::getBackgroundImageManager protected function
BackgroundImage::getBlur public function Overrides BackgroundImageInterface::getBlur
BackgroundImage::getBlurRadius public function Overrides BackgroundImageInterface::getBlurRadius
BackgroundImage::getBlurSpeed public function Overrides BackgroundImageInterface::getBlurSpeed
BackgroundImage::getCacheTags public function The cache tags associated with this object. Overrides EntityBase::getCacheTags
BackgroundImage::getContainer protected function Retrieves the Container.
BackgroundImage::getCreatedTime public function
BackgroundImage::getCssClass public function Overrides BackgroundImageInterface::getCssClass
BackgroundImage::getCssUri public function Retrieves the CSS file this background image. Overrides BackgroundImageInterface::getCssUri
BackgroundImage::getEntityRepository protected function Retrieves the Entity Repository service.
BackgroundImage::getImageFile public function Retrieves the image file. Overrides BackgroundImageInterface::getImageFile
BackgroundImage::getImageHash public function Retrieves the image based hash. Overrides BackgroundImageInterface::getImageHash
BackgroundImage::getImageUrl public function Retrieves the URL for the image. Overrides BackgroundImageInterface::getImageUrl
BackgroundImage::getLanguageCode public function Returns the currently set langcode for the entity.
BackgroundImage::getOwner public function Returns the entity owner's user entity. Overrides EntityOwnerInterface::getOwner
BackgroundImage::getOwnerId public function Returns the entity owner's user ID. Overrides EntityOwnerInterface::getOwnerId
BackgroundImage::getParent public function Retrieves the parent background image, if one exists. Overrides BackgroundImageInterface::getParent
BackgroundImage::getSetting public function Overrides BackgroundImageInterface::getSetting
BackgroundImage::getSettings public function Retrieves the settings for this background image. Overrides BackgroundImageInterface::getSettings
BackgroundImage::getSettingsHash public function Retrieves the settings hash. Overrides BackgroundImageInterface::getSettingsHash
BackgroundImage::getTarget public function Retrieves the target identifier that is specific to the type. Overrides BackgroundImageInterface::getTarget
BackgroundImage::getTargetEntity public function Retrieves the target entity, if the type is supported and exists. Overrides BackgroundImageInterface::getTargetEntity
BackgroundImage::getTargetEntityBundle public function Retrieves the target entity bundle, if the type is supported and exists. Overrides BackgroundImageInterface::getTargetEntityBundle
BackgroundImage::getTargetView public function Retrieves the target entity view, if the type is supported and exists. Overrides BackgroundImageInterface::getTargetView
BackgroundImage::getText public function Overrides BackgroundImageInterface::getText
BackgroundImage::getType public function The type. Overrides BackgroundImageInterface::getType
BackgroundImage::getTypeLabel public function The type label. Overrides BackgroundImageInterface::getTypeLabel
BackgroundImage::getTypes public static function Retrieves all the types. Overrides BackgroundImageInterface::getTypes
BackgroundImage::hasEntityToken public function Indicates whether this background image contains entity based tokens. Overrides BackgroundImageInterface::hasEntityToken
BackgroundImage::label public function Gets the label of the entity. Overrides ContentEntityBase::label
BackgroundImage::preCreate public static function Changes the values of an entity before it is created. Overrides EntityBase::preCreate
BackgroundImage::save public function Saves an entity permanently. Overrides EntityBase::save
BackgroundImage::setOwner public function Sets the entity owner's user entity. Overrides EntityOwnerInterface::setOwner
BackgroundImage::setOwnerId public function Sets the entity owner's user ID. Overrides EntityOwnerInterface::setOwnerId
BackgroundImage::__sleep public function Overrides ContentEntityBase::__sleep
BackgroundImageInterface::BLUR_NONE constant Never blur the background image.
BackgroundImageInterface::BLUR_PERSISTENT constant Always blur the background image.
BackgroundImageInterface::BLUR_SCROLL constant Only blur the background image after the user has scrolled.
BackgroundImageInterface::BLUR_SCROLL_FULL_VIEWPORT constant Same as BLUR_SCROLL, but also only if using the full_viewport setting.
BackgroundImageInterface::INHERIT constant General value to indicate "inherit".
BackgroundImageInterface::NORMAL constant General value to indicate "normal".
BackgroundImageInterface::TYPE_ENTITY constant Attached to an entity.
BackgroundImageInterface::TYPE_ENTITY_BUNDLE constant Attached to an entity bundle.
BackgroundImageInterface::TYPE_GLOBAL constant Attached to whole site.
BackgroundImageInterface::TYPE_PATH constant Attached to a path or multiple paths.
BackgroundImageInterface::TYPE_ROUTE constant Attached to a route or multiple routes.
BackgroundImageInterface::TYPE_VIEW constant Attached to a view page.
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
ContentEntityBase::$activeLangcode protected property Language code identifying the entity active language.
ContentEntityBase::$defaultLangcode protected property Local cache for the default language code.
ContentEntityBase::$defaultLangcodeKey protected property The default langcode entity key.
ContentEntityBase::$enforceRevisionTranslationAffected protected property Whether the revision translation affected flag has been enforced.
ContentEntityBase::$entityKeys protected property Holds untranslatable entity keys such as the ID, bundle, and revision ID.
ContentEntityBase::$fieldDefinitions protected property Local cache for field definitions.
ContentEntityBase::$fields protected property The array of fields, each being an instance of FieldItemListInterface.
ContentEntityBase::$fieldsToSkipFromTranslationChangesCheck protected static property Local cache for fields to skip from the checking for translation changes.
ContentEntityBase::$isDefaultRevision protected property Indicates whether this is the default revision.
ContentEntityBase::$langcodeKey protected property The language entity key.
ContentEntityBase::$languages protected property Local cache for the available language objects.
ContentEntityBase::$loadedRevisionId protected property The loaded revision ID before the new revision was set.
ContentEntityBase::$newRevision protected property Boolean indicating whether a new revision should be created on save.
ContentEntityBase::$revisionTranslationAffectedKey protected property The revision translation affected entity key.
ContentEntityBase::$translatableEntityKeys protected property Holds translatable entity keys such as the label.
ContentEntityBase::$translationInitialize protected property A flag indicating whether a translation object is being initialized.
ContentEntityBase::$translations protected property An array of entity translation metadata.
ContentEntityBase::$validated protected property Whether entity validation was performed.
ContentEntityBase::$validationRequired protected property Whether entity validation is required before saving the entity.
ContentEntityBase::$values protected property The plain data values of the contained fields.
ContentEntityBase::access public function Checks data value access. Overrides EntityBase::access 1
ContentEntityBase::addTranslation public function Adds a new translation to the translatable object. Overrides TranslatableInterface::addTranslation
ContentEntityBase::bundle public function Gets the bundle of the entity. Overrides EntityBase::bundle
ContentEntityBase::bundleFieldDefinitions public static function Provides field definitions for a specific bundle. Overrides FieldableEntityInterface::bundleFieldDefinitions 4
ContentEntityBase::clearTranslationCache protected function Clear entity translation object cache to remove stale references.
ContentEntityBase::createDuplicate public function Creates a duplicate of the entity. Overrides EntityBase::createDuplicate 1
ContentEntityBase::get public function Gets a field item list. Overrides FieldableEntityInterface::get
ContentEntityBase::getEntityKey protected function Gets the value of the given entity key, if defined. 1
ContentEntityBase::getFieldDefinition public function Gets the definition of a contained field. Overrides FieldableEntityInterface::getFieldDefinition
ContentEntityBase::getFieldDefinitions public function Gets an array of field definitions of all contained fields. Overrides FieldableEntityInterface::getFieldDefinitions
ContentEntityBase::getFields public function Gets an array of all field item lists. Overrides FieldableEntityInterface::getFields
ContentEntityBase::getFieldsToSkipFromTranslationChangesCheck protected function Returns an array of field names to skip in ::hasTranslationChanges. 1
ContentEntityBase::getIterator public function
ContentEntityBase::getLanguages protected function
ContentEntityBase::getLoadedRevisionId public function Gets the loaded Revision ID of the entity. Overrides RevisionableInterface::getLoadedRevisionId
ContentEntityBase::getRevisionId public function Gets the revision identifier of the entity. Overrides RevisionableInterface::getRevisionId
ContentEntityBase::getTranslatableFields public function Gets an array of field item lists for translatable fields. Overrides FieldableEntityInterface::getTranslatableFields
ContentEntityBase::getTranslatedField protected function Gets a translated field.
ContentEntityBase::getTranslation public function Gets a translation of the data. Overrides TranslatableInterface::getTranslation
ContentEntityBase::getTranslationLanguages public function Returns the languages the data is translated to. Overrides TranslatableInterface::getTranslationLanguages
ContentEntityBase::getTranslationStatus public function Returns the translation status. Overrides TranslationStatusInterface::getTranslationStatus
ContentEntityBase::getUntranslated public function Returns the translatable object referring to the original language. Overrides TranslatableInterface::getUntranslated
ContentEntityBase::hasField public function Determines whether the entity has a field with the given name. Overrides FieldableEntityInterface::hasField
ContentEntityBase::hasTranslation public function Checks there is a translation for the given language code. Overrides TranslatableInterface::hasTranslation
ContentEntityBase::hasTranslationChanges public function Determines if the current translation of the entity has unsaved changes. Overrides TranslatableInterface::hasTranslationChanges
ContentEntityBase::id public function Gets the identifier. Overrides EntityBase::id
ContentEntityBase::initializeTranslation protected function Instantiates a translation object for an existing translation.
ContentEntityBase::isDefaultRevision public function Checks if this entity is the default revision. Overrides RevisionableInterface::isDefaultRevision
ContentEntityBase::isDefaultTranslation public function Checks whether the translation is the default one. Overrides TranslatableInterface::isDefaultTranslation
ContentEntityBase::isDefaultTranslationAffectedOnly public function Checks if untranslatable fields should affect only the default translation. Overrides TranslatableRevisionableInterface::isDefaultTranslationAffectedOnly
ContentEntityBase::isLatestRevision public function Checks if this entity is the latest revision. Overrides RevisionableInterface::isLatestRevision
ContentEntityBase::isLatestTranslationAffectedRevision public function Checks whether this is the latest revision affecting this translation. Overrides TranslatableRevisionableInterface::isLatestTranslationAffectedRevision
ContentEntityBase::isNewRevision public function Determines whether a new revision should be created on save. Overrides RevisionableInterface::isNewRevision
ContentEntityBase::isNewTranslation public function Checks whether the translation is new. Overrides TranslatableInterface::isNewTranslation
ContentEntityBase::isRevisionTranslationAffected public function Checks whether the current translation is affected by the current revision. Overrides TranslatableRevisionableInterface::isRevisionTranslationAffected
ContentEntityBase::isRevisionTranslationAffectedEnforced public function Checks if the revision translation affected flag value has been enforced. Overrides TranslatableRevisionableInterface::isRevisionTranslationAffectedEnforced
ContentEntityBase::isTranslatable public function Returns the translation support status. Overrides TranslatableInterface::isTranslatable
ContentEntityBase::isValidationRequired public function Checks whether entity validation is required before saving the entity. Overrides FieldableEntityInterface::isValidationRequired
ContentEntityBase::language public function Gets the language of the entity. Overrides EntityBase::language
ContentEntityBase::onChange public function Reacts to changes to a field. Overrides FieldableEntityInterface::onChange
ContentEntityBase::postCreate public function Acts on a created entity before hooks are invoked. Overrides EntityBase::postCreate
ContentEntityBase::postSave public function Acts on a saved entity before the insert or update hook is invoked. Overrides EntityBase::postSave 5
ContentEntityBase::preSave public function Acts on an entity before the presave hook is invoked. Overrides EntityBase::preSave 5
ContentEntityBase::preSaveRevision public function Acts on a revision before it gets saved. Overrides RevisionableInterface::preSaveRevision 2
ContentEntityBase::referencedEntities public function Gets a list of entities referenced by this entity. Overrides EntityBase::referencedEntities 1
ContentEntityBase::removeTranslation public function Removes the translation identified by the given language code. Overrides TranslatableInterface::removeTranslation
ContentEntityBase::set public function Sets a field value. Overrides FieldableEntityInterface::set
ContentEntityBase::setDefaultLangcode protected function Populates the local cache for the default language code.
ContentEntityBase::setNewRevision public function Enforces an entity to be saved as a new revision. Overrides RevisionableInterface::setNewRevision
ContentEntityBase::setRevisionTranslationAffected public function Marks the current revision translation as affected. Overrides TranslatableRevisionableInterface::setRevisionTranslationAffected
ContentEntityBase::setRevisionTranslationAffectedEnforced public function Enforces the revision translation affected flag value. Overrides TranslatableRevisionableInterface::setRevisionTranslationAffectedEnforced
ContentEntityBase::setValidationRequired public function Sets whether entity validation is required before saving the entity. Overrides FieldableEntityInterface::setValidationRequired
ContentEntityBase::toArray public function Gets an array of all property values. Overrides EntityBase::toArray
ContentEntityBase::updateFieldLangcodes protected function Updates language for already instantiated fields.
ContentEntityBase::updateLoadedRevisionId public function Updates the loaded Revision ID with the revision ID. Overrides RevisionableInterface::updateLoadedRevisionId
ContentEntityBase::updateOriginalValues public function Updates the original values with the interim changes.
ContentEntityBase::uuid public function Gets the entity UUID (Universally Unique Identifier). Overrides EntityBase::uuid
ContentEntityBase::validate public function Validates the currently set values. Overrides FieldableEntityInterface::validate
ContentEntityBase::wasDefaultRevision public function Checks whether the entity object was a default revision when it was saved. Overrides RevisionableInterface::wasDefaultRevision
ContentEntityBase::__clone public function Magic method: Implements a deep clone.
ContentEntityBase::__construct public function Constructs an Entity object. Overrides EntityBase::__construct
ContentEntityBase::__get public function Implements the magic method for getting object properties.
ContentEntityBase::__isset public function Implements the magic method for isset().
ContentEntityBase::__set public function Implements the magic method for setting object properties.
ContentEntityBase::__unset public function Implements the magic method for unset().
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function Aliased as: traitSleep 1
DependencySerializationTrait::__wakeup public function 2
EntityBase::$enforceIsNew protected property Boolean indicating whether the entity should be forced to be new.
EntityBase::$entityTypeId protected property The entity type.
EntityBase::$typedData protected property A typed data object wrapping this entity.
EntityBase::create public static function Constructs a new entity object, without permanently saving it. Overrides EntityInterface::create
EntityBase::delete public function Deletes an entity permanently. Overrides EntityInterface::delete 2
EntityBase::enforceIsNew public function Enforces an entity to be new. Overrides EntityInterface::enforceIsNew
EntityBase::entityManager Deprecated protected function Gets the entity manager.
EntityBase::entityTypeBundleInfo protected function Gets the entity type bundle info service.
EntityBase::entityTypeManager protected function Gets the entity type manager.
EntityBase::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyTrait::getCacheContexts
EntityBase::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyTrait::getCacheMaxAge
EntityBase::getCacheTagsToInvalidate public function Returns the cache tags that should be used to invalidate caches. Overrides EntityInterface::getCacheTagsToInvalidate 2
EntityBase::getConfigDependencyKey public function Gets the key that is used to store configuration dependencies. Overrides EntityInterface::getConfigDependencyKey
EntityBase::getConfigDependencyName public function Gets the configuration dependency name. Overrides EntityInterface::getConfigDependencyName 1
EntityBase::getConfigTarget public function Gets the configuration target identifier for the entity. Overrides EntityInterface::getConfigTarget 1
EntityBase::getEntityType public function Gets the entity type definition. Overrides EntityInterface::getEntityType
EntityBase::getEntityTypeId public function Gets the ID of the type of the entity. Overrides EntityInterface::getEntityTypeId
EntityBase::getListCacheTagsToInvalidate protected function The list cache tags to invalidate for this entity.
EntityBase::getOriginalId public function Gets the original ID. Overrides EntityInterface::getOriginalId 1
EntityBase::getTypedData public function Gets a typed data object for this entity object. Overrides EntityInterface::getTypedData
EntityBase::hasLinkTemplate public function Indicates if a link template exists for a given key. Overrides EntityInterface::hasLinkTemplate
EntityBase::invalidateTagsOnDelete protected static function Invalidates an entity's cache tags upon delete. 1
EntityBase::invalidateTagsOnSave protected function Invalidates an entity's cache tags upon save. 1
EntityBase::isNew public function Determines whether the entity is new. Overrides EntityInterface::isNew 2
EntityBase::languageManager protected function Gets the language manager.
EntityBase::link public function Deprecated way of generating a link to the entity. See toLink(). Overrides EntityInterface::link 1
EntityBase::linkTemplates protected function Gets an array link templates. 1
EntityBase::load public static function Loads an entity. Overrides EntityInterface::load
EntityBase::loadMultiple public static function Loads one or more entities. Overrides EntityInterface::loadMultiple
EntityBase::postDelete public static function Acts on deleted entities before the delete hook is invoked. Overrides EntityInterface::postDelete 16
EntityBase::postLoad public static function Acts on loaded entities. Overrides EntityInterface::postLoad 2
EntityBase::preDelete public static function Acts on entities before they are deleted and before hooks are invoked. Overrides EntityInterface::preDelete 4
EntityBase::setOriginalId public function Sets the original ID. Overrides EntityInterface::setOriginalId 1
EntityBase::toLink public function Generates the HTML for a link to this entity. Overrides EntityInterface::toLink
EntityBase::toUrl public function Gets the URL object for the entity. Overrides EntityInterface::toUrl 2
EntityBase::uriRelationships public function Gets a list of URI relationships supported by this entity. Overrides EntityInterface::uriRelationships
EntityBase::url public function Gets the public URL for this entity. Overrides EntityInterface::url 2
EntityBase::urlInfo public function Gets the URL object for the entity. Overrides EntityInterface::urlInfo 1
EntityBase::urlRouteParameters protected function Gets an array of placeholders for this entity. 2
EntityBase::uuidGenerator protected function Gets the UUID generator.
EntityChangedTrait::getChangedTime public function Gets the timestamp of the last entity change for the current translation.
EntityChangedTrait::getChangedTimeAcrossTranslations public function Returns the timestamp of the last entity change across all translations.
EntityChangedTrait::setChangedTime public function Sets the timestamp of the last entity change for the current translation.
EntityChangesDetectionTrait::getFieldsToSkipFromTranslationChangesCheck protected function Returns an array of field names to skip when checking for changes. Aliased as: traitGetFieldsToSkipFromTranslationChangesCheck
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
SynchronizableEntityTrait::$isSyncing protected property Whether this entity is being created, updated or deleted through a synchronization process.
SynchronizableEntityTrait::isSyncing public function
SynchronizableEntityTrait::setSyncing public function
TranslationStatusInterface::TRANSLATION_CREATED constant Status code identifying a newly created translation.
TranslationStatusInterface::TRANSLATION_EXISTING constant Status code identifying an existing translation.
TranslationStatusInterface::TRANSLATION_REMOVED constant Status code identifying a removed translation.