Fix user.data ServiceNotFoundException when using Gin as distribution installer theme

Created on 5 December 2022, about 2 years ago
Updated 24 January 2024, 11 months ago

Problem/Motivation

When setting Gin as theme for the profile installation wizard this happens:

Steps to reproduce

1. Download Drupal
2. Edit core/profiles/standard/standard.info.yml. Edit the code below name and type to look like this:

name: Standard
type: profile
distribution:
  name: Standard
  install:
    theme: gin

3. Open the installation wizard

you'll get the error when using gin here. With Claro it works fine:

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇳🇱Netherlands jurriaanroelofs

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇯🇴Jordan Rajab Natshah Jordan

    Quick fix for this with custom --gin-color-primary accent

    Not to load not styled gin accent while installing.
    As no user Gin setting yet and no user service yet.

    Removing

    /**
     * Implements hook_css_alter().
     */
    function hook_css_alter(&$css, AttachedAssetsInterface $assets) {
    
      global $install_state;
      if (isset($install_state) && empty($install_state['installation_finished'])) {
        // Not to load not styled gin accent while installing.
        // As no user Gin setting yet and not user service yet.
        $gin_theme_css_path = \Drupal::service('extension.list.theme')->getPath('gin') . '/dist/css';
        unset($css[$gin_theme_css_path . '/base/gin.css']);
      }
    
    }
    

    Looking for a better fix tho

  • 🇯🇴Jordan Rajab Natshah Jordan

    Obs, forgot the patch

  • Status changed to Needs review about 1 year ago
  • Assigned to Rajab Natshah
  • Status changed to Active about 1 year ago
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇫🇷France nicolasgraph Strasbourg

    Thank you all for your work on this issue! It does work as far as I tested.
    However, Did you think about fixing the backend part directly and only in GinSettings to keep things simple and tidy?
    I don't want to pollute current patches but here is what seems to work for me.

    diff --git a/src/GinSettings.php b/src/GinSettings.php
    index 0bb6e42..15a111f 100644
    --- a/src/GinSettings.php
    +++ b/src/GinSettings.php
    @@ -27,7 +27,7 @@ class GinSettings implements ContainerInjectionInterface {
       /**
        * The user data service.
        *
    -   * @var \Drupal\user\UserDataInterface
    +   * @var \Drupal\user\UserDataInterface|null
        */
       protected $userData;
     
    @@ -41,15 +41,15 @@ class GinSettings implements ContainerInjectionInterface {
       /**
        * Settings constructor.
        *
    -   * @param \Drupal\user\UserDataInterface $userData
    -   *   The user data service.
        * @param \Drupal\Core\Session\AccountInterface $currentUser
        *   The current user.
        * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
        *   The config factory.
        */
    -  public function __construct(UserDataInterface $userData, AccountInterface $currentUser, ConfigFactoryInterface $configFactory) {
    -    $this->userData = $userData;
    +  public function __construct(AccountInterface $currentUser, ConfigFactoryInterface $configFactory) {
    +    if (\Drupal::hasService('user.data')) {
    +      $this->userData = \Drupal::service('user.data');
    +    }
         $this->currentUser = $currentUser;
         $this->configFactory = $configFactory;
       }
    @@ -59,7 +59,6 @@ class GinSettings implements ContainerInjectionInterface {
        */
       public static function create(ContainerInterface $container) {
         return new static(
    -      $container->get('user.data'),
           $container->get('current_user'),
           $container->get('config.factory')
         );
    @@ -121,7 +120,7 @@ class GinSettings implements ContainerInjectionInterface {
        *   The account object. Current user if NULL.
        */
       public function setAll(array $settings, AccountInterface $account = NULL) {
    -    if (!$account) {
    +    if (!$account || !$this->userData) {
           $account = $this->currentUser;
         }
         // All settings are deleted to remove legacy settings.
    @@ -137,7 +136,7 @@ class GinSettings implements ContainerInjectionInterface {
        *   The account object. Current user if NULL.
        */
       public function clear(AccountInterface $account = NULL) {
    -    if (!$account) {
    +    if (!$account || !$this->userData) {
           $account = $this->currentUser;
         }
         $this->userData->delete('gin', $account->id());
    @@ -164,7 +163,7 @@ class GinSettings implements ContainerInjectionInterface {
        *   TRUE or FALSE.
        */
       public function userOverrideEnabled(AccountInterface $account = NULL) {
    -    if (!$account) {
    +    if (!$account || !$this->userData) {
           $account = $this->currentUser;
         }
         return $this->allowUserOverrides() && (bool) $this->userData->get('gin', $account->id(), 'enable_user_settings');
    
    
  • Status changed to RTBC 12 months ago
  • leymannx Berlin

    Upping #26 as patch as it's working for me and I prefer this approach for fixing the problem exactly where it occurs. Credits need to go to @NicolasGraph.

  • 🇨🇭Switzerland saschaeggi Zurich

    @leymannx can you create a MR for this? TY in advance!

  • Status changed to Fixed 11 months ago
  • 🇨🇭Switzerland saschaeggi Zurich

    Thanks y'all for your participation in addressing this 🙌

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

  • Pipeline finished with Failed
    2 months ago
    Total: 428s
    #303335
  • Pipeline finished with Failed
    2 months ago
    Total: 540s
    #303349
  • Pipeline finished with Failed
    2 months ago
    Total: 441s
    #304159
  • Pipeline finished with Failed
    2 months ago
    Total: 1080s
    #304182
  • Pipeline finished with Failed
    2 months ago
    Total: 523s
    #304199
  • Pipeline finished with Failed
    2 months ago
    Total: 258s
    #304308
  • Pipeline finished with Failed
    2 months ago
    Total: 619s
    #304309
Production build 0.71.5 2024