You are here

public function ActionLinkHelper::flagHelper in Flag Lists 4.0.x

Same name and namespace in other branches
  1. 8 src/Controller/ActionLinkHelper.php \Drupal\flag_lists\Controller\ActionLinkHelper::flagHelper()

Helper function for flag ActionLinks.

Parameters

\Drupal\flag\FlagInterface $flag: The flag to flag.

string $entity_id: The entity id to add the flag list item to.

string $flag_list: The flag list to add the flag list item to.

File

src/Controller/ActionLinkHelper.php, line 54

Class

ActionLinkHelper
Helper class for ActionLink Controller.

Namespace

Drupal\flag_lists\Controller

Code

public function flagHelper(FlagInterface $flag, $entity_id, $flag_list) {

  // Create the Flag List Item.
  $flag_list_name = $this->flagListsService
    ->getFlaggingCollectionById($flag_list)
    ->getName();
  $flag_list_item = FlagListItem::create([
    'entity_id' => $entity_id,
    'type' => $flag
      ->getFlaggableEntityTypeId(),
    'baseflag' => $flag
      ->id(),
    'flag_list' => $flag_list,
    'name' => $flag_list_name . ' ' . $entity_id,
  ]);
  $flag_list_item
    ->save();
}