This issue is to track the work around adding a way to choose the AMP theme on the AMP configuration screen.

Comments

sirkitree created an issue. See original summary.

sirkitree’s picture

Issue summary: View changes
rainbowarray’s picture

Assigned: Unassigned » rainbowarray
rainbowarray’s picture

Assigned: rainbowarray » Unassigned
Status: Active » Needs review
StatusFileSize
new1.92 KB

This adds a configuration setting for selecting the theme to use on AMP pages and then uses that configuration in amp_custom_theme, which does the theme switching.

This code is based on how the admin theme switching is handled in core.

mtift’s picture

  1. +++ b/amp.admin.inc
    @@ -108,3 +116,42 @@ function amp_admin_form_validate($form, &$form_state) {
    +/**
    + * Process amp_admin_form form submissions.
    + */
    +function amp_admin_form_submit($form, &$form_state) {
    +  variable_set('amp_theme', $form_state['values']['amp_theme']);
    +}
    

    This is unnecessary because we are using system_settings_form()

  2. +++ b/amp.admin.inc
    @@ -108,3 +116,42 @@ function amp_admin_form_validate($form, &$form_state) {
    +  $theme_options = [];
    

    Drupal 7 only requires PHP 5.2.5 or higher so you probably shouldn't use short array syntax

  3. +++ b/amp.admin.inc
    @@ -108,3 +116,42 @@ function amp_admin_form_validate($form, &$form_state) {
    +function _amp_sort_theme_by_info_name($a, $b) {
    

    Is this a function you think we are going to need elsewhere? It seems weird to uasort the values from a sorting function.

mtift’s picture

Status: Needs review » Needs work
rainbowarray’s picture

Status: Needs work » Needs review
StatusFileSize
new1.74 KB

1. Fixed.
2. Fixed.
3. system_modules() prepares a similar list of theme options and relies upon a system_sort_modules_by_info_name callback that does the same sorting. Unfortunately, calling that wasn't working from within the amp module, so I created a similar helper function to do the same thing. So the amp module is essentially handling this the same way core does.

mtift’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

  • mdrummond committed 3831b02 on 7.x-1.x
    Issue #2678306 by mdrummond: [Port Config] Choose theme
    
rainbowarray’s picture

Status: Reviewed & tested by the community » Fixed
dave reid’s picture

+++ b/amp.admin.inc
@@ -108,3 +116,34 @@ function amp_admin_form_validate($form, &$form_state) {
+  uasort($themes, '_amp_sort_theme_by_info_name');

We can just reuse system_sort_modules_by_info_name() here, it has the same exact logic as _amp_sort_theme_by_info_name().

Why it wasn't working is that you just have to do this first: module_load_include('inc', 'system', 'system.admin');

dave reid’s picture

+++ b/amp.module
@@ -92,6 +92,6 @@ function amp_is_amp_request() {
+    return variable_get('amp_theme');

Should this variable_get() call have a default parameter? Or check if the variable is not empty? It seems odd it has a default value in the form above, but not here.

  • mdrummond committed 084b79a on 7.x-1.x authored by Dave Reid
    Issue #2678306 by mdrummond, Dave Reid: Improve configuration for...
rainbowarray’s picture

Applied the changes you suggested. Thanks Dave!

  • mdrummond committed f8befc3 on 7.x-1.x
    Issue #2678306 by mdrummond, Dave Reid: Fix missing semi-colon in...

Status: Fixed » Closed (fixed)

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