アカウントにフラグが設定されている場合、メッセージを表示できません

-3
fire 2020-11-06 17:47.

私は私のサブテーマにこのコードを持っています:

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

これらは「グローバル」フラグです。これがマシン名(スクリーンショット)です。フラグの種類によっては、マシン名の末尾のみが変わります。

更新

1 answers

3
MacSim 2020-11-06 18:42.

フラグサービスを3回実装する必要はありません。1回で十分です(ユーザーがフラグを立てるのと同じです)。

エラーはMessage TypeError : Argument 1 passed to Drupal\flag\FlagService::getFlagging() must implement interface Drupal\flag\FlagInterface, null given$flag変数がnullであることを意味します。ほとんどのフラグサービスでは、(与えているフラグIDのフラグを取得することができませんflag_role_associationflag_role_pop_up_storeflag_role_artisan)。それらの値についてよろしいですか?

私はあなたのフックを次のように個人的に書き直します; エラーを削除してページを表示する必要$flagがありますが、nullになる限り、問題が完全に解決されるかどうかはわかりません。

<?php

/**
 * Implements hook_preprocess_HOOK() for user.html.twig.
 */
function bootstrap_subtheme_front_office_old_preprocess_user(&$variables) { $flag_service = \Drupal::service('flag');
  $user_to_flag = $variables['user'];

  $flag_ids = [ 'flag_role_association' => 'is_flagged_role_association', 'flag_role_pop_up_store' => 'is_flagged_role_pop_up_store', 'flag_role_artisan' => 'is_flagged_role_artisan', ]; foreach ($flag_ids as $flag_id => $var_flag) {
    if ($flag = $flag_service->getFlagById($flag_id)) { if ($flag_status = $flag_service->getFlagging($flag, $user_to_flag)) { $variables[$var_flag] = $flag_status;
      }
    }
  }
}

Related questions

MORE COOL STUFF

Reba McEntire は、彼女が息子の Shelby Blackstock と共有する「楽しい」クリスマスの伝統を明らかにしました:「私たちはたくさん笑います」

Reba McEntire は、彼女が息子の Shelby Blackstock と共有する「楽しい」クリスマスの伝統を明らかにしました:「私たちはたくさん笑います」

Reba McEntire が息子の Shelby Blackstock と共有しているクリスマスの伝統について学びましょう。

メーガン・マークルは、自然な髪のスタイリングをめぐってマライア・キャリーと結ばれました

メーガン・マークルは、自然な髪のスタイリングをめぐってマライア・キャリーと結ばれました

メーガン・マークルとマライア・キャリーが自然な髪の上でどのように結合したかについて、メーガンの「アーキタイプ」ポッドキャストのエピソードで学びましょう.

ハリー王子は家族との関係を修復できるという「希望を持っている」:「彼は父親と兄弟を愛している」

ハリー王子は家族との関係を修復できるという「希望を持っている」:「彼は父親と兄弟を愛している」

ハリー王子が家族、特にチャールズ王とウィリアム王子との関係について望んでいると主張したある情報源を発見してください。

ワイノナ・ジャッドは、パニックに陥った休暇の瞬間に、彼女がジャッド家の家長であることを認識しました

ワイノナ・ジャッドは、パニックに陥った休暇の瞬間に、彼女がジャッド家の家長であることを認識しました

ワイノナ・ジャッドが、母親のナオミ・ジャッドが亡くなってから初めての感謝祭のお祝いを主催しているときに、彼女が今では家長であることをどのように認識したかを学びましょう.

セントヘレナのジェイコブのはしごを登るのは、気弱な人向けではありません

セントヘレナのジェイコブのはしごを登るのは、気弱な人向けではありません

セント ヘレナ島のジェイコブズ ラダーは 699 段の真っ直ぐ上る階段で、頂上に到達すると証明書が発行されるほどの難易度です。

The Secrets of Airline Travel Quiz

The Secrets of Airline Travel Quiz

Air travel is far more than getting from point A to point B safely. How much do you know about the million little details that go into flying on airplanes?

Where in the World Are You? Take our GeoGuesser Quiz

Where in the World Are You? Take our GeoGuesser Quiz

The world is a huge place, yet some GeoGuessr players know locations in mere seconds. Are you one of GeoGuessr's gifted elite? Take our quiz to find out!

バイオニック読書はあなたをより速く読むことができますか?

バイオニック読書はあなたをより速く読むことができますか?

