3 namespace Drupal\views_ui\Form;
5 use Drupal\Core\Entity\EntityConfirmFormBase;
6 use Drupal\Core\Entity\EntityManagerInterface;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\user\SharedTempStoreFactory;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Builds the form to break the lock of an edited view.
14 class BreakLockForm extends EntityConfirmFormBase {
17 * Stores the Entity manager.
19 * @var \Drupal\Core\Entity\EntityManagerInterface
21 protected $entityManager;
24 * Stores the user tempstore.
26 * @var \Drupal\user\SharedTempStore
31 * Constructs a \Drupal\views_ui\Form\BreakLockForm object.
33 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
35 * @param \Drupal\user\SharedTempStoreFactory $temp_store_factory
36 * The factory for the temp store object.
38 public function __construct(EntityManagerInterface $entity_manager, SharedTempStoreFactory $temp_store_factory) {
39 $this->entityManager = $entity_manager;
40 $this->tempStore = $temp_store_factory->get('views');
46 public static function create(ContainerInterface $container) {
48 $container->get('entity.manager'),
49 $container->get('user.shared_tempstore')
56 public function getFormId() {
57 return 'views_ui_break_lock_confirm';
63 public function getQuestion() {
64 return $this->t('Do you want to break the lock on view %name?', ['%name' => $this->entity->id()]);
70 public function getDescription() {
71 $locked = $this->tempStore->getMetadata($this->entity->id());
72 $account = $this->entityManager->getStorage('user')->load($locked->owner);
74 '#theme' => 'username',
75 '#account' => $account,
77 return $this->t('By breaking this lock, any unsaved changes made by @user will be lost.', ['@user' => drupal_render($username)]);
83 public function getCancelUrl() {
84 return $this->entity->urlInfo('edit-form');
90 public function getConfirmText() {
91 return $this->t('Break lock');
97 public function buildForm(array $form, FormStateInterface $form_state) {
98 if (!$this->tempStore->getMetadata($this->entity->id())) {
99 $form['message']['#markup'] = $this->t('There is no lock on view %name to break.', ['%name' => $this->entity->id()]);
102 return parent::buildForm($form, $form_state);
108 public function submitForm(array &$form, FormStateInterface $form_state) {
109 $this->tempStore->delete($this->entity->id());
110 $form_state->setRedirectUrl($this->entity->urlInfo('edit-form'));
111 drupal_set_message($this->t('The lock has been broken and you may now edit this view.'));