Projet

Général

Profil

Révision 5e632cae

Ajouté par Assos Assos il y a plus de 3 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/field_collection/ctools/relationships/field_collection_from_field.inc
88 88
    }
89 89

  
90 90
    if (!empty($items) && isset($items[$delta]['value'])) {
91
      $field_collection_item = field_collection_item_load($items[$delta]['value']);
91
      return ctools_context_create('entity:field_collection_item', $items[$delta]['value']);
92 92
    }
93

  
94
    return ctools_context_create('entity:field_collection_item', $items[$delta]['value']);
95 93
  }
96 94

  
97 95
  return ctools_context_create_empty('entity:field_collection_item', NULL);
drupal7/sites/all/modules/field_collection/field-collection-item.tpl.php
28 28
 * @see template_process()
29 29
 */
30 30
?>
31
<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
31
<div <?php print $attributes; ?>>
32 32
  <div class="content"<?php print $content_attributes; ?>>
33 33
    <?php
34 34
      print render($content);
drupal7/sites/all/modules/field_collection/field_collection.api.php
113 113
    ->execute();
114 114
}
115 115

  
116
/**
117
 * Responds to field collection item archiving.
118
 *
119
 * This hook is invoked after the field collection item has been archived while
120
 * removing it from its host entity.
121
 *
122
 * @param FieldCollectionItemEntity $field_collection_item
123
 *   The field collection item that is being archived.
124
 */
125
function hook_field_collection_item_archive(FieldCollectionItemEntity $field_collection_item) {
126
  db_update('mytable')
127
    ->fields(array('archived' => 1))
128
    ->condition('id', entity_id('field_collection_item', $field_collection_item))
129
    ->execute();
130
}
131

  
116 132
/**
117 133
 * Act on a field collection item that is being assembled before rendering.
118 134
 *
drupal7/sites/all/modules/field_collection/field_collection.entity.inc
127 127
  public function translatedInstanceLabel($langcode = NULL) {
128 128
    if ($info = $this->instanceInfo()) {
129 129
      if (module_exists('i18n_field')) {
130
        return i18n_string("field:{$this->field_name}:{$info['bundle']}:label", $info['label'], array('langcode' => $langcode));
130
        return i18n_string("field:{$this->field_name}:{$info['bundle']}:label", $info['label'], array('langcode' => $langcode, 'sanitize' => FALSE));
131 131
      }
132 132
      return $info['label'];
133 133
    }
......
330 330
          $query->entityCondition('entity_type', $entity_type);
331 331
          $query->entityCondition('entity_id', $hostEntity->{$key});
332 332
          $query->entityCondition('bundle', $bundle);
333
          if (isset($entity_info['entity keys']['language'])) {
334
            $query->propertyCondition('language', $hostEntity->language);
333
          // Only filter by language if this entity type has a language key that
334
          // has a corresponding field in its base table.
335
          if (!empty($entity_info['entity keys']['language']) && !empty($entity_info['schema_fields_sql']['base table']) && in_array($entity_info['entity keys']['language'], $entity_info['schema_fields_sql']['base table'], TRUE)) {
336
            $query->propertyCondition($entity_info['entity keys']['language'], $hostEntity->{$entity_info['entity keys']['language']});
335 337
          }
336 338
        }
337 339
        $query->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
......
607 609
          ->fields(array('archived' => 1, 'revision_id' => $row['revision_id']))
608 610
          ->condition('item_id', $this->item_id)
609 611
          ->execute();
612

  
613
        // Let other modules know about the archived item.
614
        entity_get_controller('field_collection_item')->invoke('archive', $this);
615

  
610 616
        entity_get_controller('field_collection_item')->resetCache(array($this->item_id));
611 617
        entity_revision_delete('field_collection_item', $this->revision_id);
612 618
      }
......
648 654
   */
