You are here

private function DemoSystem::getOrCreateFont in Open Social 8.6

Same name and namespace in other branches
  1. 8.9 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
  2. 8 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
  3. 8.2 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
  4. 8.3 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
  5. 8.4 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
  6. 8.5 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
  7. 8.7 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
  8. 8.8 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
  9. 10.3.x modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
  10. 10.0.x modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
  11. 10.1.x modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
  12. 10.2.x modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()

Get or create the font.

Parameters

string $fontName: The font name.

Return value

int|mixed|null|string Return the font.

File

modules/custom/social_demo/src/DemoSystem.php, line 267

Class

DemoSystem
Class DemoSystem.

Namespace

Drupal\social_demo

Code

private function getOrCreateFont($fontName) {

  /** @var \Drupal\social_font\Entity\Font $font_entities */
  foreach (Font::loadMultiple() as $font_entities) {
    if ($fontName == $font_entities
      ->get('name')->value) {
      return $font_entities
        ->id();
    }
  }

  // Ok, so it doesn't exist.

  /* @var Font $font */
  $font = Font::create([
    'name' => $fontName,
    'user_id' => 1,
    'created' => \Drupal::time()
      ->getRequestTime(),
    'field_fallback' => '0',
  ]);
  $font
    ->save();

  // Return the id.
  return $font
    ->id();
}