You are here

public function ContentLock::isLockedBy in Content locking (anti-concurrent editing) 8.2

Same name and namespace in other branches
  1. 8 src/ContentLock/ContentLock.php \Drupal\content_lock\ContentLock\ContentLock::isLockedBy()

Check lock status.

Parameters

int $entity_id: The entity id.

string $langcode: The translation language code of the entity.

string $form_op: The entity form operation.

int $uid: The user id.

string $entity_type: The entity type.

Return value

bool Return TRUE OR FALSE.

File

src/ContentLock/ContentLock.php, line 225

Class

ContentLock
Class ContentLock.

Namespace

Drupal\content_lock\ContentLock

Code

public function isLockedBy($entity_id, $langcode, $form_op, $uid, $entity_type = 'node') {
  if (!$this
    ->isTranslationLockEnabled($entity_type)) {
    $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED;
  }
  if (!$this
    ->isFormOperationLockEnabled($entity_type)) {
    $form_op = '*';
  }

  /** @var \Drupal\Core\Database\Query\SelectInterface $query */
  $query = $this->database
    ->select('content_lock', 'c')
    ->fields('c')
    ->condition('entity_id', $entity_id)
    ->condition('uid', $uid)
    ->condition('entity_type', $entity_type)
    ->condition('langcode', $langcode)
    ->condition('form_op', $form_op);
  $num_rows = $query
    ->countQuery()
    ->execute()
    ->fetchField();
  return (bool) $num_rows;
}