I'm working on porting Browsersync to Drupal 8, and also willing to help maintain the module. I will post patches here for the time being, please let me know if you'd like a co-maintainer. Note that it would be at least partially sponsored by my employer so I would want to add my employer as a Supporting Organization on the project page via the built-in mechanism there.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Cottser created an issue. See original summary.

star-szr’s picture

Issue summary: View changes

Issue summary update.

jorgegc’s picture

Hi @Cottser,

Porting the module to D8 is definitely on the roadmap, it just so happens that it isn't on the module's page :-) I am definitely keen on the idea and I don't see a problem in giving credits to your employer for your work. Ping me on IRC and we will chat about it a bit more.

Thanks!

star-szr’s picture

Pinged :) timezones are hard. I probably won't be online tonight (roughly 12 hours from now) and will be travelling a good chunk of tomorrow.

jorgegc’s picture

They are hard, indeed "Cottser commented about 12 hours ago" :-) I am sure we will find some time though.

star-szr’s picture

Status: Active » Needs review
FileSize
4.37 KB

I realized I said I'd post patches and I haven't posted a patch yet, and people have been pinging me about this.

Here's a very minimal port (no settings support, it's either on or off, I commented out things to be addressed later). Patch is against 7.x-1.x-dev (7.x-1.1).

Status: Needs review » Needs work

The last submitted patch, 6: port_to_drupal_8-2596637-6.patch, failed testing.

jorgegc’s picture

No worries @Cottser, I will review it as soon as I can. I should probably create a 8.x-1.x branch to avoid any problems.

askibinski’s picture

FileSize
13.94 KB

Patch works great, although I had to rename the *.tpl.php file manually to *.html.twig and also the 'theme' folder into 'templates'.
Also cleaned up some D7 files.

Attached is the complete module with these changes based on the patch by Cottser, would be great to see a Drupal 8 branch :)

star-szr’s picture

The patch does all those things, for the record :) thanks and glad it works for you.

jorgegc’s picture

Hi @Cottser, patch looks good thanks. I can confirm it embeds the snippet and it also renames the template file and the folder it lives in. I have created a 8.x-1.x branch off the current 7.x-1.x (7.x-1.1).

Hey @askibinski, thanks for the zip file but Cottser has volunteered to work on this issue (see it assigned to him) and ideally we would like to work with .patch files as they are easier to apply to the development branch the test. At the moment we probably need people to test the module and give us feedback. If you wanted to help that would be great :-)

askibinski’s picture

Yes I know, applying the patch in phpstorm/git did the trick. Apparently the old method using patch command without a git repo doesn't perform the rename/remove actions.

Anyway, patch applies cleanly and works for me. Will report if I find any issues with it.

star-szr’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev

@jorgegc thanks for creating the branch, looks like I missed your IRC ping by a few hours :( timezones--

I'm looking at porting the settings and permissions now.

star-szr’s picture

Work in progress (obeys permissions and integrates with theme settings forms), not sure how correct the CMI stuff is but it seems to work :)

star-szr’s picture

One thing I think is technically available again (in addition to the UI) is setting these values via a settings.php/settings.local.php file but still need to test it.

jorgegc’s picture

I honestly don't know how to test the settings override in settings.php/settings.local.php so if you could shed some light that would be awesome. I have tested the permissions and settings forms and they seem to work fine, great work. I've got one tiny comment about the code though:

  • You have replaced hook_page_build with hook_page_bottom but forgot to update the phpdoc :-)

What are you planning on tackling next? Tests?

star-szr’s picture

Status: Needs work » Needs review
FileSize
8.63 KB
3.53 KB

Good catch @jorgegc :) fixed that and a couple other things here. It looks like as soon as you add fields to the theme settings form they are saved with the theme settings whether you like it or not so the whole third_party_settings thing seems unnecessary and redundant at this point, removed.

Yes, tests are up next for sure, I think that's the only thing left.

In the meantime here's the syntax to test the settings.php overrides. We're not doing anything special to get this, just a built-in CMI feature:

# Enable Browsersync globally (themes can still override this so it's not really a global 'ON' switch).
$config['system.theme.global']['browsersync_enabled'] = TRUE;

# Enable Browsersync for a specific theme.
$config['bartik.settings']['browsersync_enabled'] = TRUE;

# Override port number for a specific theme.
$config['bartik.settings']['browsersync_port'] = 3002;

# Override host globally.
$config['bartik.settings']['browsersync_host'] = 'localhost';
star-szr’s picture

Oh and there's probably no better time to convert to short array syntax!

star-szr’s picture

And also it dawned on me that hook_form_system_theme_settings_alter() is technically only for themes although it emulates a hook_form_FORM_ID_alter(). See color_form_system_theme_settings_alter() and #943212: hook_form_system_theme_settings_alter() vs. THEME_form_system_theme_settings_alter() name-clash.

jorgegc’s picture

Hi @Cottser, I tested the overrides and I can confirm this feature is available again. Also, I noticed that you fixed the PHP warnings, cheers for that.

The short array syntax is very welcome, nice one! Oh and thanks for the heads up, I wasn't aware of that issue. Following it now!

Please keep the patches coming, I am looking forward to seeing this module ported.

jorgegc’s picture

Status: Needs review » Needs work

