FlagLinkBuilder.php in Flag 8.4
File
src/FlagLinkBuilder.php
View source
<?php
namespace Drupal\flag;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Security\TrustedCallbackInterface;
class FlagLinkBuilder implements FlagLinkBuilderInterface, TrustedCallbackInterface {
protected $entityTypeManager;
protected $flagService;
public function __construct(EntityTypeManagerInterface $entity_type_manager, FlagServiceInterface $flag_service) {
$this->entityTypeManager = $entity_type_manager;
$this->flagService = $flag_service;
}
public static function trustedCallbacks() {
return [
'build',
];
}
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);
}
}