Révision 5e632cae
Ajouté par Assos Assos il y a plus de 3 ans
drupal7/sites/all/modules/field_collection/field_collection.module | ||
---|---|---|
44 | 44 |
if (!isset($field['type']['#title'])) { |
45 | 45 |
continue; |
46 | 46 |
} |
47 |
if ($field['type']['#title'] == 'Field collection') { |
|
47 |
if ($field['type']['#title'] === 'Field collection') {
|
|
48 | 48 |
$form['fields'][$fieldname]['field_name']['#markup'] = |
49 | 49 |
l($form['fields'][$fieldname]['field_name']['#markup'], 'admin/structure/field-collections/' . str_replace('_', '-', $fieldname) . '/fields'); |
50 | 50 |
} |
... | ... | |
56 | 56 |
* Implements hook_ctools_plugin_directory(). |
57 | 57 |
*/ |
58 | 58 |
function field_collection_ctools_plugin_directory($module, $plugin) { |
59 |
if ($module == 'ctools') { |
|
59 |
if ($module === 'ctools') {
|
|
60 | 60 |
return 'ctools/' . $plugin; |
61 | 61 |
} |
62 | 62 |
} |
... | ... | |
164 | 164 |
*/ |
165 | 165 |
function field_collection_field_name_load($arg) { |
166 | 166 |
$field_name = strtr($arg, array('-' => '_')); |
167 |
if (($field = field_info_field($field_name)) && $field['type'] == 'field_collection') { |
|
167 |
if (($field = field_info_field($field_name)) && $field['type'] === 'field_collection') {
|
|
168 | 168 |
return $field_name; |
169 | 169 |
} |
170 | 170 |
} |
... | ... | |
232 | 232 |
|
233 | 233 |
// Add menu paths for viewing/editing/deleting field collection items. |
234 | 234 |
foreach (field_info_fields() as $field) { |
235 |
if ($field['type'] == 'field_collection') { |
|
235 |
if ($field['type'] === 'field_collection') {
|
|
236 | 236 |
$path = field_collection_field_get_path($field); |
237 | 237 |
$count = substr_count($path, '/') + 1; |
238 | 238 |
|
... | ... | |
291 | 291 |
} |
292 | 292 |
|
293 | 293 |
/** |
294 |
* Implements hook_menu_alter() to fix the field collections admin UI tabs. |
|
294 |
* Implements hook_menu_alter(). |
|
295 |
* |
|
296 |
* Fix the field collections admin UI tabs. |
|
295 | 297 |
*/ |
296 | 298 |
function field_collection_menu_alter(&$items) { |
297 | 299 |
if (isset($items['admin/structure/field-collections/%field_collection_field_name/fields']) && module_exists('field_ui')) { |
... | ... | |
369 | 371 |
// We do not support editing field collection revisions that are not used at |
370 | 372 |
// the hosts default revision as saving the host might result in a new default |
371 | 373 |
// revision. |
372 |
if ($op != 'view' && isset($item) && !$item->isInUse()) { |
|
374 |
if ($op !== 'view' && isset($item) && !$item->isInUse()) {
|
|
373 | 375 |
return FALSE; |
374 | 376 |
} |
375 | 377 |
if (user_access('edit field collections', $account)) { |
... | ... | |
381 | 383 |
if (!isset($item)) { |
382 | 384 |
return FALSE; |
383 | 385 |
} |
384 |
$op = $op == 'view' ? 'view' : 'edit'; |
|
386 |
$op = $op === 'view' ? 'view' : 'edit';
|
|
385 | 387 |
|
386 | 388 |
// Access is determined by the entity and field containing the reference. |
387 | 389 |
$field = field_info_field($item->field_name); |
388 | 390 |
$hostEntity = $item->hostEntity() !== FALSE ? $item->hostEntity() : NULL; |
389 |
$entity_access = entity_access($op == 'view' ? 'view' : 'update', $item->hostEntityType(), $hostEntity, $account); |
|
391 |
$entity_access = entity_access($op === 'view' ? 'view' : 'update', $item->hostEntityType(), $hostEntity, $account);
|
|
390 | 392 |
|
391 | 393 |
return $entity_access && field_access($op, $field, $item->hostEntityType(), $hostEntity, $account); |
392 | 394 |
} |
... | ... | |
535 | 537 |
'value' => $entity->item_id, |
536 | 538 |
'revision_id' => $entity->revision_id, |
537 | 539 |
); |
540 |
|
|
541 |
if (module_exists('pathauto')) { |
|
542 |
module_load_include('inc', 'field_collection', 'field_collection.pathauto'); |
|
543 |
field_collection_pathauto_create_alias($host_entity, $entity, 'insert'); |
|
544 |
} |
|
538 | 545 |
} |
539 | 546 |
} |
540 | 547 |
} |
... | ... | |
583 | 590 |
if (!empty($host_entity->revision) || !empty($host_entity->is_new_revision)) { |
584 | 591 |
$entity->revision = TRUE; |
585 | 592 |
// Without this cache clear entity_revision_is_default will |
586 |
// incorrectly return false here when creating a new published revision |
|
593 |
// incorrectly return false here when creating a new published |
|
594 |
// revision. |
|
587 | 595 |
if (!isset($cleared_host_entity_cache)) { |
588 | 596 |
list($entity_id) = entity_extract_ids($host_entity_type, $host_entity); |
589 | 597 |
entity_get_controller($host_entity_type)->resetCache(array($entity_id)); |
... | ... | |
614 | 622 |
'value' => $entity->item_id, |
615 | 623 |
'revision_id' => $entity->revision_id, |
616 | 624 |
); |
625 |
|
|
626 |
if (module_exists('pathauto')) { |
|
627 |
module_load_include('inc', 'field_collection', 'field_collection.pathauto'); |
|
628 |
field_collection_pathauto_create_alias($host_entity, $entity, 'update'); |
|
629 |
} |
|
617 | 630 |
} |
618 | 631 |
} |
619 | 632 |
|
... | ... | |
631 | 644 |
->fields(array('archived' => 1)) |
632 | 645 |
->condition('item_id', $ids, 'IN') |
633 | 646 |
->execute(); |
647 |
|
|
648 |
// Let other modules know about the archived items. |
|
649 |
foreach (field_collection_item_load_multiple($ids) as $un_item) { |
|
650 |
entity_get_controller('field_collection_item')->invoke('archive', $un_item); |
|
651 |
|
|
652 |
entity_get_controller('field_collection_item')->resetCache(array($un_item->item_id)); |
|
653 |
} |
|
634 | 654 |
} |
635 | 655 |
else { |
636 | 656 |
// Load items from the original entity from all languages checking which |
... | ... | |
646 | 666 |
foreach (field_collection_item_load_multiple($items_to_remove) as $un_item) { |
647 | 667 |
$un_item->updateHostEntity($host_entity, $host_entity_type); |
648 | 668 |
$un_item->deleteRevision(TRUE); |
669 |
|
|
670 |
if (module_exists('pathauto')) { |
|
671 |
pathauto_entity_path_delete_all('field_collection_item', $un_item); |
|
672 |
} |
|
649 | 673 |
} |
650 | 674 |
} |
651 | 675 |
} |
... | ... | |
689 | 713 |
$hostEntity->field_collection_deleting = TRUE; |
690 | 714 |
} |
691 | 715 |
} |
716 |
|
|
717 |
if (module_exists('pathauto')) { |
|
718 |
pathauto_path_delete_all('field-collection/' . str_replace('_', '-', $field['field_name']) . '/' . $id); |
|
719 |
} |
|
692 | 720 |
} |
693 | 721 |
|
694 | 722 |
entity_delete_multiple('field_collection_item', $ids); |
... | ... | |
752 | 780 |
} |
753 | 781 |
|
754 | 782 |
/** |
755 |
* Determines whether a field collection item entity is empty based on the collection-fields. |
|
783 |
* Determines whether a field collection item entity is empty based on the |
|
784 |
* collection-fields. |
|
756 | 785 |
*/ |
757 | 786 |
function field_collection_item_is_empty(FieldCollectionItemEntity $item) { |
758 | 787 |
$instances = field_info_instances('field_collection_item', $item->field_name); |
... | ... | |
767 | 796 |
|
768 | 797 |
// Boolean fields as those are always considered non-empty, thus their |
769 | 798 |
// information is not useful and can be skipped by default. |
770 |
if (!$all_boolean && $field['type'] == 'list_boolean') { |
|
799 |
if (!$all_boolean && $field['type'] === 'list_boolean') {
|
|
771 | 800 |
continue; |
772 | 801 |
} |
773 | 802 |
|
... | ... | |
797 | 826 |
*/ |
798 | 827 |
function _field_collection_field_is_not_boolean($instance) { |
799 | 828 |
$field = field_info_field($instance['field_name']); |
800 |
return $field['type'] != 'list_boolean'; |
|
829 |
return $field['type'] !== 'list_boolean';
|
|
801 | 830 |
} |
802 | 831 |
|
803 | 832 |
/** |
... | ... | |
846 | 875 |
$settings = $display['settings']; |
847 | 876 |
$elements = array(); |
848 | 877 |
|
849 |
if ($display['type'] != 'field_collection_fields') { |
|
878 |
if ($display['type'] !== 'field_collection_fields') {
|
|
850 | 879 |
$elements['add'] = array( |
851 | 880 |
'#type' => 'textfield', |
852 | 881 |
'#title' => t('Add link title'), |
... | ... | |
880 | 909 |
); |
881 | 910 |
} |
882 | 911 |
|
883 |
// Add a select form element for view_mode if viewing the rendered field_collection. |
|
912 |
// Add a select form element for view_mode if viewing the rendered |
|
913 |
// field_collection. |
|
884 | 914 |
if ($display['type'] !== 'field_collection_list') { |
885 | 915 |
|
886 | 916 |
$entity_type = entity_get_info('field_collection_item'); |
... | ... | |
933 | 963 |
static $local_entity_cache = array(); |
934 | 964 |
|
935 | 965 |
$fc_ids = array(); |
936 |
|
|
966 |
$new_items = array(); |
|
937 | 967 |
// Collect every possible term attached to any of the fieldable entities. |
938 | 968 |
foreach ($entities as $id => $entity) { |
939 | 969 |
foreach ($items[$id] as $delta => $item) { |
940 | 970 |
|
941 |
// Check if this item is in our local entity cache |
|
971 |
// Check if the entity already exists. |
|
972 |
if (isset($item['entity'])) { |
|
973 |
continue; |
|
974 |
} |
|
975 |
|
|
976 |
// Check if this item is in our local entity cache. |
|
942 | 977 |
if (isset($local_entity_cache[$item['value']])) { |
943 | 978 |
$items[$id][$delta]['field_collection'] = $local_entity_cache[$item['value']]; |
944 | 979 |
continue; |
... | ... | |
952 | 987 |
if ($fc_ids) { |
953 | 988 |
$new_entities = array(); |
954 | 989 |
$terms = field_collection_item_load_multiple($fc_ids); |
990 |
$new_items == $items; |
|
955 | 991 |
|
956 | 992 |
// Iterate through the fieldable entities again to attach the loaded |
957 | 993 |
// field collection data. |
... | ... | |
959 | 995 |
$rekey = FALSE; |
960 | 996 |
|
961 | 997 |
foreach ($items[$id] as $delta => $item) { |
962 |
// Check whether the field collection field instance value could be loaded. |
|
998 |
// Check whether the field collection field instance value could be |
|
999 |
// loaded. |
|
963 | 1000 |
if (isset($terms[$item['value']])) { |
964 | 1001 |
// Replace the instance value with the term data. |
965 | 1002 |
$e = $terms[$item['value']]; |
966 | 1003 |
$local_entity_cache[$item['value']] = $e; |
967 | 1004 |
$items[$id][$delta]['field_collection'] = $e; |
968 | 1005 |
|
969 |
foreach ($fields as $field_name => $field) {
|
|
1006 |
foreach ($fields as $field_name => $field) {
|
|
970 | 1007 |
if (isset($e->$field_name)) { |
971 | 1008 |
$field_data = $e->$field_name; |
972 | 1009 |
if (isset($field_data[$langcode])) { |
973 | 1010 |
$new_entities[$e->item_id] = $e->item_id; |
974 |
$items[$e->item_id] = $field_data[$langcode]; |
|
1011 |
$new_items[$e->item_id] = $field_data[$langcode];
|
|
975 | 1012 |
} |
976 | 1013 |
} |
977 | 1014 |
} |
978 | 1015 |
} |
979 |
// Otherwise, unset the instance value, since the field colletion entity does not exist. |
|
1016 |
// Otherwise, unset the instance value, since the field colletion entity |
|
1017 |
// does not exist. |
|
980 | 1018 |
else { |
981 |
unset($items[$id][$delta]); |
|
1019 |
unset($new_items[$id][$delta]);
|
|
982 | 1020 |
$rekey = TRUE; |
983 | 1021 |
} |
984 | 1022 |
} |
985 | 1023 |
|
986 | 1024 |
if ($rekey) { |
987 | 1025 |
// Rekey the items array. |
988 |
$items[$id] = array_values($items[$id]);
|
|
1026 |
$new_items[$id] = array_values($new_items[$id]);
|
|
989 | 1027 |
} |
990 | 1028 |
} |
991 |
|
|
992 |
field_collection_entity_preload($new_entities, $langcode, $items, $fields); |
|
1029 |
field_collection_entity_preload($new_entities, $langcode, $new_items, $fields); |
|
993 | 1030 |
} |
994 | 1031 |
} |
995 | 1032 |
|
... | ... | |
1013 | 1050 |
$output = l($field_collection->label(), $field_collection->path()); |
1014 | 1051 |
$links = array(); |
1015 | 1052 |
foreach (field_collection_get_operations($settings) as $op => $label) { |
1016 |
if ($settings[$op] && entity_access($op == 'edit' ? 'update' : $op, 'field_collection_item', $field_collection)) { |
|
1053 |
if ($settings[$op] && entity_access($op === 'edit' ? 'update' : $op, 'field_collection_item', $field_collection)) {
|
|
1017 | 1054 |
$title = entity_i18n_string("field:{$field['field_name']}:{$instance['bundle']}:setting_$op", $settings[$op]); |
1018 | 1055 |
$links[] = l($title, $field_collection->path() . '/' . $op, array('query' => drupal_get_destination())); |
1019 | 1056 |
} |
... | ... | |
1053 | 1090 |
); |
1054 | 1091 |
$links['#attributes']['class'][] = 'field-collection-view-links'; |
1055 | 1092 |
foreach (field_collection_get_operations($settings) as $op => $label) { |
1056 |
if ($settings[$op] && entity_access($op == 'edit' ? 'update' : $op, 'field_collection_item', $field_collection)) { |
|
1093 |
if ($settings[$op] && entity_access($op === 'edit' ? 'update' : $op, 'field_collection_item', $field_collection)) {
|
|
1057 | 1094 |
$links['#links'][$op] = array( |
1058 | 1095 |
'title' => entity_i18n_string("field:{$field['field_name']}:{$instance['bundle']}:setting_$op", $settings[$op]), |
1059 | 1096 |
'href' => $field_collection->path() . '/' . $op, |
... | ... | |
1124 | 1161 |
$path = field_collection_field_get_path($field); |
1125 | 1162 |
list($id) = entity_extract_ids($entity_type, $entity); |
1126 | 1163 |
$element['#suffix'] = ''; |
1127 |
if ($entity_type != 'node' && !empty($settings['description'])) { |
|
1164 |
if ($entity_type !== 'node' && !empty($settings['description'])) {
|
|
1128 | 1165 |
$element['#suffix'] .= '<div class="description field-collection-description">' . field_filter_xss($instance['description']) . '</div>'; |
1129 | 1166 |
} |
1130 | 1167 |
$title = entity_i18n_string("field:{$field['field_name']}:{$instance['bundle']}:setting_add", $settings['add']); |
1131 | 1168 |
$add_path = $path . '/add/' . $entity_type . '/' . $id; |
1132 |
$element['#suffix'] .= '<ul class="action-links action-links-field-collection-add"><li>'; |
|
1133 |
$element['#suffix'] .= l($title, $add_path, array('query' => drupal_get_destination())); |
|
1134 |
$element['#suffix'] .= '</li></ul>'; |
|
1169 |
$element['#suffix'] .= |
|
1170 |
'<ul class="action-links action-links-field-collection-add"><li>' . |
|
1171 |
l($title, $add_path, array('query' => drupal_get_destination())) . |
|
1172 |
'</li></ul>'; |
|
1135 | 1173 |
} |
1136 | 1174 |
} |
1137 | 1175 |
// If there is no add link, add a special class to the last item. |
... | ... | |
1268 | 1306 |
if (!isset($field_collection_item->entity_translation_handler_id)) { |
1269 | 1307 |
list($id, $revision_id) = entity_extract_ids('field_collection_item', $field_collection_item); |
1270 | 1308 |
$revision_id = isset($revision_id) ? $revision_id : 0; |
1271 |
$field_collection_item->entity_translation_handler_id = 'field_collection_item' . '-' . (!empty($id) ? 'eid-' . $id . '-' . $revision_id : 'new-' . rand()); |
|
1309 |
$field_collection_item->entity_translation_handler_id = 'field_collection_item' . '-' . (!empty($id) ? 'eid-' . $id . '-' . $revision_id : 'new-' . mt_rand());
|
|
1272 | 1310 |
} |
1273 | 1311 |
$element['#field_collection_item'] = $field_collection_item; |
1274 | 1312 |
field_collection_add_child_translation_handler($element); |
... | ... | |
1283 | 1321 |
} |
1284 | 1322 |
} |
1285 | 1323 |
|
1286 |
// Add the subform |
|
1324 |
// Add the subform.
|
|
1287 | 1325 |
field_form_set_state($field_parents, $field_name, $language, $form_state, $field_state); |
1288 | 1326 |
// Set the language to to parent entity language, because |
1289 | 1327 |
// field_content_languages() will always set $language to LANGUAGE_NONE. |
... | ... | |
1339 | 1377 |
$item_id = isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL; |
1340 | 1378 |
$revision_id = isset($items[$delta]['revision_id']) ? $items[$delta]['revision_id'] : NULL; |
1341 | 1379 |
|
1342 |
// add a label component to visually identify this field collection item
|
|
1380 |
// Add a label component to visually identify this field collection item.
|
|
1343 | 1381 |
$element['label'] = array(); |
1344 | 1382 |
if ($item_id) { |
1345 | 1383 |
$item = field_collection_item_load($item_id); |
1346 | 1384 |
$element['label']['#markup'] = $item ? $item->label() : $item_id; |
1347 | 1385 |
} |
1348 | 1386 |
|
1349 |
// the field stored value (item_id) and revision_id values
|
|
1350 |
// so we need hidden fields to represent them
|
|
1387 |
// The field stored value (item_id) and revision_id values so we need
|
|
1388 |
// hidden fields to represent them.
|
|
1351 | 1389 |
$element['value'] = array( |
1352 | 1390 |
'#type' => 'hidden', |
1353 | 1391 |
'#default_value' => $item_id, |
... | ... | |
1381 | 1419 |
'#title' => check_plain($instance['label']), |
1382 | 1420 |
'#required' => FALSE, |
1383 | 1421 |
'#description' => field_filter_xss($instance['description']), |
1384 |
'#max_delta' => $count-1,
|
|
1422 |
'#max_delta' => $count - 1,
|
|
1385 | 1423 |
); |
1386 | 1424 |
} |
1387 | 1425 |
|
... | ... | |
1390 | 1428 |
} |
1391 | 1429 |
|
1392 | 1430 |
/** |
1393 |
* Implements hook_entity_translation_source_field_state_alter() |
|
1431 |
* Implements hook_entity_translation_source_field_state_alter().
|
|
1394 | 1432 |
*/ |
1395 | 1433 |
function field_collection_entity_translation_source_field_state_alter(&$field_state) { |
1396 | 1434 |
if (isset($field_state['entity'])) { |
... | ... | |
1429 | 1467 |
&& field_access('edit', $field, $entity_type)) { |
1430 | 1468 |
|
1431 | 1469 |
$element_langcode = $form[$field_name]['#language']; |
1432 |
if ($form[$field_name][$element_langcode]['#max_delta'] > 0) { |
|
1470 |
if (!empty($form[$field_name][$element_langcode]['#max_delta']) && $form[$field_name][$element_langcode]['#max_delta'] > 0) {
|
|
1433 | 1471 |
$form[$field_name][$element_langcode]['#max_delta']--; |
1434 | 1472 |
} |
1435 | 1473 |
// Remove blank form elements and force user to explicitly add a field |
1436 | 1474 |
// collection if both 'hide_initial_item' and 'hide_blank_items' are TRUE. |
1437 | 1475 |
if ($field['settings']['hide_initial_item'] |
1438 | 1476 |
&& $field['settings']['hide_blank_items'] |
1477 |
&& !empty($form[$field_name][$element_langcode][0]['#entity']) |
|
1439 | 1478 |
&& $form[$field_name][$element_langcode][0]['#entity'] instanceof FieldCollectionItemEntity |
1440 | 1479 |
&& field_collection_item_is_empty($form[$field_name][$element_langcode][0]['#entity'])) { |
1441 | 1480 |
|
1442 | 1481 |
_field_collection_process_children_attached($form[$field_name][$element_langcode][0]); |
1443 |
unset($form[$field_name][$element_langcode][0]); |
|
1444 |
unset($form_state['field']['#parents'][$field_name][$element_langcode][0]); |
|
1482 |
unset( |
|
1483 |
$form[$field_name][$element_langcode][0], |
|
1484 |
$form_state['field']['#parents'][$field_name][$element_langcode][0] |
|
1485 |
); |
|
1445 | 1486 |
} |
1446 | 1487 |
} |
1447 | 1488 |
|
... | ... | |
1580 | 1621 |
} |
1581 | 1622 |
|
1582 | 1623 |
// Replace the deleted entity with an empty one. This helps to ensure that |
1583 |
// trying to add a new entity won't ressurect a deleted entity from the
|
|
1624 |
// trying to add a new entity won't resurrect a deleted entity from the
|
|
1584 | 1625 |
// trash bin. |
1585 | 1626 |
$count = count($field_state['entity']); |
1586 | 1627 |
$field_state['entity'][$count] = entity_create('field_collection_item', array('field_name' => $field_name)); |
... | ... | |
1600 | 1641 |
// the 3, the order of the two 3s now is undefined and may not match what |
1601 | 1642 |
// the user had selected. |
1602 | 1643 |
$input = drupal_array_get_nested_value($form_state['input'], $values_address); |
1603 |
// Sort by weight |
|
1644 |
// Sort by weight.
|
|
1604 | 1645 |
uasort($input, '_field_sort_items_helper'); |
1605 | 1646 |
|
1606 | 1647 |
// Reweight everything in the correct order. |
... | ... | |
1740 | 1781 |
$is_empty_multiple = $is_countable && (!count($elements['#value'])); |
1741 | 1782 |
$is_empty_string = (is_string($elements['#value']) && drupal_strlen(trim($elements['#value'])) == 0); |
1742 | 1783 |
$is_empty_value = ($elements['#value'] === 0); |
1743 |
$is_empty_option = (isset($elements['#options']['_none']) && $elements['#value'] == '_none'); |
|
1784 |
$is_empty_option = (isset($elements['#options']['_none']) && $elements['#value'] === '_none');
|
|
1744 | 1785 |
|
1745 | 1786 |
// Validate fields with hook_field_is_empty. This will handle cases when |
1746 | 1787 |
// file entity passes validation when it shouldn't. |
... | ... | |
1808 | 1849 |
* Implements hook_field_create_field(). |
1809 | 1850 |
*/ |
1810 | 1851 |
function field_collection_field_create_field($field) { |
1811 |
if ($field['type'] == 'field_collection') { |
|
1852 |
if ($field['type'] === 'field_collection') {
|
|
1812 | 1853 |
field_attach_create_bundle('field_collection_item', $field['field_name']); |
1813 | 1854 |
|
1814 | 1855 |
// Clear caches. |
... | ... | |
1824 | 1865 |
* Implements hook_field_delete_field(). |
1825 | 1866 |
*/ |
1826 | 1867 |
function field_collection_field_delete_field($field) { |
1827 |
if ($field['type'] == 'field_collection') { |
|
1868 |
if ($field['type'] === 'field_collection') {
|
|
1828 | 1869 |
// Notify field.module that field collection was deleted. |
1829 | 1870 |
field_attach_delete_bundle('field_collection_item', $field['field_name']); |
1830 | 1871 |
|
... | ... | |
1841 | 1882 |
* Implements hook_i18n_string_list_{textgroup}_alter(). |
1842 | 1883 |
*/ |
1843 | 1884 |
function field_collection_i18n_string_list_field_alter(&$properties, $type, $instance) { |
1844 |
if ($type == 'field_instance') { |
|
1885 |
if ($type === 'field_instance') {
|
|
1845 | 1886 |
$field = field_info_field($instance['field_name']); |
1846 | 1887 |
|
1847 |
if ($field['type'] == 'field_collection' && !empty($instance['display'])) { |
|
1888 |
if ($field['type'] === 'field_collection' && !empty($instance['display'])) {
|
|
1848 | 1889 |
|
1849 | 1890 |
foreach ($instance['display'] as $view_mode => $display) { |
1850 |
if ($display['type'] != 'field_collection_fields') { |
|
1851 |
$display['settings'] += array('edit' => 'edit', 'translate' => 'translate', 'delete' => 'delete', 'add' => 'add'); |
|
1891 |
if ($display['type'] !== 'field_collection_fields') { |
|
1892 |
$display['settings'] += array( |
|
1893 |
'edit' => 'edit', |
|
1894 |
'translate' => 'translate', |
|
1895 |
'delete' => 'delete', |
|
1896 |
'add' => 'add', |
|
1897 |
); |
|
1852 | 1898 |
|
1853 | 1899 |
$properties['field'][$instance['field_name']][$instance['bundle']]['setting_edit'] = array( |
1854 | 1900 |
'title' => t('Edit link title'), |
... | ... | |
1896 | 1942 |
if (!function_exists('field_instance_features_export_options')) { |
1897 | 1943 |
// Add the fields of the field collection entity to the pipe. |
1898 | 1944 |
foreach ($data as $identifier) { |
1899 |
if (($field = features_field_load($identifier)) && $field['field_config']['type'] == 'field_collection') { |
|
1945 |
if (($field = features_field_load($identifier)) && $field['field_config']['type'] === 'field_collection') {
|
|
1900 | 1946 |
$fields = field_info_instances('field_collection_item', $field['field_config']['field_name']); |
1901 | 1947 |
foreach ($fields as $name => $field) { |
1902 | 1948 |
$pipe['field'][] = "{$field['entity_type']}-{$field['bundle']}-{$field['field_name']}"; |
... | ... | |
1914 | 1960 |
function field_collection_features_pipe_field_instance_alter(&$pipe, $data, $export) { |
1915 | 1961 |
// Add the fields of the field collection entity to the pipe. |
1916 | 1962 |
foreach ($data as $identifier) { |
1917 |
if (($field = features_field_load($identifier)) && $field['field_config']['type'] == 'field_collection') { |
|
1963 |
if (($field = features_field_load($identifier)) && $field['field_config']['type'] === 'field_collection') {
|
|
1918 | 1964 |
$fields = field_info_instances('field_collection_item', $field['field_config']['field_name']); |
1919 | 1965 |
foreach ($fields as $name => $field) { |
1920 | 1966 |
$pipe['field_instance'][] = "{$field['entity_type']}-{$field['bundle']}-{$field['field_name']}"; |
... | ... | |
1968 | 2014 |
*/ |
1969 | 2015 |
function field_collection_item_get_specific_type_host_entity($item, array $options, $name) { |
1970 | 2016 |
// These properties' machine names have the form "host_entity_TYPE". |
1971 |
if (substr($name, 0, 12) !== 'host_entity_') {
|
|
2017 |
if (strpos($name, 'host_entity_') !== 0) {
|
|
1972 | 2018 |
return NULL; |
1973 | 2019 |
} |
1974 | 2020 |
return $item->hostEntityType() === substr($name, 12) ? $item->hostEntity() : NULL; |
... | ... | |
2085 | 2131 |
$field_name = $instance['field_name']; |
2086 | 2132 |
$field = field_info_field($field_name); |
2087 | 2133 |
|
2088 |
if ($field['type'] == 'field_collection') { |
|
2134 |
if ($field['type'] === 'field_collection') {
|
|
2089 | 2135 |
$field_langcode = field_is_translatable($entity_type, $field) ? $langcode : LANGUAGE_NONE; |
2090 | 2136 |
|
2091 | 2137 |
if (!empty($entity->{$field_name}[$field_langcode])) { |
... | ... | |
2134 | 2180 |
} |
2135 | 2181 |
|
2136 | 2182 |
/** |
2137 |
* implements hook_entity_translation_insert
|
|
2183 |
* Implements hook_entity_translation_insert().
|
|
2138 | 2184 |
*/ |
2139 | 2185 |
function field_collection_entity_translation_insert($entity_type, $entity, $translation, $values = array()) { |
2140 |
// Check if some of the values inserted are of a field_collection field |
|
2186 |
// Check if some of the values inserted are of a field_collection field.
|
|
2141 | 2187 |
if (!empty($values)) { |
2142 | 2188 |
foreach ($values as $field_name => $value) { |
2143 | 2189 |
$field = field_info_field($field_name); |
2144 | 2190 |
|
2145 |
if ($field['type'] == 'field_collection') { |
|
2146 |
// We have found a field collection |
|
2191 |
if ($field['type'] === 'field_collection') {
|
|
2192 |
// We have found a field collection.
|
|
2147 | 2193 |
$language = $translation['language']; |
2148 | 2194 |
$source_language = $translation['source']; |
2149 | 2195 |
|
2150 | 2196 |
if (!empty($value[$language])) { |
2151 | 2197 |
$source_items = !empty($entity->{$field_name}[$source_language]) ? field_collection_field_item_to_ids($entity->{$field_name}[$source_language]) : array(); |
2152 | 2198 |
foreach ($value[$language] as $delta => $field_value) { |
2153 |
// Check if this field collection item belongs to the source language |
|
2199 |
// Check if this field collection item belongs to the source language.
|
|
2154 | 2200 |
if (!isset($field_value['entity']) |
2155 | 2201 |
&& ($fc_entity = field_collection_field_get_entity($field_value)) |
2156 |
&& in_array($fc_entity->item_id, $source_items)) { |
|
2157 |
// Clone the field collection item |
|
2202 |
&& in_array($fc_entity->item_id, $source_items) |
|
2203 |
) { |
|
2204 |
// Clone the field collection item. |
|
2158 | 2205 |
$new_fc_entity = clone $fc_entity; |
2159 | 2206 |
$new_fc_entity->item_id = NULL; |
2160 | 2207 |
$new_fc_entity->revision_id = NULL; |
2161 | 2208 |
$new_fc_entity->is_new = TRUE; |
2162 | 2209 |
|
2163 |
// Set the new entity for saving it later |
|
2210 |
// Set the new entity for saving it later.
|
|
2164 | 2211 |
$entity->{$field_name}[$language][$delta]['entity'] = $new_fc_entity; |
2165 | 2212 |
} |
2166 | 2213 |
} |
... | ... | |
2172 | 2219 |
|
2173 | 2220 |
|
2174 | 2221 |
/** |
2175 |
* Implements hook_feeds_processor_targets_alter() |
|
2222 |
* Implements hook_feeds_processor_targets_alter().
|
|
2176 | 2223 |
*/ |
2177 | 2224 |
function field_collection_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { |
2178 | 2225 |
|
... | ... | |
2192 | 2239 |
|
2193 | 2240 |
foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) { |
2194 | 2241 |
$info = field_info_field($name); |
2195 |
if ($info['type'] == 'field_collection') { |
|
2242 |
if ($info['type'] === 'field_collection') {
|
|
2196 | 2243 |
|
2197 | 2244 |
$sub_type = 'field_collection_item'; |
2198 | 2245 |
$new_targets = module_invoke_all('feeds_processor_targets', $sub_type, $info['field_name']); |
... | ... | |
2255 | 2302 |
while (isset($value[$delta])) { |
2256 | 2303 |
|
2257 | 2304 |
// Zero out. |
2258 |
$field_collection_item = null;
|
|
2305 |
$field_collection_item = NULL;
|
|
2259 | 2306 |
|
2260 | 2307 |
// FC is already set on host entity. |
2261 | 2308 |
if (isset($field[LANGUAGE_NONE][$delta]['entity'])) { |
... | ... | |
2266 | 2313 |
$field_collection_item = field_collection_item_load($field[LANGUAGE_NONE][$delta]['value']); |
2267 | 2314 |
|
2268 | 2315 |
// Zero out field so that we don't just keep accumulating values. |
2269 |
unset($field_collection_item->{$sub_target}[LANGUAGE_NONE] );
|
|
2316 |
unset($field_collection_item->{$sub_target}[LANGUAGE_NONE]); |
|
2270 | 2317 |
} |
2271 | 2318 |
|
2272 | 2319 |
// Host entity does not have any attached FCs yet. |
... | ... | |
2279 | 2326 |
$config = $source->importer()->getConfig(); |
2280 | 2327 |
if (!empty($config['processor']['config']['mappings'])) { |
2281 | 2328 |
foreach ($config['processor']['config']['mappings'] as $mapping) { |
2282 |
if ($mapping['target'] == $target . ':' . $sub_target) { |
|
2329 |
if ($mapping['target'] === $target . ':' . $sub_target) {
|
|
2283 | 2330 |
$sub_mapping = $mapping; |
2284 | 2331 |
$sub_mapping['target'] = $sub_target; |
2285 | 2332 |
// Needs language or feeds mappers shout php notices. |
... | ... | |
2292 | 2339 |
if (isset($_sub_targets[$sub_target]['callback']) && function_exists($_sub_targets[$sub_target]['callback'])) { |
2293 | 2340 |
$callback = $_sub_targets[$sub_target]['callback']; |
2294 | 2341 |
|
2295 |
// Normalize |
|
2342 |
// Normalize.
|
|
2296 | 2343 |
if (!is_array($value[$delta])) { |
2297 | 2344 |
$value[$delta] = array($value[$delta]); |
2298 | 2345 |
} |
... | ... | |
2303 | 2350 |
} |
2304 | 2351 |
|
2305 | 2352 |
// HiJack the file callback so we can make it work. |
2306 |
if ($callback == 'file_feeds_set_target') { |
|
2353 |
if ($callback === 'file_feeds_set_target') {
|
|
2307 | 2354 |
$callback = 'field_collection_file_feeds_set_target'; |
2308 | 2355 |
} |
2309 | 2356 |
|
... | ... | |
2393 | 2440 |
watchdog('feeds', check_plain($e->getMessage())); |
2394 | 2441 |
} |
2395 | 2442 |
if ($file) { |
2396 |
$field[LANGUAGE_NONE][$i] = (array)$file; |
|
2397 |
$field[LANGUAGE_NONE][$i]['display'] = 1; // @todo: Figure out how to properly populate this field. |
|
2443 |
$field[LANGUAGE_NONE][$i] = (array) $file; |
|
2444 |
// @todo: Figure out how to properly populate this field. |
|
2445 |
$field[LANGUAGE_NONE][$i]['display'] = 1; |
|
2398 | 2446 |
if ($info['cardinality'] == 1) { |
2399 | 2447 |
break; |
2400 | 2448 |
} |
... | ... | |
2405 | 2453 |
|
2406 | 2454 |
} |
2407 | 2455 |
|
2408 |
|
|
2409 | 2456 |
/** |
2410 | 2457 |
* Implementation of hook_feeds_presave(). |
2458 |
* |
|
2411 | 2459 |
* Invoked before a feed item is saved. |
2412 | 2460 |
* |
2413 | 2461 |
* @param FeedsSource $source |
... | ... | |
2436 | 2484 |
$info = field_info_field($fc_name); |
2437 | 2485 |
|
2438 | 2486 |
// If the field is not a field collection, skip it. |
2439 |
if ($info['type'] != 'field_collection') { |
|
2487 |
if ($info['type'] !== 'field_collection') {
|
|
2440 | 2488 |
continue; |
2441 | 2489 |
} |
2442 | 2490 |
|
... | ... | |
2454 | 2502 |
} |
2455 | 2503 |
} |
2456 | 2504 |
} |
2457 |
|
Formats disponibles : Unified diff
Weekly update of contrib modules