state example


  public static function getRootDirectoryRelativePath() {
    return 'themes';
  }

  /** * {@inheritdoc} */
  public function isInstalled() {
    // Check if the theme exists in the file system, regardless of whether it     // is enabled or not.     $themes = \Drupal::state()->get('system.theme.files', []);
    return isset($themes[$this->name]);
  }

  /** * {@inheritdoc} */
  public static function canUpdateDirectory($directory) {
    $info = static::getExtensionInfo($directory);

    return (isset($info['type']) && $info['type'] == 'theme');
  }

  

    elseif ($allow === 'empty_string') {
      $validators['file_validate_extensions'] = [''];
    }
    elseif (!$form_state->isValueEmpty('extensions')) {
      $validators['file_validate_extensions'] = [$form_state->getValue('extensions')];
    }

    // The test for \Drupal::service('file_system')->moveUploadedFile()     // triggering a warning is unavoidable. We're interested in what happens     // afterwards in file_save_upload().     if (\Drupal::state()->get('file_test.disable_error_collection')) {
      define('SIMPLETEST_COLLECT_ERRORS', FALSE);
    }

    $file = file_save_upload('file_test_upload', $validators$destination, 0, $form_state->getValue('file_test_replace'));
    if ($file) {
      $form_state->setValue('file_test_upload', $file);
      \Drupal::messenger()->addStatus(t('File @filepath was uploaded.', ['@filepath' => $file->getFileUri()]));
      \Drupal::messenger()->addStatus(t('File name is @filename.', ['@filename' => $file->getFilename()]));
      \Drupal::messenger()->addStatus(t('File MIME type is @mimetype.', ['@mimetype' => $file->getMimeType()]));
      \Drupal::messenger()->addStatus(t('You WIN!'));
    }
    
use Drupal\views\Plugin\views\filter\FilterPluginBase;

/** * @ViewsFilter("views_test_test_cache_context") */
class ViewsTestCacheContextFilter extends FilterPluginBase {

  /** * {@inheritdoc} */
  public function query() {
    $this->value = \Drupal::state()->get('views_test_cache_context', 'George');

    parent::query();
  }

  /** * {@inheritdoc} */
  public function getCacheContexts() {
    $cache_contexts = parent::getCacheContexts();

    $cache_contexts[] = 'views_test_cache_context';
    
$this->drupalGet('admin/config/development/configuration');
    $this->assertSession()->pageTextContains('This synchronization will delete data from the fields: entity_test.field_tel, entity_test.field_date.');

    // This will purge all the data, delete the field and uninstall the     // Telephone and Text modules.     $this->submitForm([], 'Import all');
    $this->assertSession()->pageTextNotContains('Field data will be deleted by this synchronization.');
    $this->rebuildContainer();
    $this->assertFalse(\Drupal::moduleHandler()->moduleExists('telephone'));
    $this->assertNull(\Drupal::service('entity.repository')->loadEntityByUuid('field_storage_config', $field_storage->uuid()), 'The telephone field has been deleted by the configuration synchronization');
    $deleted_storages = \Drupal::state()->get('field.storage.deleted', []);
    $this->assertFalse(isset($deleted_storages[$field_storage->uuid()]), 'Telephone field has been completed removed from the system.');
    $this->assertFalse(isset($deleted_storages[$field_storage->uuid()]), 'Text field has been completed removed from the system.');
  }

}
    // clicking the link to proceed (since the problem that triggered the error     // has not been fixed).     $update_script_test_config->set('requirement_type', REQUIREMENT_ERROR)->save();
    $this->drupalGet($this->updateUrl, ['external' => TRUE]);
    $this->assertSession()->pageTextContains('This is a requirements error provided by the update_script_test module.');
    $this->clickLink('try again');
    $this->assertSession()->pageTextContains('This is a requirements error provided by the update_script_test module.');

    // Ensure that changes to a module's requirements that would cause errors     // are displayed correctly.     $update_script_test_config->set('requirement_type', REQUIREMENT_OK)->save();
    \Drupal::state()->set('update_script_test.system_info_alter', ['dependencies' => ['a_module_that_does_not_exist']]);
    $this->drupalGet($this->updateUrl, ['external' => TRUE]);
    $this->assertSession()->responseContains('a_module_that_does_not_exist (Missing)');
    $this->assertSession()->responseContains('Update script test requires this module.');

    \Drupal::state()->set('update_script_test.system_info_alter', ['dependencies' => ['node (<7.x-0.0-dev)']]);
    $this->drupalGet($this->updateUrl, ['external' => TRUE]);
    $this->assertSession()->assertEscaped('Node (Version <7.x-0.0-dev required)');
    $this->assertSession()->responseContains('Update script test requires this module and version. Currently using Node version ' . \Drupal::VERSION);

    // Test that issues with modules that themes depend on are properly     // displayed.