649 655
  public function __sleep() {
650 656
    $vars = get_object_vars($this);
651
    unset($vars['entityInfo'], $vars['idKey'], $vars['nameKey'], $vars['statusKey']);
652
    unset($vars['fieldInfo']);
657
    unset($vars['entityInfo'], $vars['idKey'], $vars['nameKey'], $vars['statusKey'], $vars['fieldInfo']);
653 658
    // Also do not serialize the host entity, but only if it has already an id.
654 659
    if ($this->hostEntity && ($this->hostEntityId || $this->hostEntityRevisionId)) {
655 660
      unset($vars['hostEntity']);
drupal7/sites/all/modules/field_collection/field_collection.info
12 12
configure = admin/structure/field-collections
13 13
package = Fields
14 14

  
15
; Information added by Drupal.org packaging script on 2019-09-03
16
version = "7.x-1.1"
15
; Information added by Drupal.org packaging script on 2020-12-26
16
version = "7.x-1.2"
17 17
core = "7.x"
18 18
project = "field_collection"
19
datestamp = "1567537827"
19
datestamp = "1609006493"
drupal7/sites/all/modules/field_collection/field_collection.info.inc
32 32
      foreach ($bundles as $bundle => $fields) {
33 33
        if (array_intersect_key($fields, $field_collection_fields)) {
34 34
          $args = array('@type' => $entity_types[$entity_type]['label']);
35
          $properties["host_entity_$entity_type"] = array(
35
          $properties["host_entity_{$entity_type}"] = array(
36 36
            'label' => t('Host entity (@type)', $args),
37 37
            'type' => $entity_type,
38 38
            'description' => t('The @type containing the field collection field (empty if this field collection is attached to an item of a different type).', $args),
drupal7/sites/all/modules/field_collection/field_collection.install
425 425
    ->fields('t', array("{$sandbox['field_name']}_revision_id"))
426 426
    ->range($sandbox['current_field_collection_item'], $items_per_pass)
427 427
    ->groupBy("t.{$sandbox['field_name']}_revision_id");
428
  $query->addExpression("COUNT(t.{$sandbox['field_name']}_revision_id)", 'vidcount');
429
  $query->havingCondition('vidcount', 2, '>=');
428
  $query->having("COUNT(t.{$sandbox['field_name']}_revision_id) >= 2");
430 429
  $vids = $query->execute()->fetchCol();
431 430

  
432 431
  // Each revision ID that occurs more than once.
......
488 487
        ->condition('delta', $row_to_replace->delta)
489 488
        ->condition('language', $row_to_replace->language)
490 489
        ->execute();
491
    }
492 490

  
493
    if ($field_collection_item_current_revision == $field_collection_duplicated_revision_id) {
494
      _field_collection_update_7009_update_data($new_revision_id, $field_collection_duplicated_revision_id);
491
      if ($field_collection_item_current_revision == $field_collection_duplicated_revision_id) {
492
        _field_collection_update_7009_update_data($new_revision_id, $field_collection_duplicated_revision_id);
495 493

  
496
      // Update the current field collection item data in its host.
497
      db_update("field_data_{$sandbox['field_name']}")
498
        ->fields(array('revision_id' => $new_revision))
499
        ->condition('revision_id', $old_revision)
500
        ->condition('entity_type', $row_to_replace->entity_type)
501
        ->execute();
494
        // Update the current field collection item data in its host.
495
        db_update("field_data_{$sandbox['field_name']}")
496
          ->fields(array('revision_id' => $new_revision_id))
497
          ->condition('revision_id', $field_collection_duplicated_revision_id)
498
          ->condition('entity_type', $row_to_replace->entity_type)
499
          ->execute();
500
      }
502 501
    }
503 502

  
503

  
504

  
504 505
    foreach ($modern_revisions as $each_modern_revision) {
505 506
      $new_revision_id = _field_collection_update_7009_new_revision($field_collection_item_id, $each_modern_revision, $sandbox['inner_fields'], $sandbox['field_name']);
506 507

  
......
523 524
        ->execute();
524 525

  
525 526
      if ($field_collection_item_current_revision == $each_modern_revision->{"{$sandbox['field_name']}_revision_id"}) {
526
        _field_collection_update_7009_update_data($new_revision_id, $each_modern_revision->{"{$sandbox['field_name']}_revision_id"});
527
        _field_collection_update_7009_update_data($new_revision_id, $field_collection_item_current_revision);
527 528

  
528 529
        // Update the current field collection item data in its host.
529 530
        db_update("field_data_{$sandbox['field_name']}")
530
          ->fields(array('revision_id' => $new_revision))
531
          ->condition('revision_id', $old_revision)
531
          ->fields(array('revision_id' => $new_revision_id))
532
          ->condition('revision_id', $field_collection_item_current_revision)
532 533
          ->condition('entity_type', $each_modern_revision->entity_type)
533 534
          ->execute();
534 535
      }
drupal7/sites/all/modules/field_collection/field_collection.migrate.inc
41 41
   */
42 42
  protected $hostEntityType;
43 43

  
44
  static public function getKeySchema() {
44
  public static function getKeySchema() {
45 45
    return array(
46 46
      'item_id' => array(
47 47
        'type' => 'int',
......
191 191
 * Implements migrate hook_migrate_api().
192 192
 */
193 193
function field_collection_migrate_api() {
194
  $api = array(
194
  return array(
195 195
    'api' => 2,
196 196
  );
197
  return $api;
198 197
}
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

  
drupal7/sites/all/modules/field_collection/field_collection.pages.inc
86 86
 */
87 87
function field_collection_item_delete_confirm_submit($form, &$form_state) {
88 88
  $field_collection_item = $form_state['field_collection_item'];
89
  entity_delete('field_collection_item',$field_collection_item->item_id);
89
  entity_delete('field_collection_item', $field_collection_item->item_id);
90 90
  drupal_set_message(t('%label has been deleted.', array('%label' => drupal_ucfirst($field_collection_item->label()))));
91 91
  $form_state['redirect'] = '<front>';
92 92
}
......
118 118
  $langcode = !empty($field['translatable']) ? entity_language($entity_type, $entity) : LANGUAGE_NONE;
119 119

  
120 120
  if (!($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || !isset($entity->{$field_name}[$langcode]) || count($entity->{$field_name}[$langcode]) < $field['cardinality'])) {
121
    drupal_set_message(t('Too many items.'), 'error');
122
    return '';
121
    return MENU_ACCESS_DENIED;
123 122
  }
124 123

  
125 124
  $field_collection_item = entity_create('field_collection_item', array('field_name' => $field_name));
......
130 129
  $field_collection_item->setHostEntity($entity_type, $entity, $langcode, FALSE);
131 130

  
132 131
  $label = $field_collection_item->translatedInstanceLabel();
133
  $title = ($field['cardinality'] == 1) ? $label : t('Add new !instance_label', array('!instance_label' => $label));
132
  $title = $field['cardinality'] == 1 ? $label : t('Add new !instance_label', array('!instance_label' => $label));
134 133
  drupal_set_title($title);
135 134

  
136 135
  // Make sure the current user has access to create a field collection item.
drupal7/sites/all/modules/field_collection/field_collection.pathauto.inc
1
<?php
2

  
3
/**
4
 * Implements hook_pathauto().
5
 */
6
function field_collection_pathauto($op) {
7
  if ('settings' === $op) {
8
    $settings = array();
9
    $settings['module'] = 'field_collection';
10
    $settings['token_type'] = 'field_collection_item';
11
    $settings['groupheader'] = t('Field collection item paths');
12
    $settings['patterndescr'] = t('Default path pattern (applies to all field collections with blank patterns below)');
13
    $settings['patterndefault'] = '';
14
    // @todo Implement bulk update:
15
    // $settings['batch_update_callback'] = 'field_collection_pathauto_bulk_update_batch_process';
16
    // $settings['batch_file'] = drupal_get_path('module', 'field_collection') . '/field_collection.pathauto.inc';
17

  
18
    $settings['patternitems'] = array();
19
    $instances = field_info_instances();
20
    foreach ($instances as $entity_type => $type_bundles) {
21
      foreach ($type_bundles as $bundle => $bundle_instances) {
22
        foreach ($bundle_instances as $field_name => $instance) {
23
          $field = field_info_field($field_name);
24
          if ($field['type'] === 'field_collection') {
25
            // @todo We may need different patterns depending on the.
26
            // host entity type or the host bundle. If so we need to prefix
27
            // field-name with $entity_type . '_' . $bundle . '_' and also need
28
            // to implement our own version of pathauto_pattern_load_by_entity()
29
            // searching for the best matching pattern.
30
            $settings['patternitems'][$field_name] = t('Pattern for all field collection @field-collection paths', array('@field-collection' => $field_name));
31
          }
32
        }
33
      }
34
    }
35

  
36
    return (object) $settings;
37
  }
38
}
39

  
40
/**
41
 * Create a path alias for a field collection item.
42
 *
43
 * @param object $host_entity
44
 *   Entity to which the field collection item belongs.
45
 * @param object $entity
46
 *   Field collection item.
47
 * @param string $op
48
 *   Operation to perform for pathauto_create_alias(). Can be 'insert', 'update', 'return', or 'bulkupdate'.
49
 *
50
 * @see field_collection_field_update()
51
 */
52
function field_collection_pathauto_create_alias($host_entity, $entity, $op, $options = array()) {
53
  module_load_include('inc', 'pathauto');
54

  
55
  pathauto_create_alias('field_collection', $op, 'field-collection/' . str_replace('_', '-', $entity->field_name) . '/' . $entity->item_id, array('field_collection_item' => $entity), $entity->field_name);
56
}
drupal7/sites/all/modules/field_collection/field_collection.test
35 35
      'field_name' => $this->field_name,
36 36
      'entity_type' => 'node',
37 37
      'bundle' => 'article',
38
      'label' => $this->randomName() . '_label',
39
      'description' => $this->randomName() . '_description',
40
      'weight' => mt_rand(0, 127),
38
      'label' => self::randomName() . '_label',
39
      'description' => self::randomName() . '_description',
40
      'weight' => random_int(0, 127),
41 41
      'settings' => array(),
42 42
      'widget' => array(
43 43
        'type' => 'hidden',
......
340 340
    $this->drupalGet($path);
341 341
    $this->assertText(t('Test text field'), 'Add form is shown.');
342 342

  
343
    $edit['field_text[und][0][value]'] = $this->randomName();
343
    $edit['field_text[und][0][value]'] = self::randomName();
344 344
    $this->drupalPost($path, $edit, t('Save'));
345 345
    $this->assertText(t('The changes have been saved.'), 'Field collection saved.');
346 346

  
347 347
    $this->assertText($edit['field_text[und][0][value]'], 'Added field value is shown.');
348 348

  
349
    $edit['field_text[und][0][value]'] = $this->randomName();
349
    $edit['field_text[und][0][value]'] = self::randomName();
350 350
    $this->drupalPost('field-collection/field-test-collection/1/edit', $edit, t('Save'));
351 351
    $this->assertText(t('The changes have been saved.'), 'Field collection saved.');
352 352
    $this->assertText($edit['field_text[und][0][value]'], 'Field collection has been edited.');
......
361 361
    // Make sure adding doesn't work any more as we have restricted cardinality
362 362
    // to 1.
363 363
    $this->drupalGet($path);
364
    $this->assertText(t('Too many items.'), 'Maxium cardinality has been reached.');
364
    $this->assertResponse(403);
365 365

  
366 366
    $this->drupalPost('field-collection/field-test-collection/1/delete', array(), t('Delete'));
367 367
    $this->drupalGet($path);
......
457 457
      'field_name' => $this->field_name,
458 458
      'entity_type' => 'node',
459 459
      'bundle' => 'article',
460
      'label' => $this->randomName() . '_label',
461
      'description' => $this->randomName() . '_description',
462
      'weight' => mt_rand(0, 127),
460
      'label' => self::randomName() . '_label',
461
      'description' => self::randomName() . '_description',
462
      'weight' => random_int(0, 127),
463 463
      'settings' => array(),
464 464
      'widget' => array(
465 465
        'type' => 'hidden',
......
572 572
      'field_name' => $this->field_name,
573 573
      'entity_type' => 'node',
574 574
      'bundle' => 'article',
575
      'label' => $this->randomName() . '_label',
576
      'description' => $this->randomName() . '_description',
577
      'weight' => mt_rand(0, 127),
575
      'label' => self::randomName() . '_label',
576
      'description' => self::randomName() . '_description',
577
      'weight' => random_int(0, 127),
578 578
      'settings' => array(),
579 579
      'widget' => array(
580 580
        'type' => 'field_collection_embed',
......
618 618
   */
619 619
  public function testContentTranslation() {
620 620
    // Create "Article" content.
621
    $edit['title'] = $this->randomName();
622
    $edit['body[' . LANGUAGE_NONE . '][0][value]'] = $this->randomName();
621
    $edit['title'] = self::randomName();
622
    $edit['body[' . LANGUAGE_NONE . '][0][value]'] = self::randomName();
623 623
    $edit['language'] = 'en';
624 624
    $field_collection_name = 'field_test_collection[' . LANGUAGE_NONE . '][0][field_text][' . LANGUAGE_NONE . '][0][value]';
625
    $edit[$field_collection_name] = $this->randomName();
625
    $edit[$field_collection_name] = self::randomName();
626 626

  
627 627
    $this->drupalPost('node/add/article', $edit, t('Save'));
628 628
    $this->assertRaw(t('Article %title has been created.', array('%title' => $edit['title'])), 'Article created.');
......
787 787
      'field_name' => $this->field_name,
788 788
      'entity_type' => 'node',
789 789
      'bundle' => 'page',
790
      'label' => $this->randomName() . '_label',
791
      'description' => $this->randomName() . '_description',
792
      'weight' => mt_rand(0, 127),
790
      'label' => self::randomName() . '_label',
791
      'description' => self::randomName() . '_description',
792
      'weight' => random_int(0, 127),
793 793
      'settings' => array(),
794 794
      'widget' => array(
795 795
        'type' => 'field_collection_embed',
......
864 864
      $num_values = self::NUM_VALUES;
865 865
    }
866 866

  
867
    $title = $this->randomName();
867
    $title = self::randomName();
868 868

  
869 869
    $this->drupalGet('node/add/page');
870 870

  
drupal7/sites/all/modules/field_collection/field_collection.theme.css
1 1
@charset "UTF-8";
2 2

  
3 3
.field-collection-container {
4
  border-bottom: 1px solid #D3D7D9;
4
  border-bottom: 1px solid #d3d7d9;
5 5
  margin-bottom: 1em;
6 6
}
7 7

  
......
16 16
.field-collection-view {
17 17
  padding: 1em 0 0.3em 0;
18 18
  margin: 0 1em 0 1em;
19
  border-bottom: 1px dotted #D3D7D9;
19
  border-bottom: 1px dotted #d3d7d9;
20 20
}
21 21

  
22 22
/* If there is no add link, don't show the final border. */
drupal7/sites/all/modules/field_collection/field_collection.tokens.inc
66 66
  );
67 67
}
68 68

  
69

  
70 69
/**
71 70
 * Implements hook_tokens().
72 71
 */
......
75 74

  
76 75
  // Provide a complete set of tokens for type == 'host', and a supplementary
77 76
  // token 'host' for type == 'field_collection_item'.
78
  if (($type == 'field_collection_item' or $type == 'host') and !empty($data['field_collection_item'])) {
77
  if (($type === 'field_collection_item' || $type === 'host') && !empty($data['field_collection_item'])) {
79 78
    $collection = $data['field_collection_item'];
80 79
    // When saving revisions, only $collection->original has valid state about
81 80
    // its host entity.
......
83 82
      $collection = $collection->original;
84 83
    }
85 84

  
86
    if ($type == 'field_collection_item') {
85
    if ($type === 'field_collection_item') {
87 86
      if (!empty($tokens['host'])) {
88 87
        $replacements[$tokens['host']] = $collection->hostEntityId();
89 88
      }
drupal7/sites/all/modules/field_collection/views/field_collection_handler_relationship.inc
4 4
 * @file
5 5
 * Provide relationship handler for field collection fields.
6 6
 */
7

  
7 8
class field_collection_handler_relationship extends views_handler_relationship {
8 9

  
9 10
  function option_definition() {
drupal7/sites/all/modules/media_youtube/includes/MediaInternetYouTubeHandler.inc
111 111
    $uri = file_stream_wrapper_uri_normalize('youtube://' . $type . '/' . check_plain($id));
112 112
    $external_url = file_create_url($uri);
113 113
    $oembed_url = url('https://www.youtube.com/oembed', array('query' => array('url' => $external_url, 'format' => 'json')));
114
    $response = drupal_http_request($oembed_url, array('method' => 'HEAD'));
114
    $response = drupal_http_request($oembed_url);
115 115

  
116
    if ($response->code == 401) {
117
      throw new MediaInternetValidationException('Embedding has been disabled for this YouTube video.');
116
    if (!isset($response->error)) {
117
      $data = drupal_json_decode($response->data);
118
      if (!empty($data)) {
119
        return TRUE;
120
      }
121
      else {
122
        $error_data = t('Unspecific');
123
        if (is_string($response->data)) {
124
          $error_data = $response->data;
125
        }
126
        throw new MediaInternetValidationException("The YouTube video ID is invalid, video was deleted or is disabled for embedding. Error: {$error_data}");
127
        return;
128
      }
118 129
    }
119
    elseif ($response->code != 200) {
120
      throw new MediaInternetValidationException('The YouTube video ID is invalid or the video was deleted.');
130
    else {
131
      throw new Exception("Error Processing Request. (Error: {$response->code}, {$response->error})");
132
      return;
121 133
    }
122

  
123
    return TRUE;
124 134
  }
125 135
}
drupal7/sites/all/modules/media_youtube/media_youtube.info
11 11
files[] = includes/MediaYouTubeStreamWrapper.inc
12 12
files[] = includes/MediaInternetYouTubeHandler.inc
13 13

  
14
; Information added by Drupal.org packaging script on 2019-10-03
15
version = "7.x-3.9"
14
; Information added by Drupal.org packaging script on 2020-12-28
15
version = "7.x-3.10"
16 16
core = "7.x"
17 17
project = "media_youtube"
18
datestamp = "1570113188"
18
datestamp = "1609172349"
drupal7/sites/all/modules/media_youtube/tests/media_youtube_test.info
8 8
files[] = includes/MediaYouTubeTestStreamWrapper.inc
9 9
files[] = includes/MediaYouTubeTestHandler.inc
10 10

  
11
; Information added by Drupal.org packaging script on 2019-10-03
12
version = "7.x-3.9"
11
; Information added by Drupal.org packaging script on 2020-12-28
12
version = "7.x-3.10"
13 13
core = "7.x"
14 14
project = "media_youtube"
15
datestamp = "1570113188"
15
datestamp = "1609172349"

Formats disponibles : Unified diff