You are here

public function ContentLock::isLockable 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::isLockable()

Check whether a node is configured to be protected by content_lock.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to check.

string $form_op: (optional) The entity form operation.

Return value

bool TRUE is entity is lockable

File

src/ContentLock/ContentLock.php, line 500

Class

ContentLock
Class ContentLock.

Namespace

Drupal\content_lock\ContentLock

Code

public function isLockable(EntityInterface $entity, $form_op = NULL) {
  $entity_id = $entity
    ->id();
  $entity_type = $entity
    ->getEntityTypeId();
  $bundle = $entity
    ->bundle();
  $config = $this->config
    ->get("types.{$entity_type}");
  $this->moduleHandler
    ->invokeAll('content_lock_entity_lockable', [
    $entity,
    $entity_id,
    $entity
      ->language()
      ->getId(),
    $form_op,
    $entity_type,
    $bundle,
    $config,
  ]);
  if (is_array($config) && (in_array($bundle, $config) || in_array('*', $config))) {
    if (isset($form_op) && $this
      ->isFormOperationLockEnabled($entity_type)) {
      $mode = $this->config
        ->get("form_op_lock.{$entity_type}.mode");
      $values = $this->config
        ->get("form_op_lock.{$entity_type}.values");
      if ($mode == self::FORM_OP_MODE_BLACKLIST) {
        return !in_array($form_op, $values);
      }
      elseif ($mode == self::FORM_OP_MODE_WHITELIST) {
        return in_array($form_op, $values);
      }
    }
    return TRUE;
  }

  // Always return FALSE.
  return FALSE;
}