From 31a365ebab7e0c0246dd262c3f0d48d32e3e0392 Mon Sep 17 00:00:00 2001
From: Liam Morland <lkmorlan@uwaterloo.ca>
Date: Wed, 20 Jan 2021 14:26:54 -0500
Subject: [PATCH] Issue #3194285: Convert some methods to static

---
 .../LayoutBuilderIdsConfigureBlock.php                | 11 ++++-------
 .../LayoutBuilderIdsConfigureSection.php              | 11 ++++-------
 .../LayoutBuilderIdsRenderSubscriber.php              |  2 +-
 src/Service/LayoutBuilderIdsService.php               |  6 +++---
 src/Service/LayoutBuilderIdsServiceInterface.php      |  6 +++---
 5 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php b/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php
index 60f5195..2f5aef4 100644
--- a/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php
+++ b/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php
@@ -5,7 +5,6 @@ namespace Drupal\layout_builder_ids\EventSubscriber;
 use Drupal\Component\Utility\Html;
 use Drupal\core_event_dispatcher\Event\Form\FormAlterEvent;
 use Drupal\Core\Form\FormStateInterface;
-use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\hook_event_dispatcher\HookEventDispatcherInterface;
 use Drupal\layout_builder_ids\Service\LayoutBuilderIdsService;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -15,8 +14,6 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  */
 class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface {
 
-  use StringTranslationTrait;
-
   /**
    * Layout builder ids service.
    *
@@ -40,7 +37,7 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface {
    * @param \Drupal\core_event_dispatcher\Event\Form\FormAlterEvent $event
    *   The event.
    */
-  public function alterForm(FormAlterEvent $event): void {
+  public static function alterForm(FormAlterEvent $event): void {
 
     // Get the form from the event.
     $form = &$event->getForm();
@@ -63,7 +60,7 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface {
         '#title' => 'Block ID',
         '#weight' => 99,
         '#default_value' => $layout_builder_id ?: NULL,
-        '#description' => $this->t('Block ID is an optional setting which is used to support an anchor link to this block. For example, entering "feature" lets you link directly to this block by adding "#feature" to the end of the URL.</br>IDs should start with a letter, may only contain letters, numbers, underscores, hyphens, and periods, and should be unique on the page.'),
+        '#description' => t('Block ID is an optional setting which is used to support an anchor link to this block. For example, entering "feature" lets you link directly to this block by adding "#feature" to the end of the URL.</br>IDs should start with a letter, may only contain letters, numbers, underscores, hyphens, and periods, and should be unique on the page.'),
       ];
 
       // Add the form validation for configure block.
@@ -80,7 +77,7 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface {
   /**
    * {@inheritdoc}
    */
-  public function layoutBuilderIdsConfigureBlockFormValidation(array &$form, FormStateInterface $form_state) {
+  public static function layoutBuilderIdsConfigureBlockFormValidation(array &$form, FormStateInterface $form_state) {
 
     // Get the layout builder id from the form,
     // also put the id through the HTML getId to make sure
@@ -111,7 +108,7 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface {
   /**
    * {@inheritdoc}
    */
-  public function layoutBuilderIdsConfigureBlockSubmitForm(array &$form, FormStateInterface $form_state) {
+  public static function layoutBuilderIdsConfigureBlockSubmitForm(array &$form, FormStateInterface $form_state) {
 
     // Load in the layout_builder_id.
     $layout_builder_id = $form_state->getValue(['settings', 'layout_builder_id']);
diff --git a/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php b/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php
index 25c2aa8..3b2045a 100644
--- a/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php
+++ b/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php
@@ -5,7 +5,6 @@ namespace Drupal\layout_builder_ids\EventSubscriber;
 use Drupal\Component\Utility\Html;
 use Drupal\core_event_dispatcher\Event\Form\FormAlterEvent;
 use Drupal\Core\Form\FormStateInterface;
-use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\hook_event_dispatcher\HookEventDispatcherInterface;
 use Drupal\layout_builder_ids\Service\LayoutBuilderIdsService;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -15,8 +14,6 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  */
 class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface {
 
-  use StringTranslationTrait;
-
   /**
    * Layout builder ids service.
    *
@@ -40,7 +37,7 @@ class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface {
    * @param \Drupal\core_event_dispatcher\Event\Form\FormAlterEvent $event
    *   The event.
    */
-  public function alterForm(FormAlterEvent $event): void {
+  public static function alterForm(FormAlterEvent $event): void {
 
     // Get the form from the event.
     $form = &$event->getForm();
@@ -65,7 +62,7 @@ class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface {
         '#title' => 'Section ID',
         '#weight' => 99,
         '#default_value' => $config['layout_builder_id'] ?: NULL,
-        '#description' => $this->t('Section ID is an optional setting which is used to support an anchor link to this block. For example, entering "feature" lets you link directly to this section by adding "#feature" to the end of the URL.</br>IDs should start with a letter, may only contain letters, numbers, underscores, hyphens, and periods, and should be unique on the page.'),
+        '#description' => t('Section ID is an optional setting which is used to support an anchor link to this block. For example, entering "feature" lets you link directly to this section by adding "#feature" to the end of the URL.</br>IDs should start with a letter, may only contain letters, numbers, underscores, hyphens, and periods, and should be unique on the page.'),
       ];
 
       // Add the form validation for configure block.
@@ -82,7 +79,7 @@ class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface {
   /**
    * {@inheritdoc}
    */
-  public function layoutBuilderIdsConfigureSectionFormValidation(array &$form, FormStateInterface $form_state) {
+  public static function layoutBuilderIdsConfigureSectionFormValidation(array &$form, FormStateInterface $form_state) {
 
     // Get the layout builder id from the form.
     $layout_builder_id = $form_state->getValue(
@@ -114,7 +111,7 @@ class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface {
   /**
    * {@inheritdoc}
    */
-  public function layoutBuilderIdsConfigureSectionSubmitForm(array &$form, FormStateInterface $form_state) {
+  public static function layoutBuilderIdsConfigureSectionSubmitForm(array &$form, FormStateInterface $form_state) {
 
     // Get the layout builder id from the form.
     $layout_builder_id = $form_state->getValue(
diff --git a/src/EventSubscriber/LayoutBuilderIdsRenderSubscriber.php b/src/EventSubscriber/LayoutBuilderIdsRenderSubscriber.php
index ac69c82..01cdd21 100644
--- a/src/EventSubscriber/LayoutBuilderIdsRenderSubscriber.php
+++ b/src/EventSubscriber/LayoutBuilderIdsRenderSubscriber.php
@@ -32,7 +32,7 @@ class LayoutBuilderIdsRenderSubscriber implements EventSubscriberInterface {
    * @param \Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent $event
    *   The section component render event.
    */
-  public function onBuildRender(SectionComponentBuildRenderArrayEvent $event) {
+  public static function onBuildRender(SectionComponentBuildRenderArrayEvent $event) {
 
     // The render array.
     $build = $event->getBuild();
diff --git a/src/Service/LayoutBuilderIdsService.php b/src/Service/LayoutBuilderIdsService.php
index ffc3fcd..0081367 100644
--- a/src/Service/LayoutBuilderIdsService.php
+++ b/src/Service/LayoutBuilderIdsService.php
@@ -16,7 +16,7 @@ class LayoutBuilderIdsService implements LayoutBuilderIdsServiceInterface {
   /**
    * {@inheritDoc}
    */
-  public function layoutBuilderIdsCheckIds(string $layout_builder_id, FormStateInterface $form_state, string $type):bool {
+  public static function layoutBuilderIdsCheckIds(string $layout_builder_id, FormStateInterface $form_state, string $type):bool {
 
     // Return the found id, which will tell us if we have a
     // duplicate id.
@@ -27,7 +27,7 @@ class LayoutBuilderIdsService implements LayoutBuilderIdsServiceInterface {
   /**
    * {@inheritDoc}
    */
-  public function layoutBuilderIdsCheckSectionIds(string $layout_builder_id, FormStateInterface $form_state, string $type):bool {
+  public static function layoutBuilderIdsCheckSectionIds(string $layout_builder_id, FormStateInterface $form_state, string $type):bool {
 
     // Get the sections from the formObject.
     $sections = $form_state->getFormObject()->getSectionStorage()->getSections();
@@ -74,7 +74,7 @@ class LayoutBuilderIdsService implements LayoutBuilderIdsServiceInterface {
   /**
    * {@inheritDoc}
    */
-  public function layoutBuilderIdsCheckBlockIds(string $layout_builder_id, FormStateInterface $form_state, string $type):bool {
+  public static function layoutBuilderIdsCheckBlockIds(string $layout_builder_id, FormStateInterface $form_state, string $type):bool {
 
     // Get the sections from the formObject.
     $sections = $form_state->getFormObject()->getSectionStorage()->getSections();
diff --git a/src/Service/LayoutBuilderIdsServiceInterface.php b/src/Service/LayoutBuilderIdsServiceInterface.php
index bad2894..a554a2f 100644
--- a/src/Service/LayoutBuilderIdsServiceInterface.php
+++ b/src/Service/LayoutBuilderIdsServiceInterface.php
@@ -24,7 +24,7 @@ interface LayoutBuilderIdsServiceInterface {
    * @return bool
    *   A boolean value to whether or not there is a duplicate id.
    */
-  public function layoutBuilderIdsCheckIds(string $layout_builder_id, FormStateInterface $form_state, string $type):bool;
+  public static function layoutBuilderIdsCheckIds(string $layout_builder_id, FormStateInterface $form_state, string $type):bool;
 
   /**
    * Function to check the sections for duplicate ids.
@@ -39,7 +39,7 @@ interface LayoutBuilderIdsServiceInterface {
    * @return bool
    *   A boolean value to whether or not there is a duplicate id.
    */
-  public function layoutBuilderIdsCheckSectionIds(string $layout_builder_id, FormStateInterface $form_state, string $type):bool;
+  public static function layoutBuilderIdsCheckSectionIds(string $layout_builder_id, FormStateInterface $form_state, string $type):bool;
 
   /**
    * A function to check the blocks for a duplicate id.
@@ -54,6 +54,6 @@ interface LayoutBuilderIdsServiceInterface {
    * @return bool
    *   A boolean value to whether or not there is a duplicate id.
    */
-  public function layoutBuilderIdsCheckBlockIds(string $layout_builder_id, FormStateInterface $form_state, string $type):bool;
+  public static function layoutBuilderIdsCheckBlockIds(string $layout_builder_id, FormStateInterface $form_state, string $type):bool;
 
 }
-- 
GitLab