Problem/Motivation
In our Drupal site, we are extending ConfigFactoryOverrideInterface and overriding the loadOverrides function to assign permissions to a user role dynamically. This functionality works as expected in Drupal version 10.2.7. However, starting from Drupal version 10.3.0, the loadOverrides method is no longer invoked after creating a new content type, which causes our dynamic permission assignment to fail.
Steps to reproduce
Implement ConfigFactoryOverrideInterface and override the loadOverrides function to assign permissions to a user role dynamically.
Create a new content type, e.g., 'test_content'.
Observe that in Drupal 10.2.7, the loadOverrides method is invoked, and permissions are assigned correctly.
Upgrade to Drupal 10.3.0 or later.
Create the same content type 'test_content'.
Observe that the loadOverrides method is not invoked, and permissions are not assigned.
Starting from Drupal 10.3.0, the loadOverrides method is not invoked after creating a new content type, causing dynamic permission assignments to fail.
Code snippets demonstrating the ConfigFactoryOverrideInterface implementation.
class PermissionOverrides implements ConfigFactoryOverrideInterface {
/**
* {@inheritdoc}
*/
public function loadOverrides($names) {
$overrides = [];
$role = 'user.role.anonymous';
if (in_array($role, $names)) {
$types = $this->entityTypeManager()->getStorage('node_type')->loadMultiple();
foreach ($types as $type) {
$permission = 'Test permission ' . $type->id();
$overrides[$role]['permissions'][$permission] = $permission;
}
}
return $overrides;
}
/**
* @return string
*/
public function getCacheSuffix() {
return static::class;
}
/**
* @param string $name
*
* @return \Drupal\Core\Cache\CacheableMetadata
*/
public function getCacheableMetadata($name) {
return new CacheableMetadata();
}
/**
* @param mixed $name
* @param string $collection
*
* @return \Drupal\Core\Config\StorableConfigBase|null
*/
public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
return NULL;
}
}
Code snippets for Content type creation.
$this->drupalCreateContentType(['type' => 'test_content', 'name' => 'test_content']);
Proposed resolution
The loadOverrides method should be invoked after creating a new content type, as it does in Drupal 10.2.7, to ensure dynamic permission assignments work correctly.