Projet

Général

Profil

Révision b858700c

Ajouté par Assos Assos il y a environ 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/commerce/commerce.module
95 95
  $fields = array();
96 96

  
97 97
  // Loop through the fields looking for any fields of the specified type.
98
  foreach (field_info_fields() as $field_name => $field) {
99
    if ($field['type'] == $field_type) {
98
  foreach (field_info_field_map() as $field_name => $field_stub) {
99
    if ($field_stub['type'] == $field_type) {
100 100
      // Add this field to the return array if no entity type was specified or
101 101
      // if the specified type exists in the field's bundles array.
102
      if (empty($entity_type) || in_array($entity_type, array_keys($field['bundles']))) {
102
      if (empty($entity_type) || in_array($entity_type, array_keys($field_stub['bundles']))) {
103
        $field = field_info_field($field_name);
103 104
        $fields[$field_name] = $field;
104 105
      }
105 106
    }
......
537 538
      // Include the currency file and invoke the currency info hook.
538 539
      module_load_include('inc', 'commerce', 'includes/commerce.currency');
539 540
      $currencies['all'] = module_invoke_all('commerce_currency_info');
540
      drupal_alter('commerce_currency_info', $currencies['all']);
541
      drupal_alter('commerce_currency_info', $currencies['all'], $language->language);
541 542

  
542 543
      // Add default values if they don't exist.
543 544
      foreach ($currencies['all'] as $currency_code => $currency) {
......
1139 1140
    $account = $user;
1140 1141
  }
1141 1142

  
1142
  // Read the base table from the query if available or default to the first
1143
  // table in the query's tables array.
1144
  if (!isset($base_table) && !$base_table = $query->getMetaData('base_table')) {
1145
    // Assume that the base table is the first table if not set. It will result
1146
    // in an invalid query if the first table is not the table we expect,
1147
    // forcing the caller to actually properly pass a base table in that case.
1148
    $tables = &$query->getTables();
1149
    reset($tables);
1150
    $base_table = key($tables);
1151
  }
1152

  
1153 1143
  // Do not apply any conditions for users with administrative view permissions.
1154 1144
  if (user_access('administer ' . $entity_type . ' entities', $account)
1155 1145
    || user_access('view any ' . $entity_type . ' entity', $account)) {
......
1159 1149
  // Get the entity type info array for the current access check and prepare a
1160 1150
  // conditions object.
1161 1151
  $entity_info = entity_get_info($entity_type);
1152

  
1153
  // If a base table wasn't specified, attempt to read it from the query if
1154
  // available, look for a table in the query's tables array that matches the
1155
  // base table of the given entity type, or just default to the first table.
1156
  if (!isset($base_table) && !$base_table = $query->getMetaData('base_table')) {
1157
    // Initialize the base table to the first table in the array. If a table can
1158
    // not be found that matches the entity type's base table, this will result
1159
    // in an invalid query if the first table is not the table we expect,
1160
    // forcing the caller to actually properly pass a base table in that case.
1161
    $tables = $query->getTables();
1162
    reset($tables);
1163
    $base_table = key($tables);
1164

  
1165
    foreach ($tables as $table_info) {
1166
      if (!($table_info instanceof SelectQueryInterface)) {
1167
        // If this table matches the entity type's base table, use its table
1168
        // alias as the base table for the purposes of bundle and ownership
1169
        // access checks.
1170
        if ($table_info['table'] == $entity_info['base table']) {
1171
          $base_table = $table_info['alias'];
1172
        }
1173
      }
1174
    }
1175
  }
1176

  
1177
  // Prepare an OR container for conditions. Conditions will be added that seek
1178
  // to grant access, meaning any particular type of permission check may grant
1179
  // access even if none of the others apply. At the end of this function, if no
1180
  // conditions have been added to the array, a condition will be added that
1181
  // always returns FALSE (1 = 0).
1162 1182
  $conditions = db_or();
1163 1183

  
1164 1184
  // Perform bundle specific permission checks for the specified entity type.
1185
  // In the event that the user has permission to view every bundle of the given
1186
  // entity type, $really_restricted will remain FALSE, indicating that it is
1187
  // safe to exit this function without applying any additional conditions. If
1188
  // the user only had such permission for a subset of the defined bundles,
1189
  // conditions representing those access checks would still be added.
1165 1190
  $really_restricted = FALSE;
1166 1191

  
1167 1192
  // Loop over every possible bundle for the given entity type.
......
1242 1267
    form_error($element, t('Use a positive number for the options list limit or else leave it blank for no limit.'));
1243 1268
  }
1244 1269
}
1270

  
1271
/**
1272
 * Implements hook_theme_registry_alter().
1273
 *
1274
 * The Entity API theme function template_preprocess_entity() assumes the
1275
 * presence of a path key in an entity URI array, which isn't strictly required
1276
 * by Drupal core itself. Until this is fixed in the Entity API code, we replace
1277
 * that function with a Commerce specific version.
1278
 *
1279
 * @todo Remove when https://drupal.org/node/1934382 is resolved.
1280
 */
1281
function commerce_theme_registry_alter(&$theme_registry) {
1282
  // Copy the preprocess functions array and remove the core preprocess function
1283
  // along with the Entity API's and this module's.
1284
  $functions = drupal_map_assoc($theme_registry['entity']['preprocess functions']);
1285
  unset($functions['template_preprocess'], $functions['template_preprocess_entity'], $functions['commerce_preprocess_entity']);
1286

  
1287
  // Unshift the core preprocess function and the Commerce specific function so
1288
  // they appear at the beginning of the array in the desired order.
1289
  array_unshift($functions, 'template_preprocess', 'commerce_preprocess_entity');
1290

  
1291
  // Update the function list in the theme registry.
1292
  $theme_registry['entity']['preprocess functions'] = array_values($functions);
1293
}
1294

  
1295
/**
1296
 * Processes variables for entity.tpl.php, replacing template_preprocess_entity().
1297
 *
1298
 * @see commerce_theme_registry_alter()
1299
 * @todo Remove when https://drupal.org/node/1934382 is resolved.
1300
 */
1301
function commerce_preprocess_entity(&$variables) {
1302
  $variables['view_mode'] = $variables['elements']['#view_mode'];
1303
  $entity_type = $variables['elements']['#entity_type'];
1304
  $variables['entity_type'] = $entity_type;
1305
  $entity = $variables['elements']['#entity'];
1306
  $variables[$variables['elements']['#entity_type']] = $entity;
1307
  $info = entity_get_info($entity_type);
1308

  
1309
  $variables['title'] = check_plain(entity_label($entity_type, $entity));
1310

  
1311
  $uri = entity_uri($entity_type, $entity);
1312
  $variables['url'] = $uri && isset($uri['path']) ? url($uri['path'], $uri['options']) : FALSE;
1313

  
1314
  if (isset($variables['elements']['#page'])) {
1315
    // If set by the caller, respect the page property.
1316
    $variables['page'] = $variables['elements']['#page'];
1317
  }
1318
  else {
1319
    // Else, try to automatically detect it.
1320
    $variables['page'] = $uri && isset($uri['path']) && $uri['path'] == $_GET['q'];
1321
  }
1322

  
1323
  // Helpful $content variable for templates.
1324
  $variables['content'] = array();
1325
  foreach (element_children($variables['elements']) as $key) {
1326
    $variables['content'][$key] = $variables['elements'][$key];
1327
  }
1328

  
1329
  if (!empty($info['fieldable'])) {
1330
    // Make the field variables available with the appropriate language.
1331
    field_attach_preprocess($entity_type, $entity, $variables['content'], $variables);
1332
  }
1333
  list(, , $bundle) = entity_extract_ids($entity_type, $entity);
1334

  
1335
  // Gather css classes.
1336
  $variables['classes_array'][] = drupal_html_class('entity-' . $entity_type);
1337
  $variables['classes_array'][] = drupal_html_class($entity_type . '-' . $bundle);
1338

  
1339
  // Add RDF type and about URI.
1340
  if (module_exists('rdf')) {
1341
    $variables['attributes_array']['about'] = empty($uri['path']) ? NULL: url($uri['path']);
1342
    $variables['attributes_array']['typeof'] = empty($entity->rdf_mapping['rdftype']) ? NULL : $entity->rdf_mapping['rdftype'];
1343
  }
1344

  
1345
  // Add suggestions.
1346
  $variables['theme_hook_suggestions'][] = $entity_type;
1347
  $variables['theme_hook_suggestions'][] = $entity_type . '__' . $bundle;
1348
  $variables['theme_hook_suggestions'][] = $entity_type . '__' . $bundle . '__' . $variables['view_mode'];
1349
  if ($id = entity_id($entity_type, $entity)) {
1350
    $variables['theme_hook_suggestions'][] = $entity_type . '__' . $id;
1351
  }
1352
}

Formats disponibles : Unified diff