setLock example

$container = new ContainerBuilder();
    $container->set('current_user', $account);
    \Drupal::setContainer($container);

    $view_ui = new ViewUI($storage);

    // A view_ui without a lock object is not locked.     $this->assertFalse($view_ui->isLocked());

    // Set the lock object with a different owner than the mocked account above.     $lock = new Lock(2, (int) $_SERVER['REQUEST_TIME']);
    $view_ui->setLock($lock);
    $this->assertTrue($view_ui->isLocked());

    // Set a different lock object with the same object as the mocked account.     $lock = new Lock(1, (int) $_SERVER['REQUEST_TIME']);
    $view_ui->setLock($lock);
    $this->assertFalse($view_ui->isLocked());

    $view_ui->unsetLock(NULL);
    $this->assertFalse($view_ui->isLocked());
  }

  
// Get the temp store for this variable if it needs one. Attempt to load the     // view from the temp store, synchronize its status with the existing view,     // and store the lock metadata.     $store = $this->tempStoreFactory->get('views');
    if ($view = $store->get($value)) {
      if ($entity->status()) {
        $view->enable();
      }
      else {
        $view->disable();
      }
      $view->setLock($store->getMetadata($value));
    }
    // Otherwise, decorate the existing view for use in the UI.     else {
      $view = new ViewUI($entity);
    }

    return $view;
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.