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

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sam152 created an issue. See original summary.

Sam152’s picture

We 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.

Sam152’s picture

Issue summary: View changes
Sam152’s picture

Issue summary: View changes
Sam152’s picture

Another option: force it on, decorate the service, do the config checking in the decorating service.

Sam152’s picture

Another option: remove it from the HTTP kernel after it has been added.

andypost’s picture

Maybe better to file core issue to move this out of compiler pass to some module?
#5 looks better (not digged too much)

dawehner’s picture

Orientate yourself based upon \Drupal\language\LanguageServiceProvider::isMultilingual which should work.

klausi made their first commit to this issue’s fork.

klausi’s picture

Status: Active » Needs review

Implemented 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.

Sam152’s picture

If you're using this and want to make changes, please do so: https://www.drupal.org/node/2794095/maintainers

  • klausi committed 9293a66 on 8.x-1.x
    Issue #2794109 by klausi, Sam152, dawehner: Find a way to replace the...
klausi’s picture

Status: Needs review » Fixed

OK 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.