Projet

Général

Profil

Révision 599a39cd

Ajouté par Assos Assos il y a environ 3 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/date/date_views/date_views.module
26 26
 * Form callback for date views settings.
27 27
 */
28 28
function date_views_settings($form, &$form_state) {
29

  
30 29
  $form['date_views_month_format_with_year'] = array(
31 30
    '#type' => 'textfield',
32 31
    '#title' => t('Date views month format with year'),
......
76 75
  );
77 76

  
78 77
  return system_settings_form($form);
79

  
80 78
}
81 79

  
82 80
/**
83 81
 * Implements hook_views_api().
84
 *
85
 * This one is used as the base to reduce errors when updating.
86 82
 */
87 83
function date_views_theme() {
84
  // This one is used as the base to reduce errors when updating.
88 85
  $path = drupal_get_path('module', 'date_views');
89 86
  $base = array(
90 87
    'file' => 'theme.inc',
......
165 162

  
166 163
/**
167 164
 * Implements hook_date_views_entities().
168
 *
169
 * Map extra Views tables to the entity that holds its date fields, needed for Views tables other than the primary tables identified in entity_info().
170 165
 */
171 166
function date_views_date_views_extra_tables() {
167
  // Map extra Views tables to the entity that holds its date fields, needed
168
  // for Views tables other than the primary tables identified in entity_info().
172 169
  return array(
173 170
    'node_revision' => 'node',
174 171
  );
175 172
}
176 173

  
177 174
/**
178
 * Helper function to map entity types to the Views base table they use, to make it easier to infer the entity type from a base table.
175
 * Helper function to map entity types to the Views base table they use.
176
 *
177
 * Used to make it easier to infer the entity type from a base table.
179 178
 *
180
 * Views has a new handler called views_handler_field_entity() that loads entities.
179
 * Views has a new handler called views_handler_field_entity() that loads
180
 * entities.
181 181
 *
182
 * And you can use something like the following to get the entity type from a view, but not all our base tables contain the entity information we need, (i.e. revisions).
182
 * And you can use something like the following to get the entity type from a
183
 * view, but not all our base tables contain the entity information we need,
184
 * (i.e. revisions).
183 185
 *
184
 * So it won't work here and we resort to creating information from entity_get_info().
186
 * So it won't work here and we resort to creating information from
187
 * entity_get_info().
185 188
 *
186 189
 *   // A method to get the entity type for a base table.
187 190
 *   $table_data = views_fetch_data($base_table);
......
194 197
  $base_tables = &drupal_static(__FILE__, array());
195 198

  
196 199
  if (empty($base_tables)) {
197

  
198 200
    // First we get the base tables we can learn about from entity_info.
199 201
    $entity_info = entity_get_info();
200 202
    foreach ($entity_info as $entity_type => $info) {
......
206 208
      }
207 209
    }
208 210

  
209
    // Then we let other modules tell us about other entity tables that hold date fields.
211
    // Then we let other modules tell us about other entity tables that hold
212
    // date fields.
210 213
    $base_tables += module_invoke_all('date_views_extra_tables');
211 214
  }
212 215

  
......
215 218

  
216 219
/**
217 220
 * Implements hook_date_views_fields().
218
 *
219
 * All modules that create custom fields that use the 'views_handler_field_date' handler can provide additional information here about the type of date they create so the date can be used by the Date API views date argument and date filter.
220 221
 */
221 222
function date_views_date_views_fields($field) {
223
  // All modules that create custom fields that use the
224
  // 'views_handler_field_date' handler can provide additional information here
225
  // about the type of date they create so the date can be used by the Date API
226
  // views date argument and date filter.
222 227
  $values = array(
223 228
    // The type of date: DATE_UNIX, DATE_ISO, DATE_DATETIME.
224 229
    'sql_type' => DATE_UNIX,
......
249 254
}
250 255

  
251 256
/**
252
 * A version of date_real_url that formats links correctly for the new Date pager.
257
 * A version of date_real_url that formats links correctly for the Date pager.
253 258
 */
254 259
function date_pager_url($view, $date_type = NULL, $date_arg = NULL, $force_view_url = FALSE, $absolute = TRUE) {
255

  
256
  // If someone adds a pager without a matching argument, there is not date information to work with.
260
  // If someone adds a pager without a matching argument, there is not date
261
  // information to work with.
257 262
  if (empty($view->date_info) || !isset($view->date_info->date_arg_pos)) {
258 263
    return '';
259 264
  }
......
261 266
  $args = $view->args;
262 267
  $pos = $view->date_info->date_arg_pos;
263 268

  
264
  // The View arguments array is indexed numerically but is not necessarily
265
  // in numerical order. Sort the arguments to ensure the correct order.
269
  // The View arguments array is indexed numerically but is not necessarily in
270
  // numerical order. Sort the arguments to ensure the correct order.
266 271
  ksort($args);
267 272

  
268
  // If there are empty arguments before the date argument,
269
  // pad them with the wildcard so the date argument will be in
270
  // the right position.
273
  // If there are empty arguments before the date argument, pad them with the
274
  // wildcard so the date argument will be in the right position.
271 275
  if (count($args) < $pos) {
272 276
    foreach ($view->argument as $name => $argument) {
273 277
      if ($argument->position == $pos) {
......
293 297

  
294 298
      default:
295 299
        $args[$pos] = date_pad($view->date_info->year, 4) . '-' . date_pad($view->date_info->month);
296
        break;
297 300
    }
298 301
  }
299 302
  elseif (!empty($date_arg)) {
......
302 305
  else {
303 306
    $args = $view->args;
304 307
  }
305
  // Is this an embedded or a block view?
306
  // Return the pager query value.
307
  if (!$force_view_url &&
308
  (!empty($view->preview) || !empty($view->date_info->block_identifier))) {
309 308

  
309
  // Is this an embedded or a block view? Return the pager query value.
310
  if (!$force_view_url &&
311
      (!empty($view->preview) || !empty($view->date_info->block_identifier))) {
310 312
    $url = $args[$pos];
311 313
    $key = date_block_identifier($view);
312 314
    if (!empty($key)) {
......
316 318
    }
317 319
  }
318 320

  
319
  // Normal views may need querystrings appended to them
320
  // if they use exposed filters.
321
  // Normal views may need querystrings appended to them if they use exposed
322
  // filters.
321 323
  return url($view->get_url($args), array(
322 324
    'query' => date_views_querystring($view),
323 325
    'absolute' => $absolute,
......
337 339

  
338 340
/**
339 341
 * Implements hook_field_views_data_alter().
340
 *
341
 * Create a Views field for each date column we care about to supplement the generic 'entity_id' and 'revision_id' fields that are automatically created.
342
 *
343
 * Also use friendlier labels to distinguish the start date and end date in listings (for fields that use both).
344 342
 */
345 343
function date_views_field_views_data_alter(&$result, $field, $module) {
344
  // Create a Views field for each date column we care about to supplement the
345
  // generic 'entity_id' and 'revision_id' fields that are automatically
346
  // created. Also use friendlier labels to distinguish the start date and end
347
  // date in listings (for fields that use both).
346 348
  if ($module == 'date') {
347 349
    $has_end_date = !empty($field['settings']['todate']);
348 350
    if ($has_end_date) {
......
358 360
        // The old values are still there with a 'moved to' key, so ignore them.
359 361
        if (array_key_exists('field', $value) && !array_key_exists('moved to', $value['field'])) {
360 362
          $result[$table][$column]['field']['is date'] = TRUE;
361
          // Not sure yet if we still need a custom field handler in D7 now that custom formatters are available.
362
          // Might still need it to handle grouping of multiple value dates.
363
          // Not sure yet if we still need a custom field handler in D7 now
364
          // that custom formatters are available. Might still need it to
365
          // handle grouping of multiple value dates.
363 366
          // $result[$table][$column]['field']['handler'] = 'date_handler_field_date';
364 367
          // $result[$table][$column]['field']['add fields to query'] = TRUE;
365 368
        }
......
458 461
}
459 462

  
460 463
/**
461
 * The instanceof function makes this work for any handler that was derived from 'views_handler_filter_date' or 'views_handler_argument_date', which includes core date fields like the node updated field.
464
 * Implements hook_form_FORM_ID_alter() for views_exposed_form().
465
 */
466
function date_views_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
467
  $children = element_children($form);
468
  // @todo On a stock views_exposed_form, there won't be any grandchildren
469
  // items, but will this always be the case? How about better_exposed_filters?
470
  foreach ($children as $child) {
471
    if (isset($form[$child]['#id']) && strpos($form[$child]['#id'], 'date_views_exposed_filter-') === 0) {
472
      // Remove empty or scalar date input when an array was expected.
473
      if (empty($form_state['input'][$child]) || !is_array($form_state['input'][$child])) {
474
        unset($form_state['input'][$child]);
475
      }
476
      elseif (empty($form_state['input'][$child]['value']) || !is_array($form_state['input'][$child]['value'])) {
477
        unset($form_state['input'][$child]['value']);
478
      }
479
    }
480
  }
481
}
482

  
483
/**
484
 * Work out if the plugin is a date.
462 485
 *
463
 * The test for $handler->min_date tells us that this is an argument that not only is derived from the views date handler but also has been processed by the Date Views filter or argument code.
486
 * The instanceof function makes this work for any handler that was derived from
487
 * 'views_handler_filter_date' or 'views_handler_argument_date', which includes
488
 * core date fields like the node updated field.
489
 *
490
 * The test for $handler->min_date tells us that this is an argument that not
491
 * only is derived from the views date handler but also has been processed by
492
 * the Date Views filter or argument code.
464 493
 */
465 494
function date_views_handler_is_date($handler, $type = 'argument') {
466 495
  switch ($type) {
......
476 505
/**
477 506
 * Validation hook for exposed filters that use the select widget.
478 507
 *
479
 * This is to ensure the the user completes all parts of the date not just some parts. Only needed for the select widget.
508
 * This is to ensure the the user completes all parts of the date not just some
509
 * parts. Only needed for the select widget.
480 510
 */
481 511
function date_views_select_validate(&$form, &$form_state) {
482 512
  // If there are no values just return.
......
525 555

  
526 556
/**
527 557
 * Implements hook_date_formatter_view_alter().
528
 *
529
 * If we are displaying a date from a view, see if we have information about which multiple value to display. If so, set the date_id in the entity.
530 558
 */
531 559
function date_views_date_formatter_pre_view_alter(&$entity, &$variables) {
560
  // If we are displaying a date from a view, see if we have information about
561
  // which multiple value to display. If so, set the date_id in the entity.
532 562
  // Some views have no row index.
533 563
  if (!empty($entity->view) && isset($entity->view->row_index)) {
534 564
    $field = $variables['field'];

Formats disponibles : Unified diff