Commit 303eb75a authored by Chris Burge's avatar Chris Burge
Browse files

Issue #3295877 by Chris Burge: Add Drupal 10 Support; Drop Drupal 8 Support

parent a94cd357
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
    },
    "license": "GPL-2.0-or-later",
    "require": {
        "drupal/core": "^8.8.4 || ^9"
        "drupal/core": "^9.3|^10"
    },
    "require-dev": {
        "drupal/codemirror_editor": "^1.0"
+5 −4
Original line number Diff line number Diff line
@@ -3,16 +3,17 @@
 * Provides JS for the Twig UI settings form.
 */

(function ($, Drupal) {
(function (Drupal, $, once) {
  Drupal.behaviors.twigUiSettingsForm = {
    attach: function (context, settings) {
      $(document).ready(function () {
        toggleAllowedThemes()
        $("input[name=allowed_themes]", context).once('allowedThemesChange').change(function (e) {

        $(once('allowedThemesChange', "input[name=allowed_themes]")).change(function (e) {
          toggleAllowedThemes()
        });

        $("input[name^=allowed_theme_list", context).once('allowedThemeListItemChange').change(function (e) {
        $(once('allowedThemeListItemChange', "input[name^=allowed_theme_list")).change(function (e) {
          showHideDefaultSelectedElement(e.target);
        });
      });
@@ -75,4 +76,4 @@
      }
    }
  };
})(jQuery, Drupal);
})(Drupal, jQuery, once);
+5 −5
Original line number Diff line number Diff line
@@ -3,12 +3,12 @@
 * Provides JS for the Twig UI TwigTemplateForm form.
 */

(function ($, Drupal, drupalSettings) {
(function (Drupal, $, once, drupalSettings) {
    Drupal.behaviors.twigUiTemplateForm = {
      attach: function (context, settings) {
        $(document).ready(function () {
          // React to changes in the 'Theme' field.
          $("select[name=theme]", context).once('themeChange').change(function (e) {
          $(once('themeChange', "select[name=theme]")).change(function (e) {
            var theme = this.value;

            $.getJSON(drupalSettings.path.baseUrl + `ajax/twig-ui/template-list-load/${theme}`, function (data) {
@@ -24,7 +24,7 @@
          });

          // React to changes in the 'Template' field.
          $("select[name=template]", context).once('templateChange').change(function (e) {
          $(once('templateChange', "select[name=template]")).change(function (e) {
            var theme = $("select[name=theme]").val();
            var template = this.value;

@@ -45,7 +45,7 @@
          });

          // Insert template code into 'Template code' field.
          $("input[name=template-insert]", context).once('templateInsert').click(function (e) {
          $(once('templateInsert', "input[name=template-insert]")).click(function (e) {
            e.preventDefault();

            var theme = $("select[name=theme]").val();
@@ -73,4 +73,4 @@
        });
      }
    };
  })(jQuery, Drupal, drupalSettings);
  })(Drupal, jQuery, once, drupalSettings);
+40 −0
Original line number Diff line number Diff line
@@ -3,7 +3,13 @@
namespace Drupal\twig_ui\Theme;

use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\Theme\Registry as CoreRegistry;
use Drupal\Core\Theme\ThemeInitializationInterface;

/**
 * An extended Registry class for retrieving the unmodified registry.
@@ -18,6 +24,40 @@ use Drupal\Core\Theme\Registry as CoreRegistry;
 */
class ImmutableRegistry extends CoreRegistry {

  /**
   * Constructs a \Drupal\Core\Theme\Registry object.
   *
   * @param string $root
   *   The app root.
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache
   *   The cache backend interface to use for the complete theme registry data.
   * @param \Drupal\Core\Lock\LockBackendInterface $lock
   *   The lock backend.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler to use to load modules.
   * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
   *   The theme handler.
   * @param \Drupal\Core\Theme\ThemeInitializationInterface $theme_initialization
   *   The theme initialization.
   * @param \Drupal\Core\Cache\CacheBackendInterface $runtime_cache
   *   The cache backend interface to use for the runtime theme registry data.
   * @param \Drupal\Core\Extension\ModuleExtensionList $module_list
   *   The module list.
   * @param string $theme_name
   *   (optional) The name of the theme for which to construct the registry.
   */
  public function __construct($root, CacheBackendInterface $cache, LockBackendInterface $lock, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, ThemeInitializationInterface $theme_initialization, CacheBackendInterface $runtime_cache, ModuleExtensionList $module_list, $theme_name = NULL) {
    // In Drupal 10, the constructor changed.
    // Drupal 10.0.0 constructor.
    if (strpos(\Drupal::VERSION, '10') === 0) {
      parent::__construct($root, $cache, $lock, $module_handler, $theme_handler, $theme_initialization, $runtime_cache, $module_list, $theme_name);
    }
    // Drupal 9.3.0 constructor.
    else {
      parent::__construct($root, $cache, $lock, $module_handler, $theme_handler, $theme_initialization, $theme_name, $runtime_cache, $module_list);
    }
  }

  /**
   * Get the theme for this instance of Registry.
   *
+2 −2
Original line number Diff line number Diff line
@@ -308,11 +308,11 @@ class TemplateFormTest extends BrowserTestBase {
    $element = $page
      ->findField('label')
      ->getValue();
    $this->assertEqual($element, 'Clone of Node');
    $this->assertEquals($element, 'Clone of Node');
    $element = $page
      ->findField('id')
      ->getValue();
    $this->assertEqual($element, 'clone_node');
    $this->assertEquals($element, 'clone_node');
    $this->assertTrue($page->hasUncheckedField('themes[grant]'));

    // Change theme suggestion and select a theme so clone can be saved.
Loading