You are here

public function LdapGroupManager::groupAddGroup in Lightweight Directory Access Protocol (LDAP) 8.4

Add a group entry.

Functionality is not in use, only called by server test form.

Parameters

string $group_dn: The group DN as an LDAP DN.

array $attributes: Attributes in key value form $attributes = array( "attribute1" = "value", "attribute2" = array("value1", "value2"), )

Return value

bool Operation result.

File

ldap_servers/src/LdapGroupManager.php, line 94

Class

LdapGroupManager
LDAP Group Manager.

Namespace

Drupal\ldap_servers

Code

public function groupAddGroup(string $group_dn, array $attributes = []) : bool {
  if (!$this
    ->checkAvailability() || $this
    ->checkDnExists($group_dn)) {
    return FALSE;
  }
  $attributes = array_change_key_case($attributes, CASE_LOWER);
  if (empty($attributes['objectclass'])) {
    $objectClass = $this->server
      ->get('grp_object_cat');
  }
  else {
    $objectClass = $attributes['objectclass'];
  }
  $attributes['objectclass'] = $objectClass;
  $context = [
    'action' => 'add',
    'corresponding_drupal_data' => [
      $group_dn => $attributes,
    ],
    'corresponding_drupal_data_type' => 'group',
  ];
  $ldap_entries = [
    $group_dn => $attributes,
  ];
  $this->moduleHandler
    ->alter('ldap_entry_pre_provision', $ldap_entries, $this, $context);
  $attributes = $ldap_entries[$group_dn];
  $entry = new Entry($group_dn, $attributes);
  try {
    $this->ldap
      ->getEntryManager()
      ->add($entry);
  } catch (LdapException $e) {
    $this->logger
      ->error('LDAP server %id exception: %ldap_error', [
      '%id' => $this->server
        ->id(),
      '%ldap_error' => $e
        ->getMessage(),
    ]);
    return FALSE;
  }
  $this->moduleHandler
    ->invokeAll('ldap_entry_post_provision', [
    $ldap_entries,
    $this,
    $context,
  ]);
  return TRUE;
}