BionicReadingアプリの人気が爆発的に高まっています。しかし、それは本当にあなたを速読術にすることができますか?

Microsoftの新しいSurfaceLaptopはこれまでになく安価です(ただし、それほど強力ではありません)

Microsoftの新しいSurfaceLaptopはこれまでになく安価です(ただし、それほど強力ではありません)

写真:Alex Cranz / Gizmodo Microsoftは、Surface Laptopラインの一部をリニューアルし、SurfaceLaptopとSurfaceBook2の2つのモデルの価格を下げました。

1か月にわたる金融デトックスの準備をする

1か月にわたる金融デトックスの準備をする

画像ソース:Pixabay私たちは皆、私たちが変えることができるお金の習慣を1つか2つ持っています。1か月の余分な支出をあきらめることは、それ自体であなたの人生を変えたり、あなたを金持ちにすることはありません。

この警官がジャークになる以外の理由がないために状況をエスカレートするのを見てください

この警官がジャークになる以外の理由がないために状況をエスカレートするのを見てください

Facebookのビデオスクリーンショットこれを知るには若すぎるかもしれない人のために、Ice-TがLaw&Order:Special Victims Unitの大スターになる前は、彼は史上最高のロサンゼルスのギャングスタラッパーの一人でした。実際、彼はNの前にギャングスタラップをやっていた。

このChrome拡張機能で「人種差別的」を「人種差別主義者」に置き換えます

このChrome拡張機能で「人種差別的」を「人種差別主義者」に置き換えます

WHAS 11経由の画像人種差別主義者でなくても、実際には「人種差別的」なものもあります。しかし、主流メディアでは、前者は通常後者のコードです。

米国のフィギュア スケートは、チーム イベントでの最終決定の欠如に「苛立ち」、公正な裁定を求める

米国のフィギュア スケートは、チーム イベントでの最終決定の欠如に「苛立ち」、公正な裁定を求める

ロシアのフィギュアスケーター、カミラ・バリエバが関与したドーピング事件が整理されているため、チームは2022年北京冬季オリンピックで獲得したメダルを待っています。

Amazonの買い物客は、わずか10ドルのシルクの枕カバーのおかげで、「甘やかされた赤ちゃんのように」眠れると言っています

Amazonの買い物客は、わずか10ドルのシルクの枕カバーのおかげで、「甘やかされた赤ちゃんのように」眠れると言っています

何千人ものAmazonの買い物客がMulberry Silk Pillowcaseを推奨しており、現在販売中. シルクの枕カバーにはいくつかの色があり、髪を柔らかく肌を透明に保ちます。Amazonで最大46%オフになっている間にシルクの枕カバーを購入してください

パデュー大学の教授が覚醒剤を扱った疑いで逮捕され、女性に性的好意を抱かせる

パデュー大学の教授が覚醒剤を扱った疑いで逮捕され、女性に性的好意を抱かせる

ラファイエット警察署は、「不審な男性が女性に近づいた」という複数の苦情を受けて、12 月にパデュー大学の教授の捜査を開始しました。

コンセプト ドリフト: AI にとって世界の変化は速すぎる

コンセプト ドリフト: AI にとって世界の変化は速すぎる

私たちの周りの世界と同じように、言語は常に変化しています。以前の時代では、言語の変化は数年または数十年にわたって発生していましたが、現在では数日または数時間で変化する可能性があります。

SF攻撃で91歳のアジア人女性が殴られ、コンクリートに叩きつけられた

犯罪擁護派のオークランドが暴力犯罪者のロミオ・ロレンゾ・パーハムを釈放

SF攻撃で91歳のアジア人女性が殴られ、コンクリートに叩きつけられた

認知症を患っている 91 歳のアジア人女性が最近、47 番街のアウター サンセット地区でロメオ ロレンゾ パーハムに襲われました。伝えられるところによると、被害者はサンフランシスコの通りを歩いていたところ、容疑者に近づき、攻撃を受け、暴行を受けました。

ℝ

“And a river went out of Eden to water the garden, and from thence it was parted and became into four heads” Genesis 2:10. ? The heart is located in the middle of the thoracic cavity, pointing eastward.

メリック・ガーランドはアメリカに失敗しましたか?

バイデン大統領の任期の半分以上です。メリック・ガーランドは何を待っていますか?

メリック・ガーランドはアメリカに失敗しましたか?

人々にチャンスを与えることは、人生で少し遅すぎると私は信じています。寛大に。

Language