2 * @file entity_browser.entity_reference.js
4 * Defines the behavior of the entity reference widget that utilizes entity
8 (function ($, Drupal) {
13 * Registers behaviours related to entity reference field widget.
15 Drupal.behaviors.entityBrowserEntityReference = {
16 attach: function (context) {
17 $(context).find('.field--widget-entity-browser-entity-reference').each(function () {
18 $(this).find('.entities-list.sortable').sortable({
19 stop: Drupal.entityBrowserEntityReference.entitiesReordered
25 Drupal.entityBrowserEntityReference = {};
28 * Reacts on sorting of the entities.
30 * @param {object} event
33 * Object with detailed information about the sort event.
35 Drupal.entityBrowserEntityReference.entitiesReordered = function (event, ui) {
36 var items = $(this).find('.item-container');
38 for (var i = 0; i < items.length; i++) {
39 ids[i] = $(items[i]).attr('data-entity-id');
42 $(this).parent().parent().find('input[type*=hidden][name*="[target_id]"]').val(ids.join(' '));