You are here

protected function GroupMenuConfigOverrides::getEnabledGroupMenuTypesByNodeType in Group Menu 8

Get all group types where the group menus are enabled for a node type.

Parameters

string $node_type: A node type.

Return value

array An array of group types with the ID as key and value.

1 call to GroupMenuConfigOverrides::getEnabledGroupMenuTypesByNodeType()
GroupMenuConfigOverrides::loadOverrides in src/GroupMenuConfigOverrides.php
Returns config overrides.

File

src/GroupMenuConfigOverrides.php, line 139

Class

GroupMenuConfigOverrides
Group menu configuration overrides.

Namespace

Drupal\groupmenu

Code

protected function getEnabledGroupMenuTypesByNodeType($node_type) {
  if (isset($this->groupTypes[$node_type])) {
    return $this->groupTypes[$node_type];
  }
  $cid = 'groupmenu:group_menu_types:' . $node_type;
  $persistent_cache = $this->cache
    ->get($cid);
  if ($persistent_cache && $persistent_cache->valid) {
    $this->groupTypes[$node_type] = $persistent_cache->data;
    return $this->groupTypes[$node_type];
  }
  $plugin_id = 'group_node:' . $node_type;
  $group_content_types = GroupContentType::loadByContentPluginId($plugin_id);

  // Get the list of group types to find menus for.
  $this->groupTypes[$node_type] = [];

  /** @var \Drupal\group\entity\GroupContentTypeInterface $group_content_type */
  foreach ($group_content_types as $group_content_type) {
    if (!empty($group_content_type
      ->getContentPlugin()
      ->getConfiguration()['node_form_group_menu'])) {
      $this->groupTypes[$node_type][$group_content_type
        ->getGroupType()
        ->id()] = $group_content_type
        ->getGroupType()
        ->id();
    }
  }
  $this->cache
    ->set($cid, $this->groupTypes[$node_type]);
  return $this->groupTypes[$node_type];
}