You are here

function type_style_get_style in Type Style 8

Helper function to grab a style 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.

string $name: The name of the style you want to get (i.e. color, icon).

mixed $default: A default value in case the style is not set. Defaults to FALSE.

Return value

mixed The style if set, or the default. This value is safe to use.

5 calls to type_style_get_style()
TypeStyle::render in src/Plugin/views/field/TypeStyle.php
Renders the field.
TypeStyleExtension::getTypeStyle in src/TwigExtension/TypeStyleExtension.php
Helper function to grab a style for a given entity.
TypeStyleModeration::render in modules/type_style_moderation/src/Plugin/views/field/TypeStyleModeration.php
Renders the field.
TypeStyleTest::testTypeStyle in tests/src/Functional/TypeStyleTest.php
Tests that the Type Style module works as expected.
type_style_tokens in ./type_style.tokens.inc
Implements hook_tokens().

File

./type_style.module, line 124
Hook implementations for the Type Style module.

Code

function type_style_get_style(EntityInterface $entity, $name, $default = FALSE) {
  $styles = type_style_get_styles($entity);
  return isset($styles[$name]) ? $styles[$name] : $default;
}