You are here

protected function FormModeManagerPermissions::buildFormModePermissions in Form mode manager 8

Same name and namespace in other branches
  1. 8.2 src/FormModeManagerPermissions.php \Drupal\form_mode_manager\FormModeManagerPermissions::buildFormModePermissions()

Returns a list of form modes permissions available for given entity type.

Parameters

string $entity_type_id: The entity type id.

array $form_modes: All form-modes available for specified entity_type_id.

Return value

array An associative array of permission names and descriptions.

1 call to FormModeManagerPermissions::buildFormModePermissions()
FormModeManagerPermissions::formModeManagerPermissions in src/FormModeManagerPermissions.php
Returns an array of Form mode manager permissions.

File

src/FormModeManagerPermissions.php, line 107

Class

FormModeManagerPermissions
Provides dynamic permissions of the form_mode_manager module.

Namespace

Drupal\form_mode_manager

Code

protected function buildFormModePermissions($entity_type_id, array $form_modes) {
  $perms_per_mode = [];
  $entity_placeholder = [
    '%type_id' => $entity_type_id,
  ];
  $form_modes_storage = $this->entityTypeManager
    ->getStorage('entity_form_mode');
  foreach ($form_modes as $form_mode) {
    $form_mode_loaded = $form_modes_storage
      ->loadByProperties([
      'id' => "{$entity_type_id}.{$form_mode}",
    ]);
    $form_mode_loaded = reset($form_mode_loaded);
    if ($form_mode_loaded instanceof EntityFormMode) {
      $placeholders = array_merge($entity_placeholder, [
        '%form_mode_label' => $form_mode_loaded
          ->label(),
        ':url' => $form_mode_loaded
          ->url(),
      ]);
      $perms_per_mode += [
        "use {$form_mode_loaded->id()} form mode" => [
          'title' => $this
            ->t('Use <a href=":url">%form_mode_label</a> form mode with <b>%type_id</b> entity', $placeholders),
          'description' => [
            '#prefix' => '<em>',
            '#markup' => $this
              ->t('This permission control access of <b>%type_id</b> entity with %form_mode_label form mode.', $placeholders),
            '#suffix' => '</em>',
          ],
          'restrict access' => TRUE,
        ],
      ];
    }
  }
  return $perms_per_mode;
}