function type_style_get_styles in Type Style 8
Helper function to grab all styles for a given entity.
You can pass a bundle (ex: NodeType) or a bundlable entity (ex: Node).
Parameters
\Drupal\Core\Entity\EntityInterface $entity: A bundlable entity, or a bundle entity.
Return value
array An associative array of styles. Values are safe to use.
1 call to type_style_get_styles()
- type_style_get_style in ./
type_style.module - Helper function to grab a style for a given entity.
File
- ./
type_style.module, line 140 - Hook implementations for the Type Style module.
Code
function type_style_get_styles(EntityInterface $entity) {
$bundle_type = $entity
->getEntityType()
->getBundleEntityType();
if (!$entity instanceof ConfigEntityBundleBase && $bundle_type) {
$entity = \Drupal::entityTypeManager()
->getStorage($bundle_type)
->load($entity
->bundle());
}
if ($entity instanceof ThirdPartySettingsInterface) {
$styles = $entity
->getThirdPartySettings('type_style');
}
else {
$styles = [];
}
return preg_replace('/[^a-zA-Z0-9\\-\\_\\#]/', '', $styles);
}