Commit be948999 authored by Andrew Morton's avatar Andrew Morton Committed by Lawri van Buël
Browse files

Issue #3254242: PHP8 Support

feat: Bumped Drupal version to minimal 9.4 to be compliant with the PHP 7.4 minimal requirement
parent bb3335b2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@
    "minimum-stability": "dev",
    "require": {
       "ext-json": "*",
       "php": "^7.2",
       "drupal/core": "^8.8 || ^9"
       "php": "^7.4 || ^8",
       "drupal/core": "^9.4 || ^10"
    },
    "require-dev": {
        "drupal/coder": "^8.3"
+1 −2
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@ description: Rocket.Chat integration module.
package: Rocket.Chat
configure: rocket_chat.admin_settings
type: module
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9.3 || ^10
dependencies:
  - rocket_chat:rocket_chat_api
+2 −0
Original line number Diff line number Diff line
@@ -34,8 +34,10 @@ use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 *
 * @param $route_name
 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
 *
 * @return string
 */
function rocket_chat_help($route_name, RouteMatchInterface $route_match) {
+9 −7
Original line number Diff line number Diff line
<?php


namespace Drupal\rocket_chat\Form;


use Drupal;
use Drupal\Core\Form\FormStateInterface;
use Drupal\group\Entity\Group;
@@ -75,7 +73,8 @@ class RocketChatGroupHelper {
          $members[] = $member;
          try {
            $member->getUserProxy($apiClient);
          } catch (Exception $e) {
          }
          catch (Exception $e) {
            //TODO log user proxy failure!.
          }
        }
@@ -90,18 +89,21 @@ class RocketChatGroupHelper {
          try {
            $Channel->getChannelProxy($apiClient);
            $Channel->addMembers($apiClient, $members);
          } catch (Exception $e) {
          }
          catch (Exception $e) {
            //Todo log proxy failure
          }
        }
        Drupal::messenger()
          ->addStatus("Group Channel | " . json_encode($fieldValue) . " | Group Type | " . json_encode($type) . " | Members " . count($members));
      }
    } else {
    }
    else {
      Drupal::messenger()->addError("Rocket Chat connection Failed");
      if (!empty($form_state)) {
        $form_state->setErrorByName('url', "Rocket Chat connection Failed, is this correct?");
      }
    }
  }

}
+66 −54
Original line number Diff line number Diff line
@@ -30,9 +30,13 @@ namespace Drupal\rocket_chat\Form;
 * Any configuration enhancement must be done within.
 */

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\rocket_chat\Utility;
use Drupal\rocket_chat_api\RocketChat\ApiClient;
use Drupal\rocket_chat_api\RocketChat\Collection\Channels;
use Drupal\rocket_chat_api\RocketChat\Collection\Groups;
@@ -43,10 +47,6 @@ use Drupal\rocket_chat_api\RocketChat\InMemoryConfig;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Form\FormStateInterface;
use Drupal\rocket_chat\Utility;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;

/**
 * Class RocketChatSettingsForm.
@@ -55,6 +55,13 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
 */
class RocketChatSettingsForm extends ConfigFormBase {

  /**
   * The messenger.
   *
   * @var \Drupal\Core\Messenger\MessengerInterface
   */
  protected $messenger;

  /**
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
@@ -65,13 +72,6 @@ class RocketChatSettingsForm extends ConfigFormBase {
   */
  private $state;

  /**
   * The messenger.
   *
   * @var \Drupal\Core\Messenger\MessengerInterface
   */
  protected $messenger;

