Problem/Motivation
The cors settings are a container parameter. We need to replace that with values from our config object BEFORE \Drupal\Core\DependencyInjection\Compiler\CorsCompilerPass
runs, because this compiler pass removes the CORS middleware if whatever is in the container at the time says it's disabled.
If we run at the start (or where the core pass is), cache bins are not available and it blows up. If it runs at the end, it's too late the service has been removed from the container by the core pass. If you place the core compiler pass at the end or remove it, something else blows up about a missing dependency (The service "http_kernel" has a dependency on a non-existent service "http_middleware.cors").
The current solution in CorsUiCompilerPass:
(new ListCacheBinsPass())->process($container);
Call the cache bin pass manually to allow you load config early.
Proposed resolution
Come up with a better way.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork cors_ui-2794109
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedWe could remove all of this and document the fact that you need to enable cors in services.yml before using the UI, but it kind of defeats the purpose.
Comment #3
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #4
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #5
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAnother option: force it on, decorate the service, do the config checking in the decorating service.
Comment #6
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAnother option: remove it from the HTTP kernel after it has been added.
Comment #7
andypostMaybe better to file core issue to move this out of compiler pass to some module?
#5 looks better (not digged too much)
Comment #8
dawehnerOrientate yourself based upon
\Drupal\language\LanguageServiceProvider::isMultilingual
which should work.Comment #11
klausiImplemented the suggestion from dawehner, thanks!
Then I can use this module on Drupal 9 and this also fixes #3196315: Drupal 9: Constructing service "validation.constraint" from a parent definition is not supported at build time
The only problem I can see now that the container is not rebuilt when the form is saved, so I had to manually call a cache rebuild.
Comment #12
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedIf you're using this and want to make changes, please do so: https://www.drupal.org/node/2794095/maintainers
Comment #14
klausiOK cool, thanks! I fixed the config_storage duplicate variable and merged this.
Changed testing to Drupal 9.1 and PHP 7.4, will check if we get a passing dev branch now and then make a 1.0 release.