Skip to content

Commit

Permalink
Update Entity Reference to 7.x-1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Hunt committed Feb 11, 2023
1 parent bc09ed9 commit 01e08d0
Show file tree
Hide file tree
Showing 15 changed files with 621 additions and 38 deletions.
2 changes: 2 additions & 0 deletions docroot/sites/all/modules/contrib/entityreference/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.diff
*.patch
103 changes: 91 additions & 12 deletions docroot/sites/all/modules/contrib/entityreference/README.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,95 @@
DESCRIPTION
===========
Provides a field type that can reference arbitrary entities.
CONTENTS OF THIS FILE
---------------------

SITE BUILDERS
=============
Note that when using a select widget, Entity reference loads all the
entities in that list in order to get the entity's label. If there are
too many loaded entities that site might reach its memory limit and crash
(also known as WSOD). In such a case you are advised to change the widget
to "autocomplete". If you get a WSOD when trying to edit the field
settings, you can reach the widget settings directly by navigation to
* Introduction
* Requirements
* Installation
* Recommended Modules
* Configuration
* Maintainers

admin/structure/types/manage/[ENTITY-TYPE]/fields/[FIELD-NAME]/widget-type

INTRODUCTION
------------

The Entity Reference module provides a field that can reference other entities.

* For a full description of the module visit
https://www.drupal.org/project/entityreference

* To submit bug reports and feature suggestions, or to track changes visit
https://www.drupal.org/project/issues/entityreference


REQUIREMENTS
------------

This module requires the following modules:

* Entity API - https://www.drupal.org/project/entity
* Chaos tool suite (ctools) - https://www.drupal.org/project/ctools


RECOMMENDED MODULES
-------------------

Modules extending Entity reference functionality:

* Entity Reference View Widget -
https://www.drupal.org/project/entityreference_view_widget
* Entityreference Prepopulate -
https://www.drupal.org/project/entityreference_prepopulate
* Inline Entity Form - https://www.drupal.org/project/inline_entity_form


INSTALLATION
------------

* Install the Entity Reference module as you would normally install a
contributed Drupal module. Visit https://www.drupal.org/node/895232 for
further information.


CONFIGURATION
--------------

1. Navigate to Administration > Modules and enable the Entity Reference
module and its dependencies.
2. To add an entity reference field to a node, navigate to Administration >
Structure > Content types > [content type to edit] > Manage fields and
add a new field. Add a title and select the entity reference field type.
Select a widget: Select list, Autocomplete (Tags style), Autocomplete, or
Check boxes/radio buttons. Save.
3. From the Field Setting tab select the entity reference "Target type":
Node, Comment, File, User, Taxonomy term, or Taxonomy vocabulary.
4. From the Field Setting tab select select the Entity Selection Mode -
Simple (with optional filter by bundle) is the default. Select how to
Sort: Don't sort, A property of the base table of the entity, or A field
attached to this entity. Select the sort field or property and the sort
direction. Save.
Now when authoring content there is an option to make reference to another
entity.


Note that when using a select widget, Entity reference loads all the entities
in that list in order to get the entity's label. If there are too many loaded
entities that site might reach its memory limit and crash(also known as WSOD).
In such a case you are advised to change the widget to "autocomplete". If you
get a WSOD when trying to edit the field settings, you can reach the widget
settings directly by navigation to:

* admin/structure/types/manage/[ENTITY-TYPE]/fields/[FIELD-NAME]/widget-type

Replace ENTITY-TYPE and FIELD_NAME with the correct values.

MAINTAINERS
-----------

* Mathew Winstone (minorOffense) - https://www.drupal.org/u/minoroffense
* Bojan Živanović (bojanz) - https://www.drupal.org/u/bojanz
* David Pascoe-Deslauriers (spotzero) - https://www.drupal.org/u/spotzero
* Amitai Burstein (amitaibu) - https://www.drupal.org/u/amitaibu

Supporting organizations:

* Coldfront Labs Inc. - https://www.drupal.org/coldfront-labs-inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ files[] = views/entityreference_plugin_row_fields.inc
files[] = tests/entityreference.handlers.test
files[] = tests/entityreference.taxonomy.test
files[] = tests/entityreference.admin.test
files[] = tests/entityreference.form.test
files[] = tests/entityreference.feeds.test
files[] = tests/entityreference.field.test
files[] = tests/entityreference.entity_translation.test

; Information added by Drupal.org packaging script on 2017-08-16
version = "7.x-1.5"
; Information added by Drupal.org packaging script on 2023-02-10
version = "7.x-1.6"
core = "7.x"
project = "entityreference"
datestamp = "1502895850"

datestamp = "1676069720"
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,15 @@ function entityreference_update_7002() {
}

