You are here

public function FlagLinkBuilder::build in Flag 8.4

Lazy builder callback for displaying a flag action link.

Parameters

string $entity_type_id: The entity type ID for which the link should be shown.

string|int $entity_id: The entity ID for which the link should be shown.

string $flag_id: The flag ID for which the link should be shown.

Return value

array A render array for the action link, empty if the user does not have access.

Overrides FlagLinkBuilderInterface::build

File

src/FlagLinkBuilder.php, line 50

Class

FlagLinkBuilder
Provides a lazy builder for flag links.

Namespace

Drupal\flag

Code

public function build($entity_type_id, $entity_id, $flag_id) {
  $entity = $this->entityTypeManager
    ->getStorage($entity_type_id)
    ->load($entity_id);
  $flag = $this->flagService
    ->getFlagById($flag_id);
  $link_type_plugin = $flag
    ->getLinkTypePlugin();
  return $link_type_plugin
    ->getAsFlagLink($flag, $entity);
}