Skip to content

Commit

Permalink
Update Entity Reference to 7.x-1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Hunt committed Apr 20, 2023
1 parent af9751c commit 237652d
Show file tree
Hide file tree
Showing 12 changed files with 523 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ description = Provides a field that can reference other entities.
package = Fields
core = 7.x

scripts[] = js/entityreference.js

dependencies[] = entity
dependencies[] = ctools

Expand Down Expand Up @@ -30,9 +32,10 @@ files[] = tests/entityreference.form.test
files[] = tests/entityreference.feeds.test
files[] = tests/entityreference.field.test
files[] = tests/entityreference.entity_translation.test
files[] = tests/entityreference.views.test

; Information added by Drupal.org packaging script on 2023-03-14
version = "7.x-1.7"
; Information added by Drupal.org packaging script on 2023-04-14
version = "7.x-1.9"
core = "7.x"
project = "entityreference"
datestamp = "1678809341"
datestamp = "1681490521"
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,10 @@ function entityreference_field_widget_form(&$form, &$form_state, $field, $instan

foreach ($entities as $entity_id => $entity_item) {
$label = $handler->getLabel($entity_item);
$key = $instance['widget']['settings']['hide_ids'] ? $label : "$label ($entity_id)";
$key = "$label ($entity_id)";
if (isset($instance['widget']['settings']['hide_ids'])) {
$key = $instance['widget']['settings']['hide_ids'] ? $label : "$label ($entity_id)";
}
// Labels containing commas or quotes must be wrapped in quotes.
if (strpos($key, ',') !== FALSE || strpos($key, '"') !== FALSE) {
$key = '"' . str_replace('"', '""', $key) . '"';
Expand Down Expand Up @@ -1129,7 +1132,10 @@ function entityreference_autocomplete_callback_get_matches($type, $field, $insta
if ($label == $denied_label) {
continue;
}
$key = $instance['widget']['settings']['hide_ids'] ? $label : "$label ($entity_id)";
$key = "$label ($entity_id)";
if (isset($instance['widget']['settings']['hide_ids'])) {
$key = $instance['widget']['settings']['hide_ids'] ? $label : "$label ($entity_id)";
}
// Strip starting/trailing white spaces, line breaks and tags.
$key = preg_replace('/\s\s+/', ' ', str_replace("\n", '', trim(decode_entities(strip_tags($key)))));
// Names containing commas or quotes must be wrapped in quotes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ core = 7.x
package = Fields
dependencies[] = entityreference

; Information added by Drupal.org packaging script on 2023-03-14
version = "7.x-1.7"
; Information added by Drupal.org packaging script on 2023-04-14
version = "7.x-1.9"
core = "7.x"
project = "entityreference"
datestamp = "1678809341"
datestamp = "1681490521"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(function ($) {
'use strict';
Drupal.behaviors.ACChangeEnterBehavior = {
attach: function (context, settings) {
$('input.form-autocomplete', context).once('ac-change-enter-behavior', function() {
$(this).keypress(function(e) {
var ac = $('#autocomplete');
if (e.keyCode == 13 && typeof ac[0] != 'undefined') {
e.preventDefault();
ac.each(function () {
if(this.owner.selected == false){
this.owner.selectDown();
}
this.owner.hidePopup();
});
$(this).trigger('change');
}
});
});
}
};
}(jQuery));
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,41 @@ public function getReferencableEntities($match = NULL, $match_operator = 'CONTAI
$query->fields('e');
$query->condition('e.' . $entity_info['entity keys']['id'], array_keys($result), 'IN');

foreach($query->execute() as $entity) {
foreach ($query->execute() as $entity) {
// When the bundle key is not on the 'base table', get it on the $entity
// through entity_load().
if (!empty($entity_info['entity keys']['bundle']) && empty($entity->{$entity_info['entity keys']['bundle']})) {
$loaded_entities = entity_load($target_type, array($entity->{$entity_info['entity keys']['id']}));
if (empty($loaded_entities)) {
continue;
}
$entity = reset($loaded_entities);
}
list($id,, $bundle) = entity_extract_ids($target_type, $entity);
$return[$bundle][$id] = $result[$id];
}
// Options will be flattened, so we don't need the bundle really.
$var = $return[$bundle];
$countable = (is_array($var) || $var instanceof Countable) ? TRUE : FALSE;
if ($countable && count($return[$bundle]) > 1) {
$max_children = 0;
$temp_key = drupal_random_key(10);
$return[$temp_key] = array();
foreach ($return as $bundle => $items) {
if ($bundle == $temp_key) continue;
$num_children = count($items);
$return[$temp_key] += $items;
if ($num_children > $max_children) {
$max_children = $num_children;
$max_children_key = $bundle;
}
unset($return[$bundle]);
}
$return[$max_children_key] = $return[$temp_key];
unset($return[$temp_key]);
$bundle = $max_children_key;
}
$return[$bundle] = array_replace($result, $return[$bundle]);
}
return $return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ interface EntityReference_SelectionHandler {
* A null implementation of EntityReference_SelectionHandler.
*/
class EntityReference_SelectionHandler_Broken implements EntityReference_SelectionHandler {
public $field;
public $instance;
public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL) {
return new EntityReference_SelectionHandler_Broken($field, $instance, $entity_type, $entity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Class for testing Feeds field mapper.
*/
class FeedsMapperFieldTestCase extends DrupalWebTestCase{
public $admin_user;
/**
* Test info function.
*/
Expand Down
Loading

0 comments on commit 237652d

Please sign in to comment.