2017 © Pedro Peláez
 

elgg-plugin elgg_tokeninput

Tokenizing autocomplete for Elgg

image

hypejunction/elgg_tokeninput

Tokenizing autocomplete for Elgg

  • Friday, December 16, 2016
  • by hypeJunction
  • Repository
  • 8 Watchers
  • 11 Stars
  • 469 Installations
  • PHP
  • 8 Dependents
  • 1 Suggesters
  • 5 Forks
  • 3 Open issues
  • 14 Versions
  • 0 % Grown

The README.md

Tokenizing Autocomplete for Elgg

Elgg 2.0, (*1)

Replacement for Elgg's core autocomplete and userpicker, (*2)

Screenshots

alt text, (*3)

Features

  • User-friendly autocomplete and userpicker inputs
  • Works with entities and meta tags
  • Developer-friendly
  • Single and multiple selection
  • Free tagging
  • Drag&Drop sorting of tokens

Notes

I/O

Default behavior of the JS plugin is to implode user input into a comma-separated string. PHP plugin hook for 'action', 'all' will attempt to explode these values and feed them back into an action for further processing. This however, will only work with basic form input names, e.g. name="field_name" If you are working with more complex forms, where e.g. name="field_name[element_name]", you will need to add some custom logic to your action., (*4)

AJAX requests

To initialize a tokeninput upon successfull AJAX request, use $('.elgg-input-tokeninput').trigger('initialize');, (*5)

Results and Token Format

Server Side

Use 'tokeninput:entity:export', $entity_type plugin hook to modify json output. You can add 'html_result' and 'html_token' parameters to customize the output., (*6)

Client Side

Use 'results:formatter', 'tokeninput' and 'results:formatter', 'tokeninput' hooks., (*7)

Examples

Example 1

Create an input that would allow users to search and select multiple files to be attached to an entity:, (*8)

Add an input to the form:, (*9)

echo elgg_view('input/tokeninput', array(
        'value' => $current_attachment_guids, // An array of values (guids or entities) to pre-populate the input with
        'name' => 'attachment_guids',
        'callback' => 'my_search_files_callback',
        'query' => array('simpletype' => 'image'),
        'multiple' => true
    ));

Add a callback function:, (*10)

function my_search_files_callback($query, $options = array()) {

    $user = elgg_get_logged_in_user_entity();
    $simpletype = get_input('simpletype');

    $query = sanitize_string($query);

    // replace mysql vars with escaped strings
    $q = str_replace(array('_', '%'), array('\_', '\%'), $query);

    $dbprefix = elgg_get_config('dbprefix');

    $options['types'] = array('object');
    $options['subtypes'] = array('file');
    $options['joins'][] = "JOIN {$dbprefix}objects_entity oe ON oe.guid = e.guid";
    $options['wheres'][] = "oe.title LIKE '%$q%'";
    $options['wheres'][] = "e.owner_guid = $user->guid";

    if ($simpletype) {
        $options['metadata_name_value_pairs'] = array(
            'name' => 'simpletype', 'value' => $simpletype
        );
    }

    return elgg_get_entities_from_metadata($options);

}

In your action file:, (*11)

$attachment_guids = get_input('attachment_guids');
if (is_string($attachment_guids)) {
    $attachment_guids = explode(',', $attachment_guids);
}
if (is_array($attachment_guids)) {
    foreach ($attachment_guids as $attachment_guid) {
        make_attachment($entity->guid, $attachment_guid);
    }
}

Upgrades

To 4.x

  • elgg.tokeninput library has been removed. elgg_load_library('elgg.tokeninput') calls will WSOD, just remove them, (*12)

  • tokeninput/init AMD module has been removed. Tokeninput is bootstrapped as needed on page load and on ajax requests., (*13)

  • define('ELGG_TOKENINPUT_PAGEHANDLER', 'tokeninput'); has been removed. If you need to modify page handler identifier, unregister the page handler and register a new one, (*14)

Attributions / Credits

  • jquery.tokeninput http://loopj.com/jquery-tokeninput/

