public function AccessStorage::saveTermPermissions in Permissions by Term 8.2
Same name and namespace in other branches
- 8 src/Service/AccessStorage.php \Drupal\permissions_by_term\Service\AccessStorage::saveTermPermissions()
Parameters
FormState $formState:
int $term_id:
Return value
array
Throws
\Exception
File
- src/
Service/ AccessStorage.php, line 397
Class
- AccessStorage
- Class AccessStorage.
Namespace
Drupal\permissions_by_term\ServiceCode
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;
}