public static function TypeStyleExtension::getTypeStyle in Type Style 8
Helper function to grab a style for a given entity.
Parameters
string|\Drupal\core\Entity\EntityInterface $type: The target entity type, or the entity object if available.
mixed|string $id: The target entity ID, or a style if an object is passed in $type.
string $style: The style name, or a default if an object is passed in $type.
string $default: A default value in case the style is not set. Defaults to empty string.
Return value
string The style if set, or the default. This value is safe to use
See also
\Drupal\system\Tests\Theme\TwigExtensionTest::testTwigExtensionFunction()
File
- src/
TwigExtension/ TypeStyleExtension.php, line 58
Class
- TypeStyleExtension
- A Twig extension to render type styles.
Namespace
Drupal\type_style\TwigExtensionCode
public static function getTypeStyle($type, $id, $style = NULL, $default = '') {
if ($type instanceof EntityInterface) {
return type_style_get_style($type, $id, $style);
}
elseif (($storage = \Drupal::entityTypeManager()
->getStorage($type)) && $style) {
if ($entity = $storage
->load($id)) {
return type_style_get_style($entity, $style, $default);
}
}
return $default;
}