You are here

public static function moduleHelper::extractChannelMachineName in Rocket.Chat 8.2

Get the Machine name for the channel in this group.

Parameters

\Drupal\group\Entity\GroupInterface $group:

Return value

string|null

2 calls to moduleHelper::extractChannelMachineName()
moduleHelper::ProcessGroupContentUpdate in modules/rocket_chat_group/src/RocketChat/moduleHelper.php
RocketChatChannelBlock::build in modules/rocket_chat_group/src/Plugin/Block/RocketChatChannelBlock.php

File

modules/rocket_chat_group/src/RocketChat/moduleHelper.php, line 162

Class

moduleHelper

Namespace

Drupal\rocket_chat_group\RocketChat

Code

public static function extractChannelMachineName(GroupInterface $group) {
  $fieldMachineName = NULL;
  $groupEntityTypeId = $group
    ->getEntityTypeId();
  $groupBundle = $group
    ->bundle();
  $fieldMapping = Drupal::service('entity_field.manager')
    ->getFieldMapByFieldType('channel');
  if (isset($fieldMapping[$groupEntityTypeId])) {
    $channelEntity = $fieldMapping[$groupEntityTypeId];
    foreach ($channelEntity as $fieldName => $fieldSettings) {
      if (isset($fieldSettings['bundles'])) {
        foreach ($fieldSettings['bundles'] as $bundle) {
          if (strcmp($groupBundle, $bundle) === 0) {
            $fieldMachineName = $fieldName;
            break;
          }
        }
      }
    }
  }
  return $fieldMachineName;
}