You are here

public function RatePermissions::permissions in Rate 8

Same name and namespace in other branches
  1. 8.2 src/RatePermissions.php \Drupal\rate\RatePermissions::permissions()

Get permissions for Rate module.

Return value

array Permissions array.

1 string reference to 'RatePermissions::permissions'
rate.permissions.yml in ./rate.permissions.yml
rate.permissions.yml

File

src/RatePermissions.php, line 62

Class

RatePermissions
Class to return permissions based on entity type for rate module.

Namespace

Drupal\rate

Code

public function permissions() {
  $permissions = [];
  $enabled_types_widgets = $this->config
    ->get('enabled_types_widgets');
  if (!empty($enabled_types_widgets)) {
    foreach ($enabled_types_widgets as $entity_type_id => $entity_types) {
      foreach ($entity_types as $bundle => $settings) {
        if ($bundle == $entity_type_id) {
          $perm_index = 'cast rate vote on ' . $entity_type_id . ' of ' . $bundle;
          $permissions[$perm_index] = [
            'title' => $this
              ->t('Can vote on :type', [
              ':type' => $entity_type_id,
            ]),
          ];
        }
        else {
          $perm_index = 'cast rate vote on ' . $entity_type_id . ' of ' . $bundle;
          $permissions[$perm_index] = [
            'title' => $this
              ->t('Can vote on :type type of :bundle', [
              ':bundle' => $bundle,
              ':type' => $entity_type_id,
            ]),
          ];
        }
      }
    }
  }
  return $permissions;
}