You are here

public function ProtectionRuleListBuilder::getProtections in User protect 8

Gets enabled protections for entity as a string.

Parameters

\Drupal\userprotect\Entity\ProtectionRuleInterface $entity: The entity the to get protections for.

Return value

string The enabled protections, comma-separated.

1 call to ProtectionRuleListBuilder::getProtections()
ProtectionRuleListBuilder::buildRow in src/Controller/ProtectionRuleListBuilder.php
Builds a row for an entity in the entity listing.

File

src/Controller/ProtectionRuleListBuilder.php, line 52

Class

ProtectionRuleListBuilder
Provides a listing of protection rules.

Namespace

Drupal\userprotect\Controller

Code

public function getProtections(ProtectionRuleInterface $entity) {
  $all_protections = $entity
    ->getProtections()
    ->getAll();
  $enabled_protections = $entity
    ->getProtections()
    ->getEnabledPlugins();
  if (count($all_protections) == count($enabled_protections)) {
    return $this
      ->t('All');
  }
  return implode(', ', array_map(function ($item) {
    return $item
      ->label();
  }, $enabled_protections));
}