status example


  public function access($displays = NULL, $account = NULL) {
    // No one should have access to disabled views.     if (!$this->storage->status()) {
      return FALSE;
    }

    if (!isset($this->current_display)) {
      $this->initDisplay();
    }

    if (!$account) {
      $account = $this->user;
    }

    

  protected function configureEntityFormDisplay(string $field_name, array $widget_settings = []) {
    // For a new field, only $mode = 'default' should be set. Use the     // preconfigured or default widget and settings. The field will not appear     // in other form modes until it is explicitly configured.     foreach ($widget_settings as $mode => $options) {
      $form_display = $this->entityDisplayRepository->getFormDisplay($this->entityTypeId, $this->bundle, $mode);
      if ($form_display->status()) {
        $form_display->setComponent($field_name$options)->save();
      }
    }

    if (empty($widget_settings)) {
      $this->entityDisplayRepository->getFormDisplay($this->entityTypeId, $this->bundle, 'default')
        ->setComponent($field_name[])
        ->save();
    }
  }

  
/** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);

    // @todo Remove if views implements a view_builder controller.     views_invalidate_cache();
    $this->invalidateCaches();

    // Rebuild the router if this is a new view, or its status changed.     if (!isset($this->original) || ($this->status() != $this->original->status())) {
      \Drupal::service('router.builder')->setRebuildNeeded();
    }
  }

  /** * {@inheritdoc} */
  public static function postLoad(EntityStorageInterface $storage, array &$entities) {
    parent::postLoad($storage$entities);
    foreach ($entities as $entity) {
      $entity->mergeDefaultDisplaysOptions();
    }

  public function convert($value$definition$name, array $defaults) {
    if (!$entity = parent::convert($value$definition$name$defaults)) {
      return;
    }

    // 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);
    }

    
    // disabled.     $views = $entity_storage->loadMultiple();

    // Ensure that all test views still exists after the deletion of the     // entity type.     $this->assertTrue(isset($views['test_view_entity_test']));
    $this->assertTrue(isset($views['test_view_entity_test_revision']));
    $this->assertTrue(isset($views['test_view_entity_test_data']));
    $this->assertTrue(isset($views['test_view_entity_test_additional_base_field']));

    // Ensure that they are all disabled.     $this->assertFalse($views['test_view_entity_test']->status());
    $this->assertFalse($views['test_view_entity_test_revision']->status());
    $this->assertFalse($views['test_view_entity_test_data']->status());
    $this->assertFalse($views['test_view_entity_test_additional_base_field']->status());
  }

  /** * Tests that renaming base tables adapts the views. */
  public function testBaseTableRename() {
    $this->renameBaseTable();
    $this->applyEntityUpdates('entity_test_update');

    
/** @var Slim $app */
$app = $container->get('app');

$app->hook('slim.before.dispatch', function D) use ($app$container) {
    $baseUrl = CommonUtils::getBaseUrl($app);

    $lang = null;
    if (!UPDATE_IS_MANUAL) {
        if (!is_file(UPDATE_META_FILE)) {
            $shopPath = str_replace('/recovery/update', '/', $app->request()->getRootUri());
            $app->response()->redirect($shopPath);
            $app->response()->status(302);
            $app->stop();
        }

        $file = file_get_contents(UPDATE_META_FILE);
        $updateConfig = json_decode($file, true);
        $container->setParameter('update.config', $updateConfig);
        $lang = substr($updateConfig['locale'], 0, 2);
    }

    session_set_cookie_params(7200, $baseUrl);

    
$block2 = $this->placeBlock('system_powered_by_block');
    $block2->disable()->save();
    // Use the config API directly to bypass Block::preSave().     \Drupal::configFactory()->getEditable('block.block.' . $block1->id())->set('region', 'INVALID')->save();
    \Drupal::configFactory()->getEditable('block.block.' . $block2->id())->set('region', 'INVALID')->save();

    // Reload block entities.     $block1 = Block::load($block1->id());
    $block2 = Block::load($block2->id());

    $this->assertSame('INVALID', $block1->getRegion());
    $this->assertTrue($block1->status());
    $this->assertSame('INVALID', $block2->getRegion());
    $this->assertFalse($block2->status());

    block_rebuild();

    // Reload block entities.     $block1 = Block::load($block1->id());
    $block2 = Block::load($block2->id());

    $messages = \Drupal::messenger()->all();
    \Drupal::messenger()->deleteAll();
    
protected function checkAccess(EntityInterface $entity$operation, AccountInterface $account) {
    /** @var \Drupal\search\SearchPageInterface $entity */
    if (in_array($operation['delete', 'disable'])) {
      if ($entity->isDefaultSearch()) {
        return AccessResult::forbidden()->addCacheableDependency($entity);
      }
      else {
        return parent::checkAccess($entity$operation$account)->addCacheableDependency($entity);
      }
    }
    if ($operation == 'view') {
      if (!$entity->status()) {
        return AccessResult::forbidden()->addCacheableDependency($entity);
      }
      $plugin = $entity->getPlugin();
      if ($plugin instanceof AccessibleInterface) {
        return $plugin->access($operation$account, TRUE)->addCacheableDependency($entity);
      }
      return AccessResult::allowed()->addCacheableDependency($entity);
    }
    return parent::checkAccess($entity$operation$account);
  }

}
/** * {@inheritdoc} */
  protected function checkAccess(EntityInterface $entity$operation, AccountInterface $account) {
    /** @var \Drupal\block\BlockInterface $entity */
    if ($operation != 'view') {
      return parent::checkAccess($entity$operation$account);
    }

    // Don't grant access to disabled blocks.     if (!$entity->status()) {
      return AccessResult::forbidden()->addCacheableDependency($entity);
    }
    else {
      $conditions = [];
      $missing_context = FALSE;
      $missing_value = FALSE;
      foreach ($entity->getVisibilityConditions() as $condition_id => $condition) {
        if ($condition instanceof ContextAwarePluginInterface) {
          try {
            $contexts = $this->contextRepository->getRuntimeContexts(array_values($condition->getContextMapping()));
            $this->contextHandler->applyContextMapping($condition$contexts);
          }
$type_name2 = $type2->id();

    // Add a field to the second node type.     $bundle_path2 = 'admin/structure/types/manage/' . $type_name2;
    $this->fieldUIAddExistingField($bundle_path2$field_name$field_label);

    \Drupal::service('module_installer')->install(['views']);
    ViewTestData::createTestViews(static::class['field_test_views']);

    $view = View::load('test_view_field_delete');
    $this->assertNotNull($view);
    $this->assertTrue($view->status());
    // Test that the View depends on the field.     $dependencies = $view->getDependencies() + ['config' => []];
    $this->assertContains("field.storage.node.$field_name", $dependencies['config']);

    // Check the config dependencies of the first field, the field storage must     // not be shown as being deleted yet.     $this->drupalGet("$bundle_path1/fields/node.$type_name1.$field_name/delete");
    $this->assertSession()->pageTextNotContains('The listed configuration will be deleted.');
    $this->assertSession()->elementNotExists('xpath', '//ul[@data-drupal-selector="edit-view"]');
    $this->assertSession()->pageTextNotContains('test_view_field_delete');

    
    $this->assertNull($temp_store->getMetadata('test_view'), 'The view is not locked.');

    $this->drupalGet('admin/structure/views/view/test_view/edit');
    // Make sure we have 'changes' to the view.     $this->drupalGet('admin/structure/views/nojs/display/test_view/default/title');
    $this->submitForm([], 'Apply');
    $this->assertSession()->pageTextContains('You have unsaved changes.');
    $this->assertEquals($views_admin_user_uid$temp_store->getMetadata('test_view')->getOwnerId(), 'View cache has been saved.');

    $view_cache = $temp_store->get('test_view');
    // The view should be enabled.     $this->assertTrue($view_cache->status(), 'The view is enabled.');
    // The view should now be locked.     $this->assertEquals($views_admin_user_uid$temp_store->getMetadata('test_view')->getOwnerId(), 'The view is locked.');

    // Cancel the view edit and make sure the cache is deleted.     $this->submitForm([], 'Cancel');
    $this->assertNull($temp_store->getMetadata('test_view'), 'Shared tempstore data has been removed.');
    // Test we are redirected to the view listing page.     $this->assertSession()->addressEquals('admin/structure/views');

    // Log in with another user and make sure the view is locked and break.     $this->drupalGet('admin/structure/views/nojs/display/test_view/default/title');
    
/** * {@inheritdoc} */
  public function disable() {
    return $this->storage->disable();
  }

  /** * {@inheritdoc} */
  public function status() {
    return $this->storage->status();
  }

  /** * {@inheritdoc} */
  public function getOriginalId() {
    return $this->storage->getOriginalId();
  }

  /** * {@inheritdoc} */

    }
    $this->assertEquals($expected_opt_groups, Views::getViewsAsOptions(FALSE, 'all', NULL, TRUE), 'Expected option array for an option group returned.');
  }

  /** * Tests view enable and disable procedural wrapper functions. */
  public function testStatusFunctions() {
    $view = Views::getView('test_view_status')->storage;

    $this->assertFalse($view->status(), 'The view status is disabled.');

    views_enable_view($view);
    $this->assertTrue($view->status(), 'A view has been enabled.');
    $this->assertEquals(views_view_is_enabled($view)$view->status(), 'views_view_is_enabled is correct.');

    views_disable_view($view);
    $this->assertFalse($view->status(), 'A view has been disabled.');
    $this->assertEquals(views_view_is_disabled($view), !$view->status(), 'views_view_is_disabled is correct.');
  }

  /** * Tests the \Drupal\views\Views::fetchPluginNames() method. */
/** * Tests the loading of blocks. */
  protected function loadTests() {
    $entity = $this->controller->load('test_block');

    $this->assertInstanceOf(Block::class$entity);

    // Verify several properties of the block.     $this->assertSame('content', $entity->getRegion());
    $this->assertTrue($entity->status());
    $this->assertEquals('stark', $entity->getTheme());
    $this->assertNotEmpty($entity->uuid());
  }

  /** * Tests the deleting of blocks. */
  protected function deleteTests() {
    $entity = $this->controller->load('test_block');

    // Ensure that the storage isn't currently empty.
throw new RuntimeException('Filesytems does not seem to match');
        }
    }

    /** * @param int $code * @param array $data */
    private function toJson($code$data)
    {
        $this->response->header('Content-Type', 'application/json');
        $this->response->status($code);

        if (\defined('JSON_PRETTY_PRINT')) {
            $this->response->body(json_encode($data, JSON_PRETTY_PRINT));
        } else {
            $this->response->body(json_encode($data));
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.