# PCM Badge Bundle Create badges from objects or as standalone elements. IMAGE HERE ```twig {{ job.kind.label }} {{ job.kind.label }} Sale 20% off Danger! ```
# Creating badges with `BadgeableInterface` Any object that you would like to be able to be turned into a badge must implement `BadgeableInterface`. This interface specifies a single method `getBadgeColour()` which expects an instance of the enum `BadgeColour` to be returned and is used to determine the colour of the rendered badge. This method can contain as much logic in it as you'd like to return different colours of badge under different circumstances. EG: ```php // Job.php public function getBadgeColour(): BadgeColour { return match ($this->getKind()) { JobKind::Investigation => BadgeColour::BLUE, JobKind::Interrogation => BadgeColour::RED, JobKind::Shootout => BadgeColour::BLACK, JobKind::SipWhiskey => BadgeColour::FOREST, default => BadgeColour::GREY }; } ``` You then specify the object using the `:obj` prop when rendering the badge: ```twig {# job.html.twig #} {{ job.kind.value }} ```
# Standalone badges If you just want a badge of a certain colour instead of associating it with an object, you can specify a `colour` prop instead. ```twig Danger ```
# Props overview A badge must contain either an `obj` or a `colour`, but not both. `obj` - An instance of an object that implements `BadgeableInterface`. You can use either of the follow syntaxes: ```twig :obj="job.kind" obj="{{ job.kind }}" ``` `colour` - One of the available colours specified by the `Badge` enum. For a full list of acceptable values type in some junk and read the exception message. `outline` - A boolean attribute that changes the style of the badge to an outline. `class` - Extra classes you want to add to the badge element. These are merged with the badge base classes taking priority in case of conflicts. `label` - Badge label text. Content inside the content block will be prioritised over the label attribute if present. ```php {# Both of these render the same markup. #} Warning! ```
# Config ```yaml pcm_badge: base_classes: "base classes here" ```