Same filename and directory in other branches
- 8.9.x core/modules/views_ui/src/Form/BreakLockForm.php
- 9 core/modules/views_ui/src/Form/BreakLockForm.php
Namespace
Drupal\views_ui\Form
File
core/modules/views_ui/src/Form/BreakLockForm.php
View source
<?php
namespace Drupal\views_ui\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TempStore\SharedTempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
class BreakLockForm extends EntityConfirmFormBase {
protected $entityTypeManager;
protected $tempStore;
public function __construct(EntityTypeManagerInterface $entity_type_manager, SharedTempStoreFactory $temp_store_factory) {
$this->entityTypeManager = $entity_type_manager;
$this->tempStore = $temp_store_factory
->get('views');
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'), $container
->get('tempstore.shared'));
}
public function getFormId() {
return 'views_ui_break_lock_confirm';
}
public function getQuestion() {
return $this
->t('Do you want to break the lock on view %name?', [
'%name' => $this->entity
->id(),
]);
}
public function getDescription() {
$locked = $this->tempStore
->getMetadata($this->entity
->id());
$account = $this->entityTypeManager
->getStorage('user')
->load($locked
->getOwnerId());
$username = [
'#theme' => 'username',
'#account' => $account,
];
return $this
->t('By breaking this lock, any unsaved changes made by @user will be lost.', [
'@user' => \Drupal::service('renderer')
->render($username),
]);
}
public function getCancelUrl() {
return $this->entity
->toUrl('edit-form');
}
public function getConfirmText() {
return $this
->t('Break lock');
}
public function buildForm(array $form, FormStateInterface $form_state) {
if (!$this->tempStore
->getMetadata($this->entity
->id())) {
$form['message']['#markup'] = $this
->t('There is no lock on view %name to break.', [
'%name' => $this->entity
->id(),
]);
return $form;
}
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->tempStore
->delete($this->entity
->id());
$form_state
->setRedirectUrl($this->entity
->toUrl('edit-form'));
$this
->messenger()
->addStatus($this
->t('The lock has been broken and you may now edit this view.'));
}
}
Classes