The Versions

16/12 2016

dev-master

9999999-dev http://hypejunction.com

Tokenizing autocomplete for Elgg

  Sources   Download

GPL-2.0

The Requires

  • bower-asset/jquery-tokeninput ~1.7.0

 

The Development Requires

by Ismayil Khayredinov

plugin search autocomplete elgg

16/12 2016

4.1.3

4.1.3.0 http://hypejunction.com

Tokenizing autocomplete for Elgg

  Sources   Download

GPL-2.0

The Requires

  • bower-asset/jquery-tokeninput ~1.7.0

 

The Development Requires

by Ismayil Khayredinov

plugin search autocomplete elgg

03/08 2016

4.1.2

4.1.2.0 http://hypejunction.com

Tokenizing autocomplete for Elgg

  Sources   Download

GPL-2.0

The Requires

  • bower-asset/jquery-tokeninput ~1.7.0

 

The Development Requires

by Ismayil Khayredinov

plugin search autocomplete elgg

03/08 2016

3.x-dev

3.9999999.9999999.9999999-dev http://hypejunction.com

Tokenizing autocomplete for Elgg

  Sources   Download

GPL-2.0

The Development Requires

by Ismayil Khayredinov

plugin search autocomplete elgg

16/06 2016

4.1.1

4.1.1.0 http://hypejunction.com

Tokenizing autocomplete for Elgg

  Sources   Download

GPL-2.0

The Requires

  • bower-asset/jquery-tokeninput ~1.7.0

 

The Development Requires

by Ismayil Khayredinov

plugin search autocomplete elgg

09/02 2016

4.1.0

4.1.0.0 http://hypejunction.com

Tokenizing autocomplete for Elgg

  Sources   Download

GPL-2.0

The Requires

  • bower-asset/jquery-tokeninput ~1.7.0

 

The Development Requires

by Ismayil Khayredinov

plugin search autocomplete elgg

24/01 2016

4.0.2

4.0.2.0 http://hypejunction.com

Tokenizing autocomplete for Elgg

  Sources   Download

GPL-2.0

The Requires

  • bower-asset/jquery-tokeninput ~1.7.0

 

The Development Requires

by Ismayil Khayredinov

plugin search autocomplete elgg

24/01 2016

3.3.2

3.3.2.0 http://hypejunction.com

Tokenizing autocomplete for Elgg

  Sources   Download

GPL-2.0

The Development Requires

by Ismayil Khayredinov

plugin search autocomplete elgg

24/01 2016

3.3.1

3.3.1.0 http://hypejunction.com

Tokenizing autocomplete for Elgg

  Sources   Download

GPL-2.0

The Development Requires

by Ismayil Khayredinov

plugin search autocomplete elgg

08/10 2015

4.0.1

4.0.1.0 http://hypejunction.com

Tokenizing autocomplete for Elgg

  Sources   Download

GPL-2.0

The Requires

  • bower-asset/jquery-tokeninput ~1.7.0

 

The Development Requires

by Ismayil Khayredinov

plugin search autocomplete elgg

28/07 2015

3.2.0

3.2.0.0 http://hypejunction.com

Tokenizing autocomplete for Elgg

  Sources   Download

GPL-2.0

The Requires

 

by Ismayil Khayredinov

plugin search autocomplete elgg

28/07 2015

3.3.0

3.3.0.0 http://hypejunction.com

Tokenizing autocomplete for Elgg

  Sources   Download

GPL-2.0

The Requires

 

by Ismayil Khayredinov

plugin search autocomplete elgg

23/06 2015

3.1.0

3.1.0.0 http://hypejunction.com

Tokenizing autocomplete for Elgg

  Sources   Download

GPL-2.0

The Requires

 

by Ismayil Khayredinov

plugin search autocomplete elgg

15/01 2015

3.0.1

3.0.1.0 http://hypejunction.com

Tokenizing autocomplete for Elgg

  Sources   Download

GPL-2.0

The Requires

 

by Ismayil Khayredinov

plugin search autocomplete elgg