Forgot to change the status. Let's tackle tests next.

star-szr’s picture

Status: Needs work » Needs review
FileSize
13.88 KB
5.11 KB

Short version: Config schema added back, D7 test ported. I added one more basic assertion and this could be expanded later to add more tests (like for the UI and other settings).

Didn't expect this but I think that the test is showing that we need to have a config schema after all. I think there is actually a core issue because of this. The theme settings form shouldn't just save everything that's added to its form, otherwise the theme settings config schema will end up incomplete/mismatched. I'll try to find an issue for that or create one.

Without adding back the config schema when you try to save the config in the test:

    // Enable Browsersync globally.
    \Drupal::configFactory()->getEditable('system.theme.global')
      ->set('browsersync_enabled', TRUE)
      ->save();

You get this:

Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for system.theme.global with the following errors: system.theme.global:browsersync_enabled missing schema in Drupal\Core\Config\Testing\ConfigSchemaChecker->onConfigSave()

@jorgegc I didn't see any PHP warnings before so if this reintroduces them please paste them in here. I think I have all the error reporting cranked up but could be something I was doing differently too :)

star-szr’s picture

star-szr’s picture

Oops :)

jorgegc’s picture

Sorry @Cottser it has been a crazy week and I haven't had time to have a look at the latest patches. Please bear with me, I will try and find some time this week.

star-szr’s picture

@jorgegc no worries it happens! Thanks for the update.

star-szr’s picture

By the way this is how to do the settings.php overrides with the latest code:

# Enable Browsersync globally (themes can still override this so it's not really a global 'ON' switch).
$config['system.theme.global']['third_party_settings']['browsersync']['enabled'] = TRUE;

# Enable Browsersync for a specific theme (Bartik for these examples).
$config['bartik.settings']['third_party_settings']['browsersync']['enabled'] = TRUE;

# Override port number for a specific theme.
$config['bartik.settings']['third_party_settings']['browsersync']['port'] = 3002;

# Override host globally.
$config['bartik.settings']['third_party_settings']['browsersync']['host'] = 'localhost';
star-szr’s picture

You can also enable Browsersync for all users, very cool :) <3 CMI


$config['user.role.anonymous']['permissions'][] = 'use browsersync';
$config['user.role.authenticated']['permissions'][] = 'use browsersync';

Edit: Hmm maybe nevermind on that one.

joelpittet’s picture

+++ b/templates/browsersync-snippet.html.twig
@@ -0,0 +1,13 @@
+<script type='text/javascript' id="__bs_script__">//<![CDATA[
...
+//]]></script>

+++ /dev/null
@@ -1,14 +0,0 @@
-<script type='text/javascript' id="__bs_script__">//<![CDATA[
...
-//]]></script>

Just a note for both versions, but more so for the D8 version as we are HTML5. You don't need to add type attribute for JavaScript @see http://stackoverflow.com/questions/5265202/do-you-need-text-javascript-s..., and CDATA is not needed for the HTML5 world (was there to pass XHTML well formed XML validation).

star-szr’s picture

@joelpittet 100% agree but thought it was out of scope. Can be addressed once we have a commit on 8.x-1.x IMO :) Thanks!

jorgegc’s picture

Hey @Cottser,

Have you addressed all the issues that you were having with the CMI? I saw you trying to resolve some issues to do with duplicates on IRC the other day. I have tested the module and everything seems to work, including the settings overrides and tests.

Agree with both you and @joelpittet regarding the snippet. We can definitely address that in a separate issue.

Cheers

star-szr’s picture

Assigned: star-szr » Unassigned

@jorgegc yes I think I've done all I can without stepping on core's toes, so this should be ready to go. To prevent the redundant data from being saved into theme settings the core bug at #2623146: theme_settings_convert_to_config() shouldn't save unknown keys into theme configuration objects needs to be fixed and @joelpittet seems to agree on the path forward there and it's really a generic core issue with anyone altering the theme settings form. I'll probably work on a patch and tests for that bug in the near future if someone else doesn't beat me to it.

So in short, this is ready to roll from my perspective. Once the core bug is fixed we shouldn't need to change anything, either.

jorgegc’s picture

Status: Needs review » Reviewed & tested by the community

I will commit it today when I get home. Thanks @Cottser!

  • jorgegc committed dd578f1 on 8.x-1.x
    Issue #2596637 by Cottser, jorgegc: Port to Drupal 8.
    
jorgegc’s picture

Status: Reviewed & tested by the community » Fixed
star-szr’s picture

Thanks, good news! Commit authorship (in git) would be appreciated next time but no big deal. We haven't yet gotten a chance to catch up on IRC but my offer for co-maintaining the 8.x branch still stands :)

jorgegc’s picture

Sorry I've screwed it up Cottser! On a much more positive note, I have added Digital Echidna as a supporting organisation for having "sponsored port to Drupal 8". Please let me know if this need to be amended.

Also, let's try and find some time to chat on IRC. I really appreciate your help and all the effort you have put into porting this module to D8. I guess I just need some guidance from someone more experienced in the issue queue to ensure I am doing the right thing. Cheers

star-szr’s picture

@jorgegc looks good thanks! I thought I had just caught you in IRC but didn't look closely enough at the timestamp.

Status: Fixed » Closed (fixed)

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