PHP code example of hypejunction / group_subtypes

1. Go to this page and download the library: Download hypejunction/group_subtypes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hypejunction / group_subtypes example snippets


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

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 = 				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, "\r\n\r\nreturn $contents;\r\n");
		fclose($file);
	}
}