getDependencies example

'workflow_third_party_settings_test',
  ];

  /** * Tests \Drupal\workflows\Entity\Workflow::onDependencyRemoval(). */
  public function testOnDependencyRemoval() {
    // Create a workflow that has a dependency on a third party setting.     $workflow = Workflow::create(['id' => 'test3', 'type' => 'workflow_type_complex_test']);
    $workflow->setThirdPartySetting('workflow_third_party_settings_test', 'key', 'value');
    $workflow->save();
    $this->assertSame(['workflow_third_party_settings_test', 'workflow_type_test']$workflow->getDependencies()['module']);

    // Uninstall workflow_third_party_settings_test to ensure     // \Drupal\workflows\Entity\Workflow::onDependencyRemoval() works as     // expected.     \Drupal::service('module_installer')->uninstall(['node', 'workflow_third_party_settings_test']);
    /** @var \Drupal\workflows\WorkflowInterface $workflow */
    $workflow = \Drupal::entityTypeManager()->getStorage('workflow')->loadUnchanged($workflow->id());
    $this->assertSame(['workflow_type_test']$workflow->getDependencies()['module']);
  }

}
$entity = EntityTestMulChanged::create(['name' => 'test']);
    $entity->save();
    $saved_time = $entity->getChangedTime();

    $action = Action::create([
      'id' => 'entity_save_action',
      'plugin' => 'entity:save_action:entity_test_mul_changed',
    ]);
    $action->save();
    $action->execute([$entity]);
    $this->assertNotSame($saved_time$entity->getChangedTime());
    $this->assertSame(['module' => ['entity_test']]$action->getDependencies());
  }

}

  public function testSystemMenuBlockConfigDependencies() {

    $block = Block::create([
      'plugin' => 'system_menu_block:' . $this->menu->id(),
      'region' => 'footer',
      'id' => 'machinename',
      'theme' => 'stark',
    ]);

    $dependencies = $block->calculateDependencies()->getDependencies();
    $expected = [
      'config' => [
        'system.menu.' . $this->menu->id(),
      ],
      'module' => [
        'system',
      ],
      'theme' => [
        'stark',
      ],
    ];
    
$entity = EntityTestMulRevPub::create(['name' => 'test']);
    $entity->setUnpublished()->save();

    $action = Action::create([
      'id' => 'entity_publish_action',
      'plugin' => 'entity:publish_action:entity_test_mulrevpub',
    ]);
    $action->save();
    $this->assertFalse($entity->isPublished());
    $action->execute([$entity]);
    $this->assertTrue($entity->isPublished());
    $this->assertSame(['module' => ['entity_test']]$action->getDependencies());
  }

  /** * @covers \Drupal\Core\Action\Plugin\Action\UnpublishAction::execute */
  public function testUnpublishAction() {
    $entity = EntityTestMulRevPub::create(['name' => 'test']);
    $entity->setPublished()->save();

    $action = Action::create([
      'id' => 'entity_unpublish_action',
      
'supported_auth' => ['cookie'],
          'supported_formats' => ['json'],
        ],
        'POST' => [
          'supported_auth' => ['basic_auth'],
          'supported_formats' => ['json'],
        ],
      ],
    ]);

    $rest_config->calculateDependencies();
    $this->assertEquals(['module' => ['basic_auth', 'entity_test', 'serialization', 'user']]$rest_config->getDependencies());
  }

}
'id' => 'bar',
      'field' => 'bar',
      'plugin_id' => 'field',
      'table' => 'entity_test__bar',
      'entity_type' => 'entity_test',
      'entity_field' => 'bar',
      'type' => 'image',
      'settings' => ['image_style' => 'foo', 'image_link' => ''],
    ];
    $view->save();

    $dependencies = $view->getDependencies() + ['config' => []];

    // Checks that style 'foo' is a dependency of view 'entity_test_fields'.     $this->assertContains('image.style.foo', $dependencies['config']);

    // Delete the 'foo' image style.     $style->delete();

    $view = View::load('entity_test_fields');

    // Checks that the view has not been deleted too.     $this->assertNotNull(View::load('entity_test_fields'));

    
