PHPackages                             hypejunction/group\_subtypes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hypejunction/group\_subtypes

AbandonedArchivedElgg-plugin[Utility &amp; Helpers](/categories/utility)

hypejunction/group\_subtypes
============================

Group subtypes for Elgg

1.0.5(9y ago)170[1 issues](https://github.com/hypeJunction/Elgg-group_subtypes/issues)1GPL-2.0PHPPHP &gt;=5.5

Since Feb 18Pushed 9y ago1 watchersCompare

[ Source](https://github.com/hypeJunction/Elgg-group_subtypes)[ Packagist](https://packagist.org/packages/hypejunction/group_subtypes)[ Docs](http://hypejunction.com)[ RSS](/packages/hypejunction-group-subtypes/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (6)Dependencies (1)Versions (8)Used By (1)

Group Subtypes for Elgg
=======================

[](#group-subtypes-for-elgg)

[![Elgg 2.0](https://camo.githubusercontent.com/981b94044a74b931be93e2825c7151896de9c8a53ccb960daf01b8fe0d800774/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f456c67672d322e302e782d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/981b94044a74b931be93e2825c7151896de9c8a53ccb960daf01b8fe0d800774/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f456c67672d322e302e782d6f72616e67652e7376673f7374796c653d666c61742d737175617265)

Features
--------

[](#features)

- API for introducing new group subtypes
- A tool for upgrading existing groups to one of the introduced subtypes
- Admin interface for configuring root level and subgroup subtypes
- Admin interface for creating groups with fixed tool presets

[![Group Subtypes](https://camo.githubusercontent.com/42841f8219f74dc12441bf0ebba024195d83dccef77d65fa72a9136509fe5288/68747470733a2f2f7261772e6769746875622e636f6d2f687970654a756e6374696f6e2f456c67672d67726f75705f73756274797065732f6d61737465722f73637265656e73686f74732f67726f75705f73756274797065732e706e67 "Admin Interface for managing group subtypes")](https://camo.githubusercontent.com/42841f8219f74dc12441bf0ebba024195d83dccef77d65fa72a9136509fe5288/68747470733a2f2f7261772e6769746875622e636f6d2f687970654a756e6374696f6e2f456c67672d67726f75705f73756274797065732f6d61737465722f73637265656e73686f74732f67726f75705f73756274797065732e706e67)

Description
-----------

[](#description)

The plugin provides high level hooks and some preliminary UI for introducing group subtypes, spreading out groups across multiple page handlers, using context specific language strings etc. The plugin does not provide actual translations, and does not change existing resource views - those are done in sister plugins (group\_lists, group\_membership, group\_profiles).

Please note that the plugin overwrites some of the group views, which are commonly overwritten by other plugins (e.g. group\_tools), so you may need to integrate them if you rely on both functionalities.

Usage
-----

[](#usage)

### Hooks

[](#hooks)

- `'list_subtypes',$identifier` - filters group subtypes to be displayed on an `$identifier` page
- `'page_identifier',"$type:$subtype"` - filter the route page identifier for a group of given type and subtype
- `'permissions_check:parent','group'` - filter the permission for a parent entity to have the group as a child

### Translations

[](#translations)

Once you set up the subtypes, there will be numerous untranslated language keys. I am yet to write a plugin to automate the process. In the meantime, you can do the following:

1. Create a new plugin for your translations
2. Add your language files to `/languages/`, e.g. `/languages/en.php`
3. Add translations 2 translations for each subtype, e.e. if your subtype is school:

```
// /languages/en.php
return [
	'group:school' => 'School',
	'item:group:school' => 'Schools',
];
```

4. In your `start.php`, add the following:

```
elgg_register_event_handler('ready', 'system', 'group_subtypes_register_translations');

/**
 * Use groups plugin translations for group subtypes
 * @global type $GLOBALS
 */
function group_subtypes_register_translations() {

	global $GLOBALS;

	$conf = group_subtypes_get_config();
	$identifiers = array();
	foreach ($conf as $subtype => $options) {
		$identifier = elgg_extract('identifier', $options);
		if ($identifier && $identifier !== 'groups') {
			$identifiers[$subtype] = $identifier;
		}
	}

	$languages = array_keys(get_installed_translations());

	foreach ($languages as $language) {
		$translations = $GLOBALS['_ELGG']->translations[$language];

		$to_translate = array();
		if (file_exists(__DIR__ . "/languages/$language.php")) {
			$to_translate = include_once __DIR__ . "/languages/$language.php";
		}

		$original_str = $translations["groups:group"];
		$original_str_plural = $translations["groups"];

		foreach ($identifiers as $subtype => $identifier) {

			$subtype_str = $original_str;
			if (isset($translations["group:$subtype"])) {
				$subtype_str = $translations["group:$subtype"];
			}
			$to_translate["group:$subtype"] = $subtype_str;

			$subtype_str_plural = $original_str_plural;
			if (isset($translations["item:group:$subtype"])) {
				$subtype_str_plural = $translations["item:group:$subtype"];
			}
			$to_translate["item:group:$subtype"] = $subtype_str_plural;

			foreach ($translations as $key => $translation) {
				$identifier_key = preg_replace("/^(groups)/", $identifier, $key);
				if ($identifier_key == $key) {
					continue;
				}
				if (!empty($translations[$identifier_key])) {
					continue;
				}

				$translation = str_replace(strtolower($original_str), strtolower($subtype_str), $translation);
				$translation = str_replace(ucfirst($original_str), ucfirst($subtype_str), $translation);

				$translation = str_replace(strtolower($original_str_plural), strtolower($subtype_str_plural), $translation);
				$translation = str_replace(ucfirst($original_str_plural), ucfirst($subtype_str_plural), $translation);

				$to_translate[$identifier_key] = $translation;
			}
		}

		$file = fopen(__DIR__ . "/languages/$language.php", 'w');
		$contents = var_export($to_translate, true);
		fwrite($file, "