  /**
   * Constructs a \Drupal\system\ConfigFormBase object.
   *
@@ -111,17 +111,43 @@ class RocketChatSettingsForm extends ConfigFormBase {
  }

  /**
   * {@inheritdoc}
   * Alternative submit handler for Button Precces that do not safe.
   *
   * @param array $form
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   */
  public function getFormId() {
    return 'rocket_chat.admin_settings';
  public static function altSubmitForm(array &$form, FormStateInterface $form_state) {
    /** @var RocketChatSettingsForm $formObject */
    $formObject = $form_state->getFormObject();
    $apiConfig = new Drupal8Config($formObject->configFactory(), $formObject->moduleHandler, $formObject->state, $formObject->messenger);
    $apiClient = new ApiClient($apiConfig);

    if ($apiConfig->isReady()) {
      $RocketChatState = new Drupal8State($formObject->state);
      $Channels = new Channels($RocketChatState, $apiClient);
      $Channels->refreshCache(TRUE);
      $Groups = new Groups($RocketChatState, $apiClient);
      $Groups->refreshCache(TRUE);
      $Users = new Users($RocketChatState, $apiClient);
      $Users->refreshCache(TRUE);
    }
  }

  /**
   * Alternative submit handler for Button Precces that do not safe.
   *
   * @param array $form
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   */
  public static function groupsSubmitForm(array &$form, FormStateInterface $form_state) {
    RocketChatGroupHelper::rebuildRocketchatState($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return ['rocket_chat.settings'];
  public function getFormId() {
    return 'rocket_chat.admin_settings';
  }

  /**
@@ -179,7 +205,12 @@ class RocketChatSettingsForm extends ConfigFormBase {
    $form['rocketchatRefreshCache'] = [
      '#type' => 'button',
      '#value' => $this->t("Rebuild Rocketchat Cache"),
      "#submit" => [['\Drupal\rocket_chat\Form\RocketChatSettingsForm','altSubmitForm']],
      "#submit" => [
        [
          '\Drupal\rocket_chat\Form\RocketChatSettingsForm',
          'altSubmitForm',
        ],
      ],
      "#limit_validation_errors" => FALSE,
      '#executes_submit_callback' => TRUE,
    ];
@@ -191,7 +222,12 @@ class RocketChatSettingsForm extends ConfigFormBase {
      $form['rocketchatRefreshGroups'] = [
        '#type' => 'button',
        '#value' => $this->t("Rebuild Groups Channels"),
        "#submit" => [['\Drupal\rocket_chat\Form\RocketChatSettingsForm','groupsSubmitForm']],
        "#submit" => [
          [
            '\Drupal\rocket_chat\Form\RocketChatSettingsForm',
            'groupsSubmitForm',
          ],
        ],
        "#limit_validation_errors" => FALSE,
        '#executes_submit_callback' => TRUE,
      ];
@@ -254,7 +290,7 @@ class RocketChatSettingsForm extends ConfigFormBase {
          'Updated the Rocketchat [@oldurl] -> [@url]',
          [
            '@url' => $form_url,
            "@oldurl" => (empty($oldUrl) ? $this->t("Not Set") : $oldUrl)
            "@oldurl" => (empty($oldUrl) ? $this->t("Not Set") : $oldUrl),
          ]
        )
      );
@@ -319,34 +355,10 @@ class RocketChatSettingsForm extends ConfigFormBase {
  }

  /**
   * Alternative submit handler for Button Precces that do not safe.
   * @param array $form
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   */
  public static function altSubmitForm(array &$form, FormStateInterface $form_state){
    /** @var RocketChatSettingsForm  $formObject */
    $formObject = $form_state->getFormObject();
    $apiConfig = new Drupal8Config($formObject->configFactory(), $formObject->moduleHandler, $formObject->state, $formObject->messenger);
    $apiClient = new ApiClient($apiConfig);

    if($apiConfig->isReady()){
       $RocketChatState = new Drupal8State($formObject->state);
       $Channels = new Channels($RocketChatState, $apiClient);
       $Channels->refreshCache(TRUE);
       $Groups = new Groups($RocketChatState, $apiClient);
       $Groups->refreshCache(TRUE);
       $Users = new Users($RocketChatState, $apiClient);
       $Users->refreshCache(TRUE);
    }
  }

  /**
   * Alternative submit handler for Button Precces that do not safe.
   * @param array $form
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   * {@inheritdoc}
   */
  public static function groupsSubmitForm(array &$form, FormStateInterface $form_state) {
    RocketChatGroupHelper::rebuildRocketchatState($form,$form_state);
  protected function getEditableConfigNames() {
    return ['rocket_chat.settings'];
  }

}
Loading