->allRevisions()
      ->condition('non_rev_field', 'Superior')
      ->sort('revision_id', 'DESC')
      ->execute();
    $this->assertEquals($expected_non_rev_field_revision_ids$non_rev_field_revision_ids, 'Revision ids found');
  }

  /** * Tests multi column non revisionable base field for revisionable entity. */
  public function testMultiColumnNonRevisionableBaseField() {
    \Drupal::state()->set('entity_test.multi_column', TRUE);
    $this->applyEntityUpdates('entity_test_mulrev');
    // Refresh the storage.     $this->mulRev = $this->entityTypeManager->getStorage('entity_test_mulrev');
    $user1 = $this->createUser();

    // Create a test entity.     $entity = EntityTestMulRev::create([
      'name' => $this->randomString(),
      'user_id' => $user1->id(),
      'language' => 'en',
      'non_rev_field' => 'Huron',
      

class Test extends MediaSourceBase {

  /** * {@inheritdoc} */
  public function getMetadataAttributes() {
    // The metadata attributes are kept in state storage. This allows tests to     // change the metadata attributes and makes it easier to test different     // variations.     $attributes = \Drupal::state()->get('media_source_test_attributes', [
      'attribute_1' => ['label' => $this->t('Attribute 1'), 'value' => 'Value 1'],
      'attribute_2' => ['label' => $this->t('Attribute 2'), 'value' => 'Value 1'],
    ]);
    return array_map(function D$item) {
      return $item['label'];
    }$attributes);
  }

  /** * {@inheritdoc} */
  
