private function DemoSystem::getOrCreateFont in Open Social 8
Same name and namespace in other branches
- 8.9 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
- 8.2 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
- 8.3 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
- 8.4 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
- 8.5 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
- 8.6 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
- 8.7 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
- 8.8 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
- 10.3.x modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
- 10.0.x modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
- 10.1.x modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::getOrCreateFont()
- 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_demoCode
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();
}