/**
* Implements hook_update_N().
*
* Remove duplicate rows in the taxonomy_index table.
*/
function entityreference_update_7100() {
if (db_table_exists('taxonomy_index')) {
if (db_table_exists('taxonomy_index') &&
($tx_schema = drupal_get_schema('taxonomy_index'))) {
if (db_table_exists('taxonomy_index_tmp')) {
db_drop_table('taxonomy_index_tmp');
}

$tx_schema = drupal_get_schema('taxonomy_index');
db_create_table('taxonomy_index_tmp', $tx_schema);
$select = db_select('taxonomy_index', 'tx');
$select->fields('tx', array('nid', 'tid'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function entityreference_behavior_plugin_process(&$plugin, $info) {
function entityreference_field_info() {
$field_info['entityreference'] = array(
'label' => t('Entity Reference'),
'description' => t('This field reference another entity.'),
'description' => t('This field references another entity.'),
'settings' => array(
// Default to the core target entity type node.
'target_type' => 'node',
Expand Down Expand Up @@ -194,7 +194,12 @@ function _entityreference_get_behavior_handler($behavior) {
ctools_include('plugins');
$class = ctools_plugin_load_class('entityreference', 'behavior', $behavior, 'class');

$class = class_exists($class) ? $class : 'EntityReference_BehaviorHandler_Broken';
// Ensure the class is available, setting it as broken if it isn't.
if (!$class || !class_exists($class)) {
include_once(dirname(__FILE__) . '/plugins/behavior/abstract.inc');
$class = 'EntityReference_BehaviorHandler_Broken';
}

$object_cache[$behavior] = new $class($behavior);
}

Expand All @@ -209,7 +214,7 @@ function entityreference_get_selection_handler($field, $instance = NULL, $entity
$handler = $field['settings']['handler'];
$class = ctools_plugin_load_class('entityreference', 'selection', $handler, 'class');

if (class_exists($class)) {
if ($class && class_exists($class)) {
return call_user_func(array($class, 'getInstance'), $field, $instance, $entity_type, $entity);
}
else {
Expand Down Expand Up @@ -736,6 +741,7 @@ function entityreference_field_widget_info() {
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => 60,
'hide_ids' => FALSE,
// We don't have a default here, because it's not the same between
// the two widgets, and the Field API doesn't update default
// settings when the widget changes.
Expand All @@ -750,6 +756,7 @@ function entityreference_field_widget_info() {
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => 60,
'hide_ids' => FALSE,
// We don't have a default here, because it's not the same between
// the two widgets, and the Field API doesn't update default
// settings when the widget changes.
Expand Down Expand Up @@ -800,6 +807,12 @@ function entityreference_field_widget_settings_form($field, $instance) {
'#element_validate' => array('_element_validate_integer_positive'),
'#required' => TRUE,
);
$form['hide_ids'] = array(
'#type' => 'checkbox',
'#title' => t('Hide IDs'),
'#description' => t('If your target entities have unique labels you may choose not to have the IDs shown to the user. Note that this setting will make it impossible to reference entities with non-unique labels!'),
'#default_value' => $settings['hide_ids'],
);
}

return $form;
Expand Down Expand Up @@ -875,7 +888,7 @@ function entityreference_field_widget_form(&$form, &$form_state, $field, $instan

foreach ($entities as $entity_id => $entity_item) {
$label = $handler->getLabel($entity_item);
$key = "$label ($entity_id)";
$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 @@ -1116,7 +1129,7 @@ function entityreference_autocomplete_callback_get_matches($type, $field, $insta
if ($label == $denied_label) {
continue;
}
$key = "$label ($entity_id)";
$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 Expand Up @@ -1184,6 +1197,7 @@ function entityreference_field_formatter_info() {
'view_mode' => 'default',
'links' => TRUE,
'use_content_language' => TRUE,
'hide_title' => FALSE,
),
),
);
Expand Down Expand Up @@ -1241,6 +1255,11 @@ function entityreference_field_formatter_settings_form($field, $instance, $view_
'#title' => t('Use current content language'),
'#default_value' => $settings['use_content_language'],
);
$element['hide_title'] = array(
'#type' => 'checkbox',
'#title' => t('Hide title'),
'#default_value' => $settings['hide_title'],
);
}

return $element;
Expand Down Expand Up @@ -1270,6 +1289,7 @@ function entityreference_field_formatter_settings_summary($field, $instance, $vi
$summary[] = t('Rendered as @mode', array('@mode' => $view_mode_label));
$summary[] = !empty($settings['links']) ? t('Display links') : t('Do not display links');
$summary[] = !empty($settings['use_content_language']) ? t('Use current content language') : t('Use field language');
$summary[] = !empty($settings['hide_title']) ? t('Hide Title') : t('Show Title');
}

return implode('<br />', $summary);
Expand Down Expand Up @@ -1415,9 +1435,9 @@ function entityreference_field_formatter_view($entity_type, $entity, $field, $in

$target_entity = clone $item['entity'];
unset($target_entity->content);
$result[$delta] = entity_view($target_type, array($item[$column] => $target_entity), $settings['view_mode'], $target_langcode, FALSE);
$result[$delta] = entity_view($target_type, array($item[$column] => $target_entity), $settings['view_mode'], $target_langcode, !empty($settings['hide_title']));

if (empty($settings['links']) && isset($result[$delta][$target_type][$column]['links'])) {
if (empty($settings['links']) && isset($result[$delta][$target_type][$item[$column]]['links'])) {
$result[$delta][$target_type][$item[$column]]['links']['#access'] = FALSE;
}
$depth = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ core = 7.x
package = Fields
dependencies[] = entityreference

; Information added by Drupal.org packaging script on 2017-08-16
version = "7.x-1.5"
; Information added by Drupal.org packaging script on 2023-02-10
version = "7.x-1.6"
core = "7.x"
project = "entityreference"
datestamp = "1502895850"

datestamp = "1676069720"
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ abstract class EntityReference_BehaviorHandler_Abstract implements EntityReferen
* A broken implementation of EntityReference_BehaviorHandler.
*/
class EntityReference_BehaviorHandler_Broken extends EntityReference_BehaviorHandler_Abstract {
public $behavior;
public $plugin;

public function settingsForm($field, $instance) {
$form['behavior_handler'] = array(
'#markup' => t('The selected behavior handler is broken.'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
*/
class EntityReference_SelectionHandler_Generic implements EntityReference_SelectionHandler {

public $field;
public $instance;
public $entity_type;
public $entity;

/**
* Implements EntityReferenceHandler::getInstance().
*/
Expand All @@ -17,6 +22,8 @@ public static function getInstance($field, $instance = NULL, $entity_type = NULL
// Check if the entity type does exist and has a base table.
$entity_info = entity_get_info($target_entity_type);
if (empty($entity_info['base table'])) {
// Make sure the EntityReference_SelectionHandler_Broken class is available.
include_once(dirname(__FILE__) . '/abstract.inc');
return EntityReference_SelectionHandler_Broken::getInstance($field, $instance);
}

Expand Down Expand Up @@ -155,10 +162,16 @@ public static function settingsForm($field, $instance) {
/**
* Implements EntityReferenceHandler::getReferencableEntities().
*/
public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
public function getReferencableEntities($match = '', $match_operator = 'CONTAINS', $limit = 0) {
$options = array();
$entity_type = $this->field['settings']['target_type'];

if (is_null($match)) {
$match = '';
}
// Remove escape formatting.
$match = trim(str_replace('""', '"', $match));

$query = $this->buildEntityFieldQuery($match, $match_operator);
if ($limit > 0) {
$query->range(0, $limit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
*/
class EntityReference_SelectionHandler_Views implements EntityReference_SelectionHandler {

public $field;
public $instance;
public $entity;
public $view;

/**
* Implements EntityReferenceHandler::getInstance().
*/
Expand Down Expand Up @@ -56,7 +61,7 @@ public static function settingsForm($field, $instance) {
$description = t('Provide a comma separated list of arguments to pass to the view.') . '<br />' . t('This field supports tokens.');

if (!module_exists('token')) {
$description .= '<br>' . t('Install the <a href="@url">token module</a> to get more tokens and display available once.', array('@url' => 'http://drupal.org/project/token'));
$description .= '<br>' . t('Install the <a href="@url">token module</a> to get more tokens and display available ones.', array('@url' => 'http://drupal.org/project/token'));
}

$form['view']['args'] = array(
Expand Down Expand Up @@ -170,7 +175,38 @@ function validateReferencableEntities(array $ids) {
* Implements EntityReferenceHandler::validateAutocompleteInput().
*/
public function validateAutocompleteInput($input, &$element, &$form_state, $form) {
return NULL;
$bundled_entities = $this->getReferencableEntities($input, '=', 6);
$entities = array();
foreach ($bundled_entities as $entities_list) {
$entities += $entities_list;
}
if (empty($entities)) {
// Error if there are no entities available for a required field.
form_error($element, t('No items found for %label', array('%label' => $element['#title'])));
}
elseif (count($entities) > 5) {
// Error if there are more than 5 matching entities.
form_error($element, t('Too many items found for %label. Specify the one you want by appending the id in parentheses, like "@value (@id)"', array(
'%label' => $element['#title'],
'@value' => $input,
'@id' => key($entities),
)));
}
elseif (count($entities) > 1) {
// More helpful error if there are only a few matching entities.
$multiples = array();
foreach ($entities as $id => $name) {
$multiples[] = filter_xss($name, array()) . ' (' . (int) $id . ')';
}
form_error($element, t('Multiple items found for %label: !multiple', array(
'%label' => $element['#title'],
'!multiple' => theme('item_list', array('items' => $multiples)),
)));
}
else {
// Take the one and only matching entity.
return (int) key($entities);
}
}

/**
Expand Down
Loading

0 comments on commit 01e08d0

Please sign in to comment.