/** * {@inheritdoc} */
  public function validate(mixed $entity, Constraint $constraint) {
    assert($constraint instanceof RequiredConfigDependenciesConstraint);

    // Only config entities can have config dependencies.     if (!$entity instanceof ConfigEntityInterface) {
      throw new UnexpectedTypeException($entity, ConfigEntityInterface::class);
    }

    $config_dependencies = $entity->getDependencies()['config'] ?? [];

    foreach ($constraint->entityTypes as $entity_type_id) {
      $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);

      if (!$entity_type instanceof ConfigEntityTypeInterface) {
        throw new LogicException("'$entity_type_id' is not a config entity type.");
      }

      // Ensure the current entity type's config prefix is found in the config       // dependencies of the entity being validated.       $pattern = sprintf('/^%s\\.\\w+/', $entity_type->getConfigPrefix());
      
'taxonomy.vocabulary.tags',
      ],
      'content' => [
        'taxonomy_term:tags:' . Term::load(2)->uuid(),
      ],
      'module' => [
        'node',
        'taxonomy',
        'user',
      ],
    ];
    $this->assertSame($expected$view->calculateDependencies()->getDependencies());
  }

  /** * Tests exposed taxonomy filters. */
  public function testExposedFilter() {
    $node_type = $this->drupalCreateContentType(['type' => 'page']);

    // Create the tag field itself.     $field_name = 'taxonomy_tags';
    $this->createEntityReferenceField('node', $node_type->id()$field_name, NULL, 'taxonomy_term');

    
$graph = [];
      foreach ($this->data as $entity) {
        $graph_key = $entity->getConfigDependencyName();
        if (!isset($graph[$graph_key])) {
          $graph[$graph_key] = [
            'edges' => [],
            'name' => $graph_key,
          ];
        }
        // Include all dependencies in the graph so that topographical sorting         // works.         foreach (array_merge($entity->getDependencies('config')$entity->getDependencies('module')$entity->getDependencies('theme')) as $dependency) {
          $graph[$dependency]['edges'][$graph_key] = TRUE;
          $graph[$dependency]['name'] = $dependency;
        }
      }
      // Ensure that order of the graph is consistent.       krsort($graph);
      $graph_object = new Graph($graph);
      $this->graph = $graph_object->searchAndSort();
    }
    return $this->graph;
  }

  
