private function removeGroupsWithoutCreateAccess(array $options, User $account, EntityInterface $entity) {

    foreach ($options as $option_category_key => $groups_in_category) {
      if (is_array($groups_in_category)) {
        foreach ($groups_in_category as $gid => $group_title) {
          if (!$this->checkGroupContentCreateAccess($gid, $account, $entity)) {
            unset($options[$option_category_key][$gid]);
          }
        }
        // Remove the entire category if there are no groups for this author.
        if (empty($options[$option_category_key])) {
          unset($options[$option_category_key]);
        }
      }
      else {
        if (!$this->checkGroupContentCreateAccess($option_category_key, $account, $entity)) {
          unset($options[$option_category_key]);
        }
      }
    }

    return $options;
  }
private function removeGroupsWithoutCreateAccess(array $options, User $account, EntityInterface $entity) {

    foreach ($options as $option_category_key => $groups_in_category) {
      if (is_array($groups_in_category)) {
        foreach ($groups_in_category as $gid => $group_title) {
          if (!$this->checkGroupContentCreateAccess($gid, $account, $entity)) {
            unset($options[$option_category_key][$gid]);
          }
        }
        // Remove the entire category if there are no groups for this author.
        if (empty($options[$option_category_key])) {
          unset($options[$option_category_key]);
        }
      }
      else {
        if (!$this->checkGroupContentCreateAccess($option_category_key, $account, $entity)) {
          unset($options[$option_category_key]);
        }
      }
    }

    return $options;
  }
private function removeGroupsWithoutCreateAccess ( array $ options , User $ account , EntityInterface $ entity ) { foreach ( $ options as $ option_category_key => $ groups_in_category ) { if ( is_array ( $ groups_in_category ) ) { foreach ( $ groups_in_category as $ gid => $ group_title ) { if ( ! $ this -> checkGroupContentCreateAccess ( $ gid , $ account , $ entity ) ) { unset ( $ options [ $ option_category_key ] [ $ gid ] ) ; } } // Remove the entire category if there are no groups for this author. if ( empty ( $ options [ $ option_category_key ] ) ) { unset ( $ options [ $ option_category_key ] ) ; } } else { if ( ! $ this -> checkGroupContentCreateAccess ( $ option_category_key , $ account , $ entity ) ) { unset ( $ options [ $ option_category_key ] ) ; } } } return $ options ; }
Remove options from the list.

@param array $options
A list of options to check.
@param \Drupal\user\Entity\User $account
The user to check for.
@param \Drupal\Core\Entity\EntityInterface $entity
The entity to check for.

@return array
An list of options for the field containing groups with create access.
Remove options from the list .