You are here

public function BackgroundImage::hasEntityToken in Background Image 2.0.x

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

Indicates whether this background image contains entity based tokens.

Parameters

string|string[] $entity_type: Optional. Specific entity types to look for.

string|string[] $property: Optional. Specific entity properties to look for.

Return value

bool

Overrides BackgroundImageInterface::hasEntityToken

2 calls to BackgroundImage::hasEntityToken()
BackgroundImage::getCacheTags in src/Entity/BackgroundImage.php
The cache tags associated with this object.
BackgroundImage::getSettingsHash in src/Entity/BackgroundImage.php
Retrieves the settings hash.

File

src/Entity/BackgroundImage.php, line 617

Class

BackgroundImage
Defines the Background Image entity.

Namespace

Drupal\background_image\Entity

Code

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;
}