trustData example

$this->dataTableRemoval($all_views$entity_type->id()$original->getRevisionDataTable()$entity_type->getRevisionTable());
          break;
      }
    }

    foreach ($this->viewsToSave as $view) {
      try {
        // All changes done to the views here can be trusted and this might be         // called during updates, when it is not safe to rely on configuration         // containing valid schema. Trust the data and disable schema validation         // and casting.         $view->trustData()->save();
      }
      catch (\Exception $e) {
        // In case the view could not be saved, log an error message that the         // view needs to be updated manually instead of failing the entire         // entity update process.         $this->logger->critical("The %view_id view could not be updated automatically while processing an entity schema update for the %entity_type_id entity type.", [
          '%view_id' => $view->id(),
          '%entity_type_id' => $entity_type->id(),
        ]);
      }
    }
    

    $user1->save();
    $user2 = User::create([
      'name' => 'username2',
      'status' => 1,
    ]);
    $user2->save();
    $role = Role::create([
      'id' => 'role1',
      'label' => 'role1',
    ]);
    $role->grantPermission('view media')->trustData()->save();
    $user2->addRole($role->id());
    $this->assertFalse($test_media_type->access('view label', $user1));
    $this->assertTrue($test_media_type->access('view label', $user2));
  }

  /** * Tests creating a media item programmatically. */
  public function testMediaEntityCreation() {
    $media = Media::create([
      'bundle' => $this->testMediaType->id(),
      
$this->assertSame(204, $response->getStatusCode());
  }

  /** * Ensures that Drupal's page cache is effective. * * @see https://www.drupal.org/project/drupal/issues/3009596 */
  public function testPageCacheFromIssue3009596() {
    $anonymous_role = Role::load(RoleInterface::ANONYMOUS_ID);
    $anonymous_role->grantPermission('access content');
    $anonymous_role->trustData()->save();

    NodeType::create(['type' => 'emu_fact'])->save();
    \Drupal::service('router.builder')->rebuildIfNeeded();

    $node = Node::create([
      'type' => 'emu_fact',
      'title' => "Emus don't say moo!",
    ]);
    $node->save();

    $request_options = [
      
/** * {@inheritdoc} */
  public function getThirdPartyProviders() {
    return $this->storage->getThirdPartyProviders();
  }

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

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

  /** * {@inheritdoc} */


    // Test that schema type enforcement can be overridden by trusting the data.     $entity = $this->storage->create([
      'id' => $this->randomMachineName(),
      'label' => $this->randomString(),
      'style' => 999,
    ]);
    $entity->save();
    $this->assertSame('999', $entity->style);
    $entity->style = 999;
    $entity->trustData()->save();
    $this->assertSame(999, $entity->style);
    $entity->save();
    $this->assertSame('999', $entity->style);
  }

}
// Remove the corresponding plugin settings (allowing `<img data-foo>`).       unset($settings['plugins']['ckeditor5_sourceEditing']);
      $editor->setSettings($settings);
      if ($filter_html_is_enabled) {
        // Stop allowing `<img data-foo>`.         $filter_html_config = $format->filters('filter_html')
          ->getConfiguration();
        $filter_html_config['settings']['allowed_html'] = str_replace('data-foo', '', $filter_html_config['settings']['allowed_html']);
        $format->setFilterConfig('filter_html', $filter_html_config);
      }
    }
    $format->trustData()->save();
    $editor->trustData()->save();

    // Run update path; snapshot the Text Format and Editor before and after.     $editor_before = Editor::load('test_format_image');
    $filter_format_before = $editor->getFilterFormat();
    $this->runUpdates();
    $editor_after = Editor::load('test_format_image');
    $filter_format_after = $editor->getFilterFormat();

    // 1. Toolbar item: `uploadImage` -> `drupalInsertImage`, position must be     // unchanged.
$this->assertSame(201, $response->getStatusCode());
    $expected = $this->getExpectedNormalizedFileEntity();
    static::recursiveKSort($expected);
    $actual = $this->serializer->decode((string) $response->getBody()static::$format);
    static::recursiveKSort($actual);
    $this->assertSame($expected$actual);

    // To still run the complete test coverage for POSTing a Media entity, we     // must revoke the additional permissions that we granted.     $role = Role::load(static::$auth ? RoleInterface::AUTHENTICATED_ID : RoleInterface::ANONYMOUS_ID);
    $role->revokePermission('create camelids media');
    $role->trustData()->save();
  }

  /** * Gets the expected file entity. * * @return array * The expected normalized data array. */
  protected function getExpectedNormalizedFileEntity() {
    $file = File::load(3);
    $owner = static::$auth ? $this->account : User::load(0);

    

  protected function grantPermissions(RoleInterface $role, array $permissions) {
    foreach ($permissions as $permission) {
      $role->grantPermission($permission);
    }
    $role->trustData()->save();
  }

}
/** * Apply the callback an entity and save it if the callback makes changes. * * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity * The entity to potentially update. * @param callable $callback * The callback to apply. */
  protected function doOne(ConfigEntityInterface $entity, callable $callback) {
    if (call_user_func($callback$entity)) {
      $entity->trustData();
      $entity->save();
    }
  }

}
/** * Revokes permissions from the authenticated role. * * @param string[] $permissions * Permissions to revoke. */
  protected function revokePermissionsFromTestedRole(array $permissions) {
    $role = Role::load(RoleInterface::AUTHENTICATED_ID);
    foreach ($permissions as $permission) {
      $role->revokePermission($permission);
    }
    $role->trustData()->save();
  }

  /** * Asserts that a resource response has the given status code and body. * * @param int $expected_status_code * The expected response status. * @param array|null|false $expected_document * The expected document or NULL if there should not be a response body. * FALSE in case this should not be asserted. * @param \Psr\Http\Message\ResponseInterface $response * The response to assert. * @param string[]|false $expected_cache_tags * (optional) The expected cache tags in the X-Drupal-Cache-Tags response * header, or FALSE if that header should be absent. Defaults to FALSE. * @param string[]|false $expected_cache_contexts * (optional) The expected cache contexts in the X-Drupal-Cache-Contexts * response header, or FALSE if that header should be absent. Defaults to * FALSE. * @param string|false $expected_page_cache_header_value * (optional) The expected X-Drupal-Cache response header value, or FALSE if * that header should be absent. Possible strings: 'MISS', 'HIT'. Defaults * to FALSE. * @param string|false $expected_dynamic_page_cache_header_value * (optional) The expected X-Drupal-Dynamic-Cache response header value, or * FALSE if that header should be absent. Possible strings: 'MISS', 'HIT'. * Defaults to FALSE. */
$id = $entity_storage->getIDFromConfigName($name$entity_storage->getEntityType()->getConfigPrefix());
        // It is possible that secondary writes can occur during configuration         // creation. Updates of such configuration are allowed.         if ($this->getActiveStorages($collection)->exists($name)) {
          $entity = $entity_storage->load($id);
          $entity = $entity_storage->updateFromStorageRecord($entity$new_config->get());
        }
        else {
          $entity = $entity_storage->createFromStorageRecord($new_config->get());
        }
        if ($entity->isInstallable()) {
          $entity->trustData()->save();
          if ($id !== $entity->id()) {
            trigger_error(sprintf('The configuration name "%s" does not match the ID "%s"', $name$entity->id()), E_USER_WARNING);
          }
        }
      }
      else {
        $new_config->save(TRUE);
      }
    }
  }

  
Home | Imprint | This part of the site doesn't use cookies.