You are here

public function AccessStorage::saveTermPermissions in Permissions by Term 8

Same name and namespace in other branches
  1. 8.2 src/Service/AccessStorage.php \Drupal\permissions_by_term\Service\AccessStorage::saveTermPermissions()

*

Parameters

FormState $formState:

int $term_id: * * @return array * @throws \Exception

File

src/Service/AccessStorage.php, line 395

Class

AccessStorage
Class AccessStorage.

Namespace

Drupal\permissions_by_term\Service

Code

public function saveTermPermissions(FormStateInterface $formState, $term_id) {
  $langcode = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  if (!empty($formState
    ->getValue('langcode'))) {
    $langcode = $formState
      ->getValue('langcode')['0']['value'];
  }
  $aExistingUserPermissions = $this
    ->getUserTermPermissionsByTid($term_id, $langcode);
  $aSubmittedUserIdsGrantedAccess = $this
    ->getSubmittedUserIds($formState);
  $aExistingRoleIdsGrantedAccess = $this
    ->getRoleTermPermissionsByTid($term_id, $langcode);
  $aSubmittedRolesGrantedAccess = $this
    ->getSubmittedRolesGrantedAccess($formState);
  $aRet = $this
    ->getPreparedDataForDatabaseQueries($aExistingUserPermissions, $aSubmittedUserIdsGrantedAccess, $aExistingRoleIdsGrantedAccess, $aSubmittedRolesGrantedAccess);
  $this
    ->deleteTermPermissionsByUserIds($aRet['UserIdPermissionsToRemove'], $term_id, $langcode);
  $this
    ->addTermPermissionsByUserIds($aRet['UserIdPermissionsToAdd'], $term_id, $langcode);
  $this
    ->deleteTermPermissionsByRoleIds($aRet['UserRolePermissionsToRemove'], $term_id, $langcode);
  if (!empty($aRet['aRoleIdPermissionsToAdd'])) {
    $this
      ->addTermPermissionsByRoleIds($aRet['aRoleIdPermissionsToAdd'], $term_id, $langcode);
  }
  return $aRet;
}