You are here

function _photos_access_user_validate in Album Photos 8.4

Same name and namespace in other branches
  1. 8.5 photos_access/photos_access.module \_photos_access_user_validate()
  2. 7.3 photos_access/photos_access.module \_photos_access_user_validate()
  3. 6.0.x photos_access/photos_access.module \_photos_access_user_validate()

Validate user access to node.

1 call to _photos_access_user_validate()
photos_access_node_validate in photos_access/photos_access.module
D7 - Implements hook_node_validate().

File

photos_access/photos_access.module, line 416
Implementation of photos_access.module.

Code

function _photos_access_user_validate($users, $access_id, $collaborate = FALSE) {
  $user = \Drupal::currentUser();

  // @todo handle all of this on submit.
  $output = '';
  foreach ($users as $target) {
    $uid = $target['target_id'];
    if ($uid != $user
      ->id()) {
      $db = \Drupal::database();
      $access_user = $db
        ->query("SELECT id FROM {photos_access_user} WHERE id = :id AND uid = :uid AND collaborate = :collaborate", [
        ':id' => $access_id,
        ':uid' => $uid,
        ':collaborate' => $collaborate ? 1 : 0,
      ])
        ->fetchField();
      if ($access_user) {

        // @todo get name.
        $output = t('User is already on the list: @uid.', [
          '@uid' => $uid,
        ]);
      }
    }
    else {
      $output = t("You do not need to add your self to this list.");
    }
  }
  return $output;
}