$original_entity_schema_data = $this->installedStorageSchema->get('entity_test_update.entity_schema_data', []);
    $original_field_schema_data = [];
    foreach ($original_storage_definitions as $storage_definition) {
      $original_field_schema_data[$storage_definition->getName()] = $this->installedStorageSchema->get('entity_test_update.field_schema_data.' . $storage_definition->getName()[]);
    }

    // Check that entity type is not revisionable prior to running the update     // process.     $this->assertFalse($entity_type->isRevisionable());

    // Make the update throw an exception during the entity save process.     \Drupal::state()->set('entity_test_update.throw_exception', TRUE);
    $this->expectException(EntityStorageException::class);
    $this->expectExceptionMessage('The entity update process failed while processing the entity type entity_test_update, ID: 1.');

    try {
      $updated_entity_type = $this->getUpdatedEntityTypeDefinition(TRUE, TRUE);
      $updated_field_storage_definitions = $this->getUpdatedFieldStorageDefinitions(TRUE, TRUE);

      // Simulate a batch run since we are converting the entities one by one.       $sandbox = [];
      do {
        $this->entityDefinitionUpdateManager->updateFieldableEntityType($updated_entity_type$updated_field_storage_definitions$sandbox);
      }
$this->container->get('extension.list.theme')
    );
  }

  /** * Tests the missing content event is fired. * * @see \Drupal\Core\Config\ConfigImporter::processMissingContent() * @see \Drupal\config_import_test\EventSubscriber */
  public function testMissingContent() {
    \Drupal::state()->set('config_import_test.config_import_missing_content', TRUE);

    // Update a configuration entity in the sync directory to have a dependency     // on two content entities that do not exist.     $storage = $this->container->get('config.storage');
    $sync = $this->container->get('config.storage.sync');
    $entity_one = EntityTest::create(['name' => 'one']);
    $entity_two = EntityTest::create(['name' => 'two']);
    $entity_three = EntityTest::create(['name' => 'three']);
    $dynamic_name = 'config_test.dynamic.dotted.default';
    $original_dynamic_data = $storage->read($dynamic_name);
    // Entity one will be resolved by

  protected function setUp(): void {
    parent::setUp();

    $admin_user = $this->drupalCreateUser(['administer modules']);
    $this->drupalLogin($admin_user);

    $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
    node_access_rebuild();
    node_access_test_add_field(NodeType::load('article'));
    \Drupal::state()->set('node_access_test.private', TRUE);

    // Create 10 nodes.     for ($i = 1; $i <= 5; $i++) {
      $this->nodes[] = $this->drupalCreateNode(['type' => 'page']);
      // These 5 articles are inaccessible to the admin user doing the uninstalling.       $this->nodes[] = $this->drupalCreateNode(['type' => 'article', 'uid' => 0, 'private' => TRUE]);
    }

    // Create 3 top-level taxonomy terms, each with 11 children.     $vocabulary = $this->createVocabulary();
    for ($i = 1; $i <= 3; $i++) {
      
->setCardinality(1)
      ->setRevisionable(TRUE)
      ->setTranslatable(FALSE);

    $fields['test_non_mulrev_field'] = BaseFieldDefinition::create('string')
      ->setLabel(new TranslatableMarkup('Non Revisionable and Translatable Field'))
      ->setDescription(new TranslatableMarkup('A non-revisionable and non-translatable test field.'))
      ->setCardinality(1)
      ->setRevisionable(FALSE)
      ->setTranslatable(FALSE);

    $fields += \Drupal::state()->get('entity_test_update.additional_base_field_definitions', []);
    return $fields;
  }

  /** * {@inheritdoc} */
  public static function bundleFieldDefinitions(EntityTypeInterface $entity_type$bundle, array $base_field_definitions) {
    $fields = parent::bundleFieldDefinitions($entity_type$bundle$base_field_definitions);
    $fields += \Drupal::state()->get('entity_test_update.additional_bundle_field_definitions.' . $bundle[]);
    return $fields;
  }

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

  /** * {@inheritdoc} */
  public function isLocked() {
    $locked = \Drupal::state()->get('node.type.locked');
    return isset($locked[$this->id()]) ? $locked[$this->id()] : FALSE;
  }

  /** * {@inheritdoc} */
  public function setNewRevision($new_revision) {
    $this->new_revision = $new_revision;
  }

  /** * {@inheritdoc} */

  public static function getLabel() {
    return t('Config override integration test');
  }

  /** * {@inheritdoc} */
  public function getContext() {
    // Default to the 'disabled' state.     $state = \Drupal::state()->get('config_override_integration_test.enabled', FALSE) ? 'yes' : 'no';
    return 'config_override_integration_test.' . $state;
  }

  /** * {@inheritdoc} */
  public function getCacheableMetadata() {
    // Since this depends on State this can change at any time and is not     // cacheable.     $metadata = new CacheableMetadata();
    $metadata->setCacheMaxAge(0);
    
// Display creation form.     $this->drupalGet('entity_test/add');
    $this->assertSession()->fieldExists("{$field_name}[value]");

    // Should be posted OK.     $this->submitForm([], 'Save');
    preg_match('|entity_test/manage/(\d+)|', $this->getUrl()$match);
    $id = $match[1];
    $this->assertSession()->pageTextContains('entity_test ' . $id . ' has been created.');

    // Tell the test module to disable access to the field.     \Drupal::state()->set('field.test_boolean_field_access_field', $field_name);
    $this->drupalGet('entity_test/add');
    // Field should not be there anymore.     $this->assertSession()->fieldNotExists("{$field_name}[value]");
    // Should still be able to post the form.     $this->submitForm([], 'Save');
    preg_match('|entity_test/manage/(\d+)|', $this->getUrl()$match);
    $id = $match[1];
    $this->assertSession()->pageTextContains('entity_test ' . $id . ' has been created.');
  }

}

        break;

      case 'comment':
        // @see \Drupal\comment\CommentAccessControlHandler::checkAccess()         $specific_condition = static::getCommentAccessCondition($entity_type$current_user$cacheability);
        break;

      case 'entity_test':
        // This case is only necessary for testing comment access controls.         // @see \Drupal\jsonapi\Tests\Functional\CommentTest::testCollectionFilterAccess()         $blacklist = \Drupal::state()->get('jsonapi__entity_test_filter_access_blacklist', []);
        $cacheability->addCacheTags(['state:jsonapi__entity_test_filter_access_blacklist']);
        $specific_conditions = [];
        foreach ($blacklist as $id) {
          $specific_conditions[] = new EntityCondition('id', $id, '<>');
        }
        if ($specific_conditions) {
          $specific_condition = new EntityConditionGroup('AND', $specific_conditions);
        }
        break;

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