Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8.x 1.x config ui domain switch #294

Conversation

davidgrayston
Copy link
Contributor

#15 proof-of-concept

  • Allows switching the active domain from a "sticky" form
  • Saves configuration for the selected domain

@zerolab
Copy link
Contributor

zerolab commented Nov 29, 2016

Looks promising. A few general comments:

  • DI for the domain.negotiator service
  • Does this work with settings overrides?
  • Needs tests.

edit: removed line about moving to modules. PEBCAK

@davidgrayston
Copy link
Contributor Author

@zerolab regarding your comments:

DI for the domain.negotiator service

  • I've now done this, I hope in the correct way

Does this work with settings overrides?

  • I intentionally didn't load the settings overrides as it might be confusing when editing.
  • I'm now only re-applying the module overrides on non-immutable config so that the settings overrides will take effect when browsing the site, but config forms should still show module overrides.

Other issues:

  • I'm currently undecided if the window should reload when switching domain.
  • I think extra logic should be put in place to only apply domain module overrides on edit forms.

@agentrickard
Copy link
Owner

I merged this to the config-ui branch for testing. First note, when enabled:

 ken ] : drush en domain_config_ui
The following extensions will be enabled: domain_config_ui, domain_config
Do you really want to continue? (y/n): y
Fatal error: Arrays are not allowed in class constants in /Applications/MAMP/htdocs/drupal-8/modules/domain/domain_config_ui/src/Config/Config.php on line 20
Drush command terminated abnormally due to an unrecoverable error.                                           [error]
Error: Arrays are not allowed in class constants in
/Applications/MAMP/htdocs/drupal-8/modules/domain/domain_config_ui/src/Config/Config.php, line 20
/Applications/MAMP/htdocs/drupal-8/modules/domain

@agentrickard
Copy link
Owner

I found (or, really couldn't find) the form selector.

The bottom right is not a natural place to find this element. That's the last place a native LTR reader would look for it.

screen shot 2016-12-06 at 4 36 50 pm

Ideally, we'd be near the Save configuration button -- if not actively changing that button.

@davidgrayston
Copy link
Contributor Author

Ah, array class constants are new in PHP 7, your fix looks better

services:
domain_config_ui.manager:
class: Drupal\domain_config_ui\DomainConfigUIManager
arguments: ['@config.storage', '@domain.loader', '@language_manager']
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no longer extending the domain config overrider or negotiator. DomainConfigUIManager service will now manage the language/domain switching.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a specific code reason that made doing so necessary?

Ideally, we'd handle all of the negotiation inside the DomainConfigOverrider, or, if needed, create a DomainConfigManager service for this.

My thought here is that the UI piece should not handle any of the negotiation logic, just the form handling, so that it could be swapped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason was to keep the loading of config that's being edited as self-contained as possible.

Spoofing the requested domain for the negotiator meant that all the config on the page also got swapped. It didn't seem right to have an admin tool overriding the negotiator and change its behaviour.

I'm also not sure if we want setting overrides to be applied to editable values?

I can change this back if you think swapping all config on the page is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thoughts, I am swapping all allowed config with the manager so it might not be helping much.

I can change back to extending the negotiator as before and see what problems I encounter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it back to use the negotiator on a new branch here https://github.com/davidgrayston/domain/tree/8.x-1.x-config_ui_domain_switch_negotiator

Diff with current pull request branch: davidgrayston/domain@8.x-1.x-config_ui_domain_switch...8.x-1.x-config_ui_domain_switch_negotiator

I had to make some changes to DomainConfigOverrider to make this work:

  • Setters to allow the domain and language to be set
  • Changed protected getDomainConfigName method to be public

This doesn't seem like the correct solution in its current state

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't had a chance to really dive into this code. The part that bothers me is the introduction of config handling to the DomainNegotiator. That class/service should not really be Config aware.

I have no problem making getDomainConfigName public, but I haven't worked through the pro-con.

In general:

  • The core Domain module and its classes should handle domain registration and negotiation. That's all.
  • Domain Config should handle storage and retrieval of config overrides.
  • Domain Config UI should put a form in from of the read/write aspects of Domain Config.

Put another way, we should be able to programatically write an override through Domain Config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the saving of configuration not being tied to forms in a standardised way, and there being no definitive way of knowing which forms/pages handle config, it's quite tricky to implement this.

I don't think there's a neat way of loading the config overrides only for forms values (and admin pages), so we have to swap the config on the entire page - it's essentially swapping the domain being viewed. This is why I initially made a global domain switcher (sticky form), to make it clear that you were changing the selected domain globally.

Now that I'm altering "known" config forms, the user will not know which domain is currently selected until they go to an admin form with the switcher field. Perhaps we should go back the the domain switch implementation but make the form much more prominent (e.g. a fixed strap at the top of the page)?

It might be quicker if you take these ideas as a proof of concept and implement as you have described above?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am working on finishing other parts of the alpha/beta release, so speed isn't something I can provide.

I need to take a deeper look at what you've done and the problems you define and try to give some better direction.

Using a config_ui_manager to handle forms makes sense. I just don't want that to bleed over into handling save/load.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really tricky place, d.o core has a lot of "config override bleeding" issues fixed, also working on domain_lang module it became clear that priority of loading overrides highly coupled to language manager initialization.
Also some overrides can be done via settings.php and somehow that should affect in UI

- { name: service_collector, tag: 'config.factory.override', call: addOverride }
arguments: ['@config.storage', '@event_dispatcher', '@config.typed']
calls:
- [setDomainConfigUIManager, ['@domain_config_ui.manager']]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config UI manager is being passed to the config factory so that it can be used to load up selected domain/language configuration.

/**
* Load only overrides for selected domain and language.
*/
public function loadOverrides($names) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config UI manager loads overrides for the current selected domain/language

],
];

