You are here

public function Subscribers::getFlags in Message Subscribe 8

Get Message subscribe related flags.

Return Flags related to message subscribe using a name convention -- the flag name should start with "subscribe_".

Parameters

string $entity_type: (optional) The entity type for which to load the flags.

string $bundle: (optional) The bundle for which to load the flags.

\Drupal\Core\Session\AccountInterface $account: (optional) The user account to filter available flags. If not set, all flags for the given entity and bundle will be returned.

Return value

\Drupal\flag\FlagInterface[] An array of the structure [fid] = flag_object.

Overrides SubscribersInterface::getFlags

See also

\Drupal\flag\FlagServiceInterface::getAllFlags()

File

src/Subscribers.php, line 376

Class

Subscribers
A message subscribers service.

Namespace

Drupal\message_subscribe

Code

public function getFlags($entity_type = NULL, $bundle = NULL, AccountInterface $account = NULL) {
  $flags = $this->flagService
    ->getAllFlags($entity_type, $bundle);
  if ($account) {

    // Filter flags down to ones the account has action access for.
    // @see https://www.drupal.org/node/2870375
    foreach ($flags as $flag_id => $flag) {
      if (!$flag
        ->actionAccess('flag', $account)
        ->isAllowed() && !$flag
        ->actionAccess('unflag', $account)
        ->isAllowed()) {
        unset($flags[$flag_id]);
      }
    }
  }
  $ms_flags = [];
  $prefix = $this->config
    ->get('flag_prefix') . '_';
  foreach ($flags as $flag_name => $flag) {

    // Check that the flag is using name convention.
    if (strpos($flag_name, $prefix) === 0) {
      $ms_flags[$flag_name] = $flag;
    }
  }
  return $ms_flags;
}