$this->fieldStorage->expects($this->once())
      ->method('getConfigDependencyName')
      ->willReturn('field.storage.test_entity_type.test_field');

    $field = new FieldConfig([
      'field_name' => $this->fieldStorage->getName(),
      'entity_type' => 'test_entity_type',
      'bundle' => 'test_bundle',
      'field_type' => 'test_field',
    ]$this->entityTypeId);
    $dependencies = $field->calculateDependencies()->getDependencies();
    $this->assertContains('field.storage.test_entity_type.test_field', $dependencies['config']);
    $this->assertContains('test.test_entity_type.id', $dependencies['config']);
    $this->assertEquals(['test_module', 'test_module2', 'test_module3']$dependencies['module']);
  }

  /** * Tests that invalid bundles are handled. */
  public function testCalculateDependenciesIncorrectBundle() {
    $storage = $this->createMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface');
    $storage->expects($this->any())
      
public function testViewsHandlerRelationshipNodeTermData() {
    $view = Views::getView('test_taxonomy_node_term_data');
    // Tests \Drupal\taxonomy\Plugin\views\relationship\NodeTermData::calculateDependencies().     $expected = [
      'config' => ['core.entity_view_mode.node.teaser'],
      'module' => [
        'node',
        'taxonomy',
        'user',
      ],
    ];
    $this->assertSame($expected$view->getDependencies());
    $this->executeView($view[$this->term1->id()$this->term2->id()]);
    $expected_result = [
      [
        'nid' => $this->nodes[1]->id(),
      ],
      [
        'nid' => $this->nodes[0]->id(),
      ],
    ];
    $column_map = ['nid' => 'nid'];
    $this->assertIdenticalResultset($view$expected_result$column_map);

    
return $this->cacheDir.'/'.hash('xxh128', $logicalPath.':'.$sourcePath).'.php';
    }

    /** * @return ResourceInterface[] */
    private function collectResourcesFromAsset(MappedAsset $mappedAsset): array
    {
        $resources = array_map(fn (string $path) => is_dir($path) ? new DirectoryResource($path) : new FileResource($path)$mappedAsset->getFileDependencies());
        $resources[] = new FileResource($mappedAsset->sourcePath);

        foreach ($mappedAsset->getDependencies() as $dependency) {
            if (!$dependency->isContentDependency) {
                continue;
            }

            $resources = array_merge($resources$this->collectResourcesFromAsset($dependency->asset));
        }

        return $resources;
    }
}
/** * Tests that role filter dependencies are calculated correctly. */
  public function testDependencies() {
    $role = Role::create(['id' => 'test_user_role', 'label' => 'Test user role']);
    $role->save();
    $view = View::load('test_user_name');
    $expected = [
      'module' => ['user'],
    ];
    $this->assertEquals($expected$view->getDependencies());

    $display = &$view->getDisplay('default');
    $display['display_options']['filters']['roles_target_id'] = [
      'id' => 'roles_target_id',
      'table' => 'user__roles',
      'field' => 'roles_target_id',
      'value' => ['test_user_role' => 'test_user_role'],
      'plugin_id' => 'user_roles',
    ];
    $view->save();
    $expected['config'][] = 'user.role.test_user_role';
    
    $sandbox = [];
    $settings = Settings::getInstance() ? Settings::getAll() : [];
    $settings['entity_update_batch_size'] = 9;
    new Settings($settings);
    $updater = $this->container->get('class_resolver')->getInstanceFromDefinition(ConfigEntityUpdater::class);
    // Cause a dependency to be added during an update.     \Drupal::state()->set('config_test_new_dependency', 'added_dependency');

    // This should run against the first 10 entities.     $updater->update($sandbox, 'config_test');
    $entities = $storage->loadMultiple();
    $this->assertEquals(['added_dependency']$entities['config_test_7']->getDependencies()['module']);
    $this->assertEquals(['added_dependency']$entities['config_test_8']->getDependencies()['module']);
    $this->assertEquals([]$entities['config_test_9']->getDependencies());
    $this->assertEquals([]$entities['config_test_14']->getDependencies());
    $this->assertEquals(15, $sandbox['config_entity_updater']['count']);
    $this->assertCount(6, $sandbox['config_entity_updater']['entities']);
    $this->assertEquals(9 / 15, $sandbox['#finished']);

    // Update the rest.     $updater->update($sandbox, 'config_test');
    $entities = $storage->loadMultiple();
    $this->assertEquals(['added_dependency']$entities['config_test_9']->getDependencies()['module']);
    
$this->assertEquals($entity_3->uuid()reset($config_entities['unchanged'])->uuid(), 'Entity 3 is not changed.');
    $this->assertEquals($entity_4->uuid()$config_entities['delete'][0]->uuid(), 'Entity 4 will be deleted.');
    $this->assertEquals($entity_5->uuid()$config_entities['update'][1]->uuid(), 'Entity 5 is updated.');

    // Perform the uninstall.     $config_manager->uninstall('module', 'node');

    // Test that expected actions have been performed.     $this->assertNull($storage->load($entity_1->id()), 'Entity 1 deleted');
    $entity_2 = $storage->load($entity_2->id());
    $this->assertNotEmpty($entity_2, 'Entity 2 not deleted');
    $this->assertEquals([]$entity_2->calculateDependencies()->getDependencies()['config'], 'Entity 2 dependencies updated to remove dependency on entity 1.');
    $entity_3 = $storage->load($entity_3->id());
    $this->assertNotEmpty($entity_3, 'Entity 3 not deleted');
    $this->assertEquals([$entity_2->getConfigDependencyName()]$entity_3->calculateDependencies()->getDependencies()['config'], 'Entity 3 still depends on entity 2.');
    $this->assertNull($storage->load($entity_4->id()), 'Entity 4 deleted');
  }

  /** * @covers ::uninstall * @covers ::getConfigEntitiesToChangeOnDependencyRemoval */
  public function testConfigEntityUninstallThirdParty() {
    
Home | Imprint | This part of the site doesn't use cookies.