uppdated modules

This commit is contained in:
Bachir Soussi Chiadmi
2017-01-22 16:19:36 +01:00
parent 03be8f82aa
commit 8416e3eea1
748 changed files with 32317 additions and 20900 deletions
View File
@@ -19,9 +19,13 @@ function _entityreference_devel_generate($object, $field, $instance, $bundle) {
// Get all the entity that are referencable here.
$referencable_entity = entityreference_get_selection_handler($field, $instance)->getReferencableEntities();
if (is_array($referencable_entity) && !empty($referencable_entity)) {
// Get a random key.
foreach ($referencable_entity as $type => $eids) {
$object_field['target_id'] = array_rand($eids);
// $referencable_entity is keyed by bundle type.
$random_bundle = array_rand($referencable_entity);
if (!empty($random_bundle)) {
$target_id = array_rand($referencable_entity[$random_bundle]);
if (!empty($referencable_entity[$random_bundle][$target_id])) {
$object_field['target_id'] = $target_id;
}
}
}
return $object_field;
@@ -125,10 +125,15 @@ function entityreference_feeds_set_target($source, $entity, $target, $value) {
break;
case 'label':
$options = $handler->getReferencableEntities($value, '=');
$options = reset($options);
$etids = array_keys($options);
// Use the first matching entity.
$entity_id = reset($etids);
if ($options) {
$options = reset($options);
$etids = array_keys($options);
// Use the first matching entity.
$entity_id = reset($etids);
}
else {
$entity_id = NULL;
}
break;
}
/*
@@ -1,18 +1,23 @@
name = Entity Reference
description = Provides a field that can reference other entities.
core = 7.x
package = Fields
core = 7.x
dependencies[] = entity
dependencies[] = ctools
test_dependencies[] = feeds
test_dependencies[] = views
; Migrate handler.
files[] = entityreference.migrate.inc
; Our plugins interfaces and abstract implementations.
; Plugins interfaces and abstract implementations.
files[] = plugins/selection/abstract.inc
files[] = plugins/selection/views.inc
files[] = plugins/behavior/abstract.inc
; Views integration.
files[] = views/entityreference_plugin_display.inc
files[] = views/entityreference_plugin_style.inc
files[] = views/entityreference_plugin_row_fields.inc
@@ -22,10 +27,11 @@ files[] = tests/entityreference.handlers.test
files[] = tests/entityreference.taxonomy.test
files[] = tests/entityreference.admin.test
files[] = tests/entityreference.feeds.test
files[] = tests/entityreference.entity_translation.test
; Information added by packaging script on 2013-11-20
version = "7.x-1.1"
; Information added by Drupal.org packaging script on 2016-09-19
version = "7.x-1.2"
core = "7.x"
project = "entityreference"
datestamp = "1384973110"
datestamp = "1474306740"
@@ -41,6 +41,7 @@ function entityreference_field_schema($field) {
}
// Invoke the behaviors to allow them to change the schema.
module_load_include('module', 'entityreference');
foreach (entityreference_get_behavior_handlers($field) as $handler) {
$handler->schema_alter($schema, $field);
}
@@ -161,4 +162,4 @@ function entityreference_update_7002() {
'not null' => TRUE,
));
}
}
}
@@ -1,12 +1,11 @@
<?php
/**
* @file
* Support for processing entity reference fields in Migrate.
*/
/**
* Implement hook_migrate_api().
* Implements hook_migrate_api().
*/
function entityreference_migrate_api() {
return array(
@@ -15,7 +14,14 @@ function entityreference_migrate_api() {
);
}
/**
* Extended class for handling entityreference fields.
*/
class MigrateEntityReferenceFieldHandler extends MigrateSimpleFieldHandler {
/**
* Constructor.
*/
public function __construct() {
parent::__construct(array(
'value_key' => 'target_id',
@@ -220,13 +220,15 @@ function entityreference_field_validate($entity_type, $entity, $field, $instance
if ($ids) {
$valid_ids = entityreference_get_selection_handler($field, $instance, $entity_type, $entity)->validateReferencableEntities(array_keys($ids));
$invalid_entities = array_diff_key($ids, array_flip($valid_ids));
if ($invalid_entities) {
foreach ($invalid_entities as $id => $delta) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'entityreference_invalid_entity',
'message' => t('The referenced entity (@type: @id) is invalid.', array('@type' => $field['settings']['target_type'], '@id' => $id)),
);
if (!empty($valid_ids)) {
$invalid_entities = array_diff_key($ids, array_flip($valid_ids));
if ($invalid_entities) {
foreach ($invalid_entities as $id => $delta) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'entityreference_invalid_entity',
'message' => t('The referenced entity (@type: @id) is invalid.', array('@type' => $field['settings']['target_type'], '@id' => $id)),
);
}
}
}
}
@@ -1094,6 +1096,7 @@ function entityreference_field_formatter_info() {
'settings' => array(
'view_mode' => 'default',
'links' => TRUE,
'use_content_language' => TRUE,
),
),
);
@@ -1105,6 +1108,7 @@ function entityreference_field_formatter_info() {
function entityreference_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
if ($display['type'] == 'entityreference_label') {
$element['link'] = array(
@@ -1136,6 +1140,12 @@ function entityreference_field_formatter_settings_form($field, $instance, $view_
'#title' => t('Show links'),
'#default_value' => $settings['links'],
);
$element['use_content_language'] = array(
'#type' => 'checkbox',
'#title' => t('Use current content language'),
'#default_value' => $settings['use_content_language'],
);
}
return $element;
@@ -1162,6 +1172,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');
}
return implode('<br />', $summary);
@@ -1195,7 +1206,7 @@ function entityreference_field_formatter_prepare_view($entity_type, $entities, $
foreach ($items[$id] as $delta => $item) {
// Check whether the referenced entity could be loaded.
if (isset($target_entities[$item['target_id']])) {
if (isset($item['target_id']) && isset($target_entities[$item['target_id']])) {
// Replace the instance value with the term data.
$items[$id][$delta]['entity'] = $target_entities[$item['target_id']];
// Check whether the user has access to the referenced entity.
@@ -1255,6 +1266,11 @@ function entityreference_field_formatter_view($entity_type, $entity, $field, $in
break;
case 'entityreference_entity_view':
$target_langcode = $langcode;
if (!empty($settings['use_content_language']) && !empty($GLOBALS['language_content']->language)) {
$target_langcode = $GLOBALS['language_content']->language;
}
foreach ($items as $delta => $item) {
// Protect ourselves from recursive rendering.
static $depth = 0;
@@ -1263,9 +1279,9 @@ function entityreference_field_formatter_view($entity_type, $entity, $field, $in
throw new EntityReferenceRecursiveRenderingException(t('Recursive rendering detected when rendering entity @entity_type(@entity_id). Aborting rendering.', array('@entity_type' => $entity_type, '@entity_id' => $item['target_id'])));
}
$entity = clone $item['entity'];
unset($entity->content);
$result[$delta] = entity_view($field['settings']['target_type'], array($item['target_id'] => $entity), $settings['view_mode'], $langcode, FALSE);
$target_entity = clone $item['entity'];
unset($target_entity->content);
$result[$delta] = entity_view($field['settings']['target_type'], array($item['target_id'] => $target_entity), $settings['view_mode'], $target_langcode, FALSE);
if (empty($settings['links']) && isset($result[$delta][$field['settings']['target_type']][$item['target_id']]['links'])) {
$result[$delta][$field['settings']['target_type']][$item['target_id']]['links']['#access'] = FALSE;
@@ -4,9 +4,9 @@ core = 7.x
package = Fields
dependencies[] = entityreference
; Information added by packaging script on 2013-11-20
version = "7.x-1.1"
; Information added by Drupal.org packaging script on 2016-09-19
version = "7.x-1.2"
core = "7.x"
project = "entityreference"
datestamp = "1384973110"
datestamp = "1474306740"
@@ -339,9 +339,11 @@ class EntityReference_SelectionHandler_Generic implements EntityReference_Select
// Join the known base-table.
$target_type = $this->field['settings']['target_type'];
$entity_info = entity_get_info($target_type);
$target_type_base_table = $entity_info['base table'];
$id = $entity_info['entity keys']['id'];
// Return the alias of the table.
return $query->innerJoin($target_type, NULL, "%alias.$id = $alias.entity_id");
return $query->innerJoin($target_type_base_table, NULL, "%alias.$id = $alias.entity_id");
}
}
@@ -543,7 +545,7 @@ class EntityReference_SelectionHandler_Generic_taxonomy_term extends EntityRefer
if ($vocabulary = taxonomy_vocabulary_machine_name_load($bundle)) {
if ($terms = taxonomy_get_tree($vocabulary->vid, 0, NULL, TRUE)) {
foreach ($terms as $term) {
$options[$vocabulary->machine_name][$term->tid] = str_repeat('-', $term->depth) . check_plain($term->name);
$options[$vocabulary->machine_name][$term->tid] = str_repeat('-', $term->depth) . check_plain(entity_label('taxonomy_term', $term));
}
}
}
@@ -138,7 +138,9 @@ class EntityReference_SelectionHandler_Views implements EntityReference_Selectio
if ($this->initializeView(NULL, 'CONTAINS', 0, $ids)) {
// Get the results.
$entities = $this->view->execute_display($display_name, $args);
$result = array_keys($entities);
if (!empty($entities)) {
$result = array_keys($entities);
}
}
return $result;
}
@@ -21,7 +21,7 @@ class EntityReferenceAdminTestCase extends DrupalWebTestCase {
parent::setUp(array('field_ui', 'entity', 'ctools', 'entityreference'));
// Create test user.
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer content types'));
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer fields'));
$this->drupalLogin($this->admin_user);
// Create content type, with underscores.
@@ -68,7 +68,7 @@ class EntityReferenceAdminTestCase extends DrupalWebTestCase {
'fields[_add_new_field][type]' => 'entityreference',
'fields[_add_new_field][widget_type]' => 'entityreference_autocomplete',
), t('Save'));
return;
// Node should be selected by default.
$this->assertFieldByName('field[settings][target_type]', 'node');
// The base handler should be selected by default.
@@ -17,6 +17,7 @@ class FeedsMapperFieldTestCase extends DrupalWebTestCase{
'name' => 'Feeds integration (field mapper)',
'description' => 'Test Feeds Mapper support for fields.',
'group' => 'Entity Reference',
'dependencies' => array('feeds'),
);
}
@@ -28,10 +29,6 @@ class FeedsMapperFieldTestCase extends DrupalWebTestCase{
module_enable(array('entityreference_feeds_test'), TRUE);
$this->resetAll();
if (!module_exists('feeds')) {
return;
}
$permissions[] = 'access content';
$permissions[] = 'administer site configuration';
$permissions[] = 'administer content types';
@@ -157,10 +154,6 @@ class FeedsMapperFieldTestCase extends DrupalWebTestCase{
* Basic test loading a double entry CSV file.
*/
public function test() {
if (!module_exists('feeds')) {
return;
}
$this->drupalLogin($this->admin_user);
$this->drupalGet('admin/structure/types/manage/article/fields');
$this->assertText('Ref - entity ID', t('Found Entity reference field %field.', array('%field' => 'field_er_id')));
@@ -8,9 +8,9 @@ dependencies[] = feeds
dependencies[] = feeds_ui
dependencies[] = entityreference
; Information added by packaging script on 2013-11-20
version = "7.x-1.1"
; Information added by Drupal.org packaging script on 2016-09-19
version = "7.x-1.2"
core = "7.x"
project = "entityreference"
datestamp = "1384973110"
datestamp = "1474306740"