私は私のサブテーマにこのコードを持っています:
bootstrap_subtheme_front_office_old.theme
<?php
/**
* Implements hook_preprocess_HOOK() for user.html.twig.
*/
function bootstrap_subtheme_front_office_old_preprocess_user(&$variables) { $flag_id = 'flag_role_association';
$flag_service = \Drupal::service('flag'); $flag = $flag_service->getFlagById($flag_id);
$user_to_flag = $variables['user'];
$flag_status = $flag_service->getFlagging($flag, $user_to_flag);
$variables['is_flagged_role_association'] = $flag_status;
$flag_id = 'flag_role_pop_up_store'; $flag_service = \Drupal::service('flag');
$flag = $flag_service->getFlagById($flag_id); $user_to_flag = $variables['user']; $flag_status = $flag_service->getFlagging($flag, $user_to_flag); $variables['is_flagged_role_pop_up_store'] = $flag_status; $flag_id = 'flag_role_artisan';
$flag_service = \Drupal::service('flag'); $flag = $flag_service->getFlagById($flag_id);
$user_to_flag = $variables['user'];
$flag_status = $flag_service->getFlagging($flag, $user_to_flag);
$variables['is_flagged_role_artisan'] = $flag_status;
}
そしてこのテンプレート:
ユーザー--account-roles.html.twig
<div class="card p-4 overflow-hidden shadow rounded bg-white">
<div class="alert alert-light" role="alert">
<p class="text-center">Vous trouverez sur cette page les différents types de compte disponible.</p>
<p class="text-center">Chaque type de compte vous donne droit à des autorisations au sein de la plateforme.</p>
<p class="text-center font-weight-bold">Vous devez avoir un numéro de SIRET.</p>
<p class="text-center">Les modifications peuvent prendre 24 heures pour ếtre appliquées.</p>
</div>
<p>Les associations sont destinées aux comités des fêtes, offices de tourisme, ... qui organisent des événements. Vous pourrez y publier divers types de contenu.</p>
{% if 'association' in user.getroles %}
<div><i class="fas fa-circle text-success"></i> Votre compte association est actif.</div>
{% elseif 'association' not in user.getroles and is_flagged_role_association %}
<div><i class="fas fa-circle text-warning"></i> Votre compte association est en attente.</div>
{% elseif 'association' not in user.getroles and not is_flagged_role_association %}
<div><i class="fas fa-circle text-danger"></i> Votre compte association est inactif.</div>
{{ content.flag_role_association }}
{% endif %}
<span class="border-top mt-4 mb-4"></span>
<p>Les boutiques éphémères vous permettent d'exposer les créations des artisans présents sur la plateforme (pas de vente en ligne).</p>
{% if 'pop_up_store' in user.getroles %}
<div><i class="fas fa-circle text-success"></i> Votre compte boutique éphémère est actif.</div>
{% elseif 'pop_up_store' not in user.getroles and is_flagged_role_pop_up_store %}
<div><i class="fas fa-circle text-warning"></i> Votre compte boutique éphémère est en attente.</div>
{% elseif 'pop_up_store' not in user.getroles and not is_flagged_role_pop_up_store %}
<div><i class="fas fa-circle text-danger"></i> Votre compte boutique éphémère est inactif.</div>
{{ content.flag_role_pop_up_store }}
{% endif %}
<span class="border-top mt-4 mb-4"></span>
<p>Si vous êtes artisans, nous serions ravis de vous accueillir sur notre marketplace. Nous facturons une commission de 10% sur chaque vente. Vous recevrez une facture à chaque début de mois, si vous réalisez des ventes le mois précédent. Plus d'infos sur <a href="/node/271">cette page</a>.</p>
<p>Pas de vente = Rien à payer</p>
{% if 'marchand' in user.getroles %}
<div><i class="fas fa-circle text-success"></i> Votre compte artisan est actif.</div>
{% elseif 'marchand' not in user.getroles and is_flagged_role_artisan %}
<div><i class="fas fa-circle text-warning"></i> Votre compte artisan est en attente.</div>
{% elseif 'marchand' not in user.getroles and not is_flagged_role_artisan %}
<div><i class="fas fa-circle text-danger"></i> Votre compte artisan est inactif.</div>
{{ content.flag_role_artisan }}
{% endif %}
</div>
ユーザーアカウントページにアクセスすると、「ウェブサイトで予期しないエラーが発生しました。しばらくしてからもう一度お試しください」という空白のページが表示されます。
Drupalログに、以下のPHPエラーがあります。
どうすればこれを修正できますか?
Type php
Date Vendredi, 6 novembre, 2020 - 04:25
Utilisateur administrateur
Emplacement https://dev.example.com/user/1
Référent
Message TypeError : Argument 1 passed to Drupal\flag\FlagService::getFlagging() must implement interface Drupal\flag\FlagInterface, null given, called in /home/ubuntu/www-example-com/web/themes/custom/bootstrap_subtheme_front_office_old/bootstrap_subtheme_front_office_old.theme on line 11 dans Drupal\flag\FlagService->getFlagging() (/home/ubuntu/www-example-com/web/modules/contrib/flag/src/FlagService.php ligne 84)
#0 /home/ubuntu/www-example-com/web/themes/custom/bootstrap_subtheme_front_office_old/bootstrap_subtheme_front_office_old.theme(11): Drupal\flag\FlagService->getFlagging()
#1 /home/ubuntu/www-example-com/web/core/lib/Drupal/Core/Theme/ThemeManager.php(287): bootstrap_subtheme_front_office_old_preprocess_user()
#2 /home/ubuntu/www-example-com/web/core/lib/Drupal/Core/Render/Renderer.php(431): Drupal\Core\Theme\ThemeManager->render()
#3 /home/ubuntu/www-example-com/web/core/lib/Drupal/Core/Render/Renderer.php(200): Drupal\Core\Render\Renderer->doRender()
#4 /home/ubuntu/www-example-com/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(226): Drupal\Core\Render\Renderer->render()
#5 /home/ubuntu/www-example-com/web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#6 /home/ubuntu/www-example-com/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(227): Drupal\Core\Render\Renderer->executeInRenderContext()
#7 /home/ubuntu/www-example-com/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(117): Drupal\Core\Render\MainContent\HtmlRenderer->prepare()
#8 /home/ubuntu/www-example-com/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse()
#9 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
#10 /home/ubuntu/www-example-com/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func()
#11 /home/ubuntu/www-example-com/vendor/symfony/http-kernel/HttpKernel.php(156): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#12 /home/ubuntu/www-example-com/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#13 /home/ubuntu/www-example-com/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle()
#14 /home/ubuntu/www-example-com/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle()
#15 /home/ubuntu/www-example-com/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#16 /home/ubuntu/www-example-com/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#17 /home/ubuntu/www-example-com/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle()
#18 /home/ubuntu/www-example-com/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\ban\BanMiddleware->handle()
#19 /home/ubuntu/www-example-com/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#20 /home/ubuntu/www-example-com/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#21 /home/ubuntu/www-example-com/web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle()
#22 /home/ubuntu/www-example-com/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#23 {main}
.
Severity Erreur
これらは「グローバル」フラグです。これがマシン名(スクリーンショット)です。フラグの種類によっては、マシン名の末尾のみが変わります。

更新