// Add language select field.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Language can now be selected

@@ -0,0 +1,113 @@
<?php
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've re-introduced the switch form for use on pages that aren't conventional config forms, such as the theme settings page. This form will reload the page when the domain is switched.

$cache_key = $this->getConfigCacheKey($name, $immutable);

if (isset($module_overrides[$name])) {
$this->cache[$cache_key]->setModuleOverride($module_overrides[$name]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've applied the domain overrides on immutable config so that unconventional admin pages (like theme settings) show the domain domain specific config

@davidgrayston
Copy link
Contributor Author

davidgrayston commented Dec 10, 2016

I still need to go through the known paths/forms/config that should be added to the allowed list by default.

The /admin/config/system/site-information form seems to be working fine, but the theme pages are still a bit clunky to use at the moment.

@andypost
Copy link
Contributor

Here's addition to show widget with permission only skilld-labs#1

@dmiric
Copy link

dmiric commented Feb 25, 2017

For the last few days before I saw this I was working on the solving this problem on my own. I'll try to describe my approach to this.

So what I did was:

  • Introduce a hook in config save (hook_config_alter) that accepts config name and data
  • Overridden config factory method getEditable to return overridden configuration values for the domain I'm currently on
  • And then In hook_config_alter I would simply change config that is being saved to have the name and data I wanted to save for that site

So far everything is working pretty well. I can edit all simple configuration blocks and views its really early to tell if I can achive everything I want this way but looks promising.

Of course I'm also not sure If Drupal community would accept to have that hook in config save.

What do you think about that approach?

If it was not clear enough. You basically visit the site from domain you want to change config and make changes in usual places as if you were building a normal Drupal site.

@dmiric
Copy link

dmiric commented Feb 25, 2017

I'm also thinking about making a domain template so you could inherit configuration from template and then introduce minor changes on domain it self so we don't have so many config files.

@andypost
Copy link
Contributor

@dmiric Use events instead of hooks for config, see ConfigEvents core class
BTW we using this branch on a project and we are going to add language & number of overrides to the floating block, also looks toolbar is a proper place for that

@dmiric
Copy link

dmiric commented Feb 26, 2017 via email

@andypost
Copy link
Contributor

After trial on this UI following bugs found

  • domain override always picked from session (set by floating box), probably it needs to use query string argument to pass, so UI needs to redirect to the same page but appending URL with ?domain=ID
  • edit forms always using original config, overriden config factory probably should care to load override if exists
  • language in name of override makes a lot of overrides and not using config translation

@andypost
Copy link
Contributor

One more core change in this area https://www.drupal.org/node/2930829

@agentrickard
Copy link
Owner

Hooray! That change was a long time coming.

@rivimey
Copy link
Contributor

rivimey commented Jun 7, 2018

I created a new PR for this as #426 which (apart from unrelated 8.6 issues) merges and builds successfully.

@andypost
Copy link
Contributor

andypost commented Jun 7, 2018

Actually instead of 2 PRs better to create repo like we used to hack https://github.com/skilld-labs/domain_config_ui and re-do it

Core in progress of CMI 2.0 so that may affect domain_config itself (I still looking to move domain overrides to own collections instead of prefixing)

@rivimey
Copy link
Contributor

rivimey commented Jun 11, 2018

@andypost Apologies, but I don't really understand "create repo like we used to hack...and re-do": I'm still finding my way around here.

[My intent here was only to use travis to check the patch again, given it has been a while since it was pushed. I intend to close the PR. ]

@agentrickard
Copy link
Owner

I'm going to pull https://github.com/skilld-labs/domain_config_ui into a new branch here for testing.

@davidgrayston
Copy link
Contributor Author

Happy to apply the changes to the branch on this PR if that helps?

@agentrickard
Copy link
Owner

Well, I moved things to #434 so that it would be part of the main repo. So new changes would go there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants