2017 © Pedro Peláez
 

elgg-plugin group_subtypes

Group subtypes for Elgg

image

hypejunction/group_subtypes

Group subtypes for Elgg

  • Sunday, January 8, 2017
  • by hypeJunction
  • Repository
  • 1 Watchers
  • 1 Stars
  • 35 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

Group Subtypes for Elgg

Elgg 2.0, (*1)

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, (*2)

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)., (*3)

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., (*4)

Usage

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

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:, (*5)

  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',
];
  1. 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, "<?php\r\n\r\nreturn $contents;\r\n");
        fclose($file);
    }
}
  1. Load the website
  2. You will now see new language files in /languages/, e.g. /languages/en.schools.php
  3. Edit the new files to your needs. You don't need to copy anything, these files will be loaded like other translation files.
  4. Remove all the code from start.php, as you don't want to run that code all the time
  5. Flush the caches and enjoy!

Acknowledgements

This plugin has been sponsored by IvyTies.com - a social network platform for college admissions, (*6)

The Versions

08/01 2017

dev-master

9999999-dev http://hypejunction.com

Group subtypes for Elgg

  Sources   Download

GPL-2.0

The Requires

 

by Ismayil Khayredinov

plugin groups elgg subtypes

08/01 2017

1.0.5

1.0.5.0 http://hypejunction.com

Group subtypes for Elgg

  Sources   Download

GPL-2.0

The Requires

 

by Ismayil Khayredinov

plugin groups elgg subtypes

05/01 2017

1.0.4

1.0.4.0 http://hypejunction.com

Group subtypes for Elgg

  Sources   Download

GPL-2.0

The Requires

 

by Ismayil Khayredinov

plugin groups elgg subtypes

15/12 2016

1.0.3

1.0.3.0 http://hypejunction.com

Group subtypes for Elgg

  Sources   Download

GPL-2.0

The Requires

 

by Ismayil Khayredinov

plugin groups elgg subtypes

08/03 2016

1.11.x-dev

1.11.9999999.9999999-dev http://hypejunction.com

Group subtypes for Elgg

  Sources   Download

GPL-2.0

The Requires

 

by Ismayil Khayredinov

plugin groups elgg subtypes

22/02 2016

1.0.2

1.0.2.0 http://hypejunction.com

Group subtypes for Elgg

  Sources   Download

GPL-2.0

The Requires

 

by Ismayil Khayredinov

plugin groups elgg subtypes

18/02 2016

1.0.1

1.0.1.0 http://hypejunction.com

Group subtypes for Elgg

  Sources   Download

GPL-2.0

The Requires

 

by Ismayil Khayredinov

plugin groups elgg subtypes

18/02 2016

1.0.0

1.0.0.0 http://hypejunction.com

Group subtypes for Elgg

  Sources   Download

GPL-2.0

The Requires

 

by Ismayil Khayredinov

plugin groups elgg subtypes