Skip to content
Snippets Groups Projects

Issue #2949202: Previewing appears to unlock node

6 unresolved threads

Closes #2949202

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
65 65 }
66 66 /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
67 67 $entity = $form_state->getFormObject()->getEntity();
68
69 // We act only on edit forms, not on creation of a new entity.
70 if (empty($entity->id())) {
  • 112 // If moderation state is in use also disable corresponding buttons.
    113 if (isset($form['moderation_state'])) {
    114 $form['moderation_state']['#attributes']['class'][] = 'content-lock-actions';
    115 }
    116 return;
    117 }
    123 // Get the current request
    124 // Post come from ajax requests.
    125 $request = \Drupal::requestStack()->getCurrentRequest();
    118 126
    119 // We lock the content if it is currently edited by another user.
    120 if (!$lock_service->locking($entity->id(), $entity->language()->getId(), $form_op, $user->id(), $entity_type)) {
    121 $form['#disabled'] = TRUE;
    127 // Show locked message to the user when returning back to edit form
    128 // from preview mode.
    129 if ($form_op == 'edit' && !empty($form_state->getValues()) && !is_null($request) && $request->getMethod() !== 'POST') {
    • Triple equal signs whenever you can

      No point in using empty here, I saw another superflous empty above as well, very strange, why bother? Just use $form->getValues(). It will be coerced to boolean, no problems. The only difference between !empty($foo) and (bool) $foo is the suppression of a notice if $foo is not defined -- but that can't happen with function return values.

      OTOH !is_null should be isset() but it's also unnecessary, just use $request once again: if it's not null, it'll be an object which coerces to boolean TRUE. https://3v4l.org/aQhK7

    • Please register or sign in to reply
  • 101 'entity' => $entity->id(),
    102 'langcode' => $entity->language()->getId(),
    103 'form_op' => $form_op,
    104 ],
    105 ['query' => ['destination' => Drupal::request()->getRequestUri()]]
    106 )->toString(),
    107 ],
    108 ];
    115 $user_input = $form_state->getUserInput();
    109 116
    110 $form['actions']['#attributes']['class'][] = 'content-lock-actions';
    117 // This hook function is called twice, first when the form loads
    118 // and second when the form is submitted.
    119 // Only perform set and check for lock on initial form load.
    120 if (isset($user_input['content_locked_by_current_user']) && $user_input['content_locked_by_current_user'] == 1) {
    121 $content_locked_by_current_user = $user_input['content_locked_by_current_user'];
  • 373 398 $entity_type = $entity->getEntityTypeId();
    374 399 $route_parameters = [
    375 400 'entity' => $entity->id(),
    376 'langcode' => $lock_service->isTranslationLockEnabled($entity_type) ? $entity->language()->getId() : LanguageInterface::LANGCODE_NOT_SPECIFIED,
    401 'langcode' => $lock_service->isTranslationLockEnabled($entity_type) ? $entity->language()
  • 85 89 }
    90 }
    86 91
    87 // This hook function is called twice, first when the form loads
    88 // and second when the form is submitted.
    89 // Only perform set and check for lock on initial form load.
    90 $userInput = $form_state->getUserInput();
    91 if (!empty($userInput)) {
    92 return;
    92 if ($lock_service->isJsLock($entity_type)) {
    93 $form['#attached']['library'][] = 'content_lock/drupal.content_lock.lock_form';
    94 $form['#attached']['drupalSettings']['content_lock'] = [
    95 Html::cleanCssIdentifier($form_id) => [
    96 'lockUrl' => Url::fromRoute('content_lock.create_lock.' . $entity_type,
    97 [
    98 'entity' => $entity->id(),
  • 100 [
    101 'entity' => $entity->id(),
    102 'langcode' => $entity->language()->getId(),
    103 'form_op' => $form_op,
    104 ],
    105 ['query' => ['destination' => Drupal::request()->getRequestUri()]]
    106 )->toString(),
    107 ],
    108 ];
    115 $user_input = $form_state->getUserInput();
    109 116
    110 $form['actions']['#attributes']['class'][] = 'content-lock-actions';
    117 // This hook function is called twice, first when the form loads
    118 // and second when the form is submitted.
    119 // Only perform set and check for lock on initial form load.
    120 if (isset($user_input['content_locked_by_current_user']) && $user_input['content_locked_by_current_user'] == 1) {
    Please register or sign in to reply
    Loading