You are here

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

Builds a button class, link type form element to unlock the content.

Parameters

string $entity_type: The entity type of the content.

int $entity_id: The entity id of the content.

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

string $form_op: The entity form operation.

string $destination: The destination query parameter to build the link with.

Return value

array The link form element.

File

src/ContentLock/ContentLock.php, line 565

Class

ContentLock
Class ContentLock.

Namespace

Drupal\content_lock\ContentLock

Code

public function unlockButton($entity_type, $entity_id, $langcode, $form_op, $destination) {
  $unlock_url_options = [];
  if ($destination) {
    $unlock_url_options['query'] = [
      'destination' => $destination,
    ];
  }
  $route_parameters = [
    'entity' => $entity_id,
    'langcode' => $this
      ->isTranslationLockEnabled($entity_type) ? $langcode : LanguageInterface::LANGCODE_NOT_SPECIFIED,
    'form_op' => $this
      ->isFormOperationLockEnabled($entity_type) ? $form_op : '*',
  ];
  return [
    '#type' => 'link',
    '#title' => $this
      ->t('Unlock'),
    '#access' => TRUE,
    '#attributes' => [
      'class' => [
        'button',
      ],
    ],
    '#url' => Url::fromRoute('content_lock.break_lock.' . $entity_type, $route_parameters, $unlock_url_options),
    '#weight' => 99,
  ];
}