Projet

Général

Profil

Révision e9f59589

Ajouté par Assos Assos il y a presque 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/field_group/field_group.module
244 244
 * Implements hook_field_attach_form().
245 245
 */
246 246
function field_group_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
247

  
247 248
  $form['#attached']['css'][] = drupal_get_path('module', 'field_group') . '/field_group.field_ui.css';
248 249
  field_group_attach_groups($form, 'form', $form_state);
249 250
  $form['#pre_render'][] = 'field_group_form_pre_render';
......
291 292
      'html-element' => array(
292 293
        'label' => t('HTML element'),
293 294
        'description' => t('This fieldgroup renders the inner content in a HTML element with classes and attributes.'),
294
        'instance_settings' => array('element' => 'div', 'classes' => '', 'attributes' => '', 'required_fields' => 1),
295
        'instance_settings' => array('element' => 'div', 'show_label' => 0, 'label_element' => 'div', 'classes' => '', 'attributes' => '', 'required_fields' => 1),
295 296
      ),
296 297
      'div' => array(
297 298
        'label' => t('Div'),
......
303 304
      'html5' => array(
304 305
        'label' => t('HTML5'),
305 306
        'description' => t('This fieldgroup renders the inner content in a semantic HTML5 wrapper'),
306
        'instance_settings' => array('wrapper' => '', 'classes' => ''),
307
        'instance_settings' => array('wrapper' => '', 'classes' => '', 'id' => ''),
307 308
      ),
308 309
      'fieldset' => array(
309 310
        'label' => t('Fieldset'),
......
365 366
      'html-element' => array(
366 367
        'label' => t('HTML element'),
367 368
        'description' => t('This fieldgroup renders the inner content in a HTML element with classes and attributes.'),
368
        'instance_settings' => array('element' => 'div', 'classes' => '', 'attributes' => '', 'required_fields' => 1),
369
        'instance_settings' => array('element' => 'div', 'show_label' => 0, 'label_element' => 'div', 'classes' => '', 'attributes' => '', 'required_fields' => 1),
369 370
      ),
370 371
      'div' => array(
371 372
        'label' => t('Div'),
372 373
        'description' => t('This fieldgroup renders the inner content in a simple div with the title as legend.'),
373 374
        'format_types' => array('open', 'collapsible', 'collapsed'),
374
        'instance_settings' => array('description' => '', 'show_label' => 1, 'label_element' => 'h3', 'effect' => 'none', 'speed' => 'fast', 'classes' => ''),
375
        'instance_settings' => array('description' => '', 'show_label' => 1, 'label_element' => 'h3', 'effect' => 'none', 'speed' => 'fast', 'classes' => '', 'id' => ''),
375 376
        'default_formatter' => 'collapsible',
376 377
      ),
377 378
      'html5' => array(
378 379
        'label' => t('HTML5'),
379 380
        'description' => t('This fieldgroup renders the inner content in a semantic HTML5 wrapper'),
380
        'instance_settings' => array('wrapper' => '', 'classes' => ''),
381
        'instance_settings' => array('wrapper' => '', 'classes' => '', 'id' => ''),
381 382
      ),
382 383
      'fieldset' => array(
383 384
        'label' => t('Fieldset'),
......
452 453
      '#type' => 'select',
453 454
      '#options' => drupal_map_assoc($formatter['format_types']),
454 455
      '#default_value' => isset($group->format_settings['formatter']) ? $group->format_settings['formatter'] : $formatter['default_formatter'],
455
      '#weight' => 1,
456
      '#weight' => -4,
456 457
    );
457 458
  }
458 459

  
......
470 471
      '#title' => t('ID'),
471 472
      '#type' => 'textfield',
472 473
      '#default_value' => isset($group->format_settings['instance_settings']['id']) ? $group->format_settings['instance_settings']['id'] : (isset($formatter['instance_settings']['id']) ? $formatter['instance_settings']['id'] : ''),
473
      '#weight' => 3,
474
      '#weight' => 10,
474 475
      '#element_validate' => array('field_group_validate_id'),
475 476
    );
476 477
  }
......
479 480
      '#title' => t('Extra CSS classes'),
480 481
      '#type' => 'textfield',
481 482
      '#default_value' => isset($group->format_settings['instance_settings']['classes']) ? $group->format_settings['instance_settings']['classes'] : (isset($formatter['instance_settings']['classes']) ? $formatter['instance_settings']['classes'] : ''),
482
      '#weight' => 4,
483
      '#weight' => 11,
483 484
      '#element_validate' => array('field_group_validate_css_class'),
484 485
    );
485 486
  }
......
501 502
        '#type' => 'textfield',
502 503
        '#default_value' => isset($group->format_settings['instance_settings']['element']) ? $group->format_settings['instance_settings']['element'] : $formatter['instance_settings']['element'],
503 504
        '#description' => t('E.g. div, section, aside etc.'),
505
        '#weight' => 1,
506
      );
507

  
508
      $form['instance_settings']['show_label'] = array(
509
        '#title' => t('Show label'),
510
        '#type' => 'select',
511
        '#options' => array(0 => t('No'), 1 => t('Yes')),
512
        '#default_value' => isset($group->format_settings['instance_settings']['show_label']) ? $group->format_settings['instance_settings']['show_label'] : $formatter['instance_settings']['show_label'],
504 513
        '#weight' => 2,
505 514
      );
506 515

  
516
      $form['instance_settings']['label_element'] = array(
517
        '#title' => t('Label element'),
518
        '#type' => 'textfield',
519
        '#default_value' => isset($group->format_settings['instance_settings']['label_element']) ? $group->format_settings['instance_settings']['label_element'] : $formatter['instance_settings']['label_element'],
520
        '#weight' => 3,
521
      );
522

  
507 523
      $form['instance_settings']['attributes'] = array(
508 524
        '#title' => t('Attributes'),
509 525
        '#type' => 'textfield',
......
533 549
        '#type' => 'select',
534 550
        '#options' => array('none' => t('None'), 'blind' => t('Blind')),
535 551
        '#default_value' => isset($group->format_settings['instance_settings']['effect']) ? $group->format_settings['instance_settings']['effect'] : $formatter['instance_settings']['effect'],
536
        '#weight' => 2,
552
        '#weight' => 3,
537 553
      );
538 554
      $form['instance_settings']['speed'] = array(
539 555
        '#title' => t('Speed'),
......
617 633
  $classes = _field_group_get_html_classes($group);
618 634

  
619 635
  $group->classes = implode(' ', $classes->required);
620
  $group->description = isset($group->format_settings['instance_settings']['description']) ? filter_xss_admin(t($group->format_settings['instance_settings']['description'])) : '';
636
  $group->description = !empty($group->format_settings['instance_settings']['description']) ? filter_xss_admin(t($group->format_settings['instance_settings']['description'])) : '';
621 637

  
622 638
}
623 639

  
......
627 643
 * @param Array $elements by address.
628 644
 * @param Object $group The Field group info.
629 645
 */
630
function field_group_field_group_pre_render(& $element, &$group, & $form) {
646
function field_group_field_group_pre_render(&$element, &$group, & $form) {
631 647

  
632 648
  field_group_pre_render_prepare($group);
633 649

  
......
640 656
  );
641 657

  
642 658
  if (isset($group->format_settings['instance_settings']['id']) && !empty($group->format_settings['instance_settings']['id'])) {
643
    $element['#id'] = $group->format_settings['instance_settings']['id'];
644
  }
645
  else {
646
    $element['#id'] = $form['#entity_type'] . '_' . $form['#bundle'] . '_' . $view_mode . '_' . $group->group_name;
659
    $element['#id'] = drupal_html_id($group->format_settings['instance_settings']['id']);
647 660
  }
648 661

  
649 662
  $element['#weight'] = $group->weight;
......
691 704
 */
692 705
function field_group_pre_render_html_element(&$element, $group, &$form) {
693 706
  $html_element = isset($group->format_settings['instance_settings']['element']) ? $group->format_settings['instance_settings']['element'] : 'div';
707
  $show_label = isset($group->format_settings['instance_settings']['show_label']) ? $group->format_settings['instance_settings']['show_label'] : 0;
708
  $label_element = isset($group->format_settings['instance_settings']['label_element']) ? $group->format_settings['instance_settings']['label_element'] : 'div';
694 709
  $attributes = isset($group->format_settings['instance_settings']['attributes']) ? ' ' . $group->format_settings['instance_settings']['attributes'] : '';
695 710
  $group->classes = trim($group->classes);
696 711

  
......
715 730
  $attributes = drupal_attributes($element_attributes);
716 731

  
717 732
  $element['#prefix'] = '<' . $html_element . $attributes . '>';
733
  if ($show_label) {
734
    $element['#prefix'] .= '<' . $label_element . '><span>' . check_plain(t($group->label)) . '</span></' . $label_element . '>';
735
  }
718 736
  $element['#suffix'] = '</' . $html_element . '>';
719 737
}
720 738

  
......
733 751
  $effect = isset($group->format_settings['instance_settings']['effect']) ? $group->format_settings['instance_settings']['effect'] : 'none';
734 752

  
735 753
  $element['#type'] = 'markup';
754
  $id = isset($element['#id']) ? ' id="' . $element['#id'] . '"' : '';
755

  
736 756
  if ($group->format_settings['formatter'] != 'open') {
737
    $element['#prefix'] = '<div id="' . $element['#id'] . '" class="' . $group->classes . '">
757

  
758
    $element['#prefix'] = '<div' . $id . ' class="' . $group->classes . '">
738 759
      <' . $label_element . '><span class="field-group-format-toggler">' . check_plain(t($group->label)) . '</span></' . $label_element . '>
739 760
      <div class="field-group-format-wrapper" style="display: ' . (!empty($group->collapsed) ? 'none' : 'block') . ';">';
740 761
    $element['#suffix'] = '</div></div>';
741 762
  }
742 763
  else {
743
    $class_attribute = '';
744
    if (!empty($group->classes)) {
745
      $class_attribute = 'class = "' . $group->classes . '"';
746
    }
747
    $element['#prefix'] = '<div id="' . $element['#id'] . '"' . $class_attribute . '>';
764
    $class_attribute = !empty($group->classes) ? ' class="' . $group->classes . '"' : '';
765

  
766
    $element['#prefix'] = '<div' . $id . $class_attribute . '>';
748 767
    if ($show_label) {
749 768
      $element['#prefix'] .= '<' . $label_element . '><span>' . check_plain(t($group->label)) . '</span></' . $label_element . '>';
750 769
    }
......
769 788
 * @param $form The root element or form.
770 789
 */
771 790
function field_group_pre_render_html5(&$element, $group, &$form) {
791
  $id = !empty($element['#id']) ? ' id="' . $element['#id'] . '"' : '';
792
  $class = !empty($group->classes) ? ' class="' . $group->classes . '"' : '';
772 793
  $element += array(
773 794
    '#type' => 'markup',
774
    '#prefix' => '<' . $group->format_settings['instance_settings']['wrapper'] . ' id="' . $element['#id'] . '" class="' . $group->classes . '">',
795
    '#prefix' => '<' . $group->format_settings['instance_settings']['wrapper'] . $id . $class . '>',
775 796
    '#suffix' => '</' . $group->format_settings['instance_settings']['wrapper'] . '>',
776 797
  );
777 798
}
......
1113 1134
  $hasChildren = FALSE;
1114 1135
  if (count($children)) {
1115 1136
    foreach ($children as $childname) {
1137

  
1116 1138
      if (in_array($childname, $groups)) {
1117 1139
        field_group_remove_empty_form_groups($childname, $element[$childname], $groups, $form_groups, $entity);
1118 1140
      }
1119 1141
      $exception = $entity . '__' . $childname;
1120
      $hasChildren = $hasChildren ? TRUE : (isset($element[$childname]['#type']) || in_array($exception, $exceptions));
1142
      $hasChildren = $hasChildren ? TRUE : (isset($element[$childname]['#type']) || isset($element[$childname]['#markup']) || in_array($exception, $exceptions));
1143

  
1121 1144
    }
1122 1145
  }
1123 1146

  
......
1443 1466
    '#default_value' => $element['#default_control'],
1444 1467
    '#attributes' => array('class' => array('multipage-active-control')),
1445 1468
  );
1446
  
1469

  
1447 1470
  return $element;
1448 1471
}
1449 1472

  
......
1566 1589
      $groups = $cached->data;
1567 1590
    }
1568 1591
    else {
1569
      drupal_static_reset('ctools_export_load_object');
1570
      drupal_static_reset('ctools_export_load_object_all');
1592
      $ctools_export_load_object = &drupal_static('ctools_export_load_object');
1593
      $ctools_export_load_object_all = &drupal_static('ctools_export_load_object_all');
1594
      unset($ctools_export_load_object['field_group']);
1595
      unset($ctools_export_load_object_all['field_group']);
1571 1596
      $groups = field_group_read_groups();
1572 1597
      cache_set('field_groups', $groups, 'cache_field');
1573 1598
    }
......
1680 1705
 *   Field group object.
1681 1706
 */
1682 1707
function field_group_unpack($packed_group) {
1683
  if (!isset($packed_group->data)) {
1708
  if (empty($packed_group->data)) {
1684 1709
    return $packed_group;
1685 1710
  }
1686 1711

  
......
1847 1872
/**
1848 1873
 * Pre render callback for rendering groups.
1849 1874
 * @see field_group_field_attach_form
1850
 * @param $element Form that is beïng rendered.
1875
 * @param $element Form that is being rendered.
1851 1876
 */
1852 1877
function field_group_form_pre_render(&$element) {
1853 1878
  return field_group_build_entity_groups($element, 'form');
......
1860 1885
 * @see field_group_theme_registry_alter
1861 1886
 * @see field_group_fields_nest()
1862 1887
 * @param $vars preprocess vars or form element
1863
 * @param $type The type of object beïng rendered
1888
 * @param $type The type of object being rendered
1864 1889
 * @return $element Array with re-arranged fields in forms.
1865 1890
 */
1866 1891
function field_group_build_entity_groups(&$vars, $type) {
......
1890 1915
    return $element;
1891 1916
  }
1892 1917

  
1918
  // No groups on the entity. Prerender removed empty field groups.
1919
  if (empty($element['#fieldgroups'])) {
1920
    return $element;
1921
  }
1922

  
1893 1923
  // Put groups inside content if we are rendering an entity_view.
1894
  foreach ($element['#groups'] as $group) {
1924
  foreach ($element['#fieldgroups'] as $group) {
1895 1925
    if (!empty($element[$group->group_name]) && $type != 'user_profile') {
1896 1926
      $vars['content'][$group->group_name] = $element[$group->group_name];
1897 1927
    }
......
1914 1944
 * @param Array $element
1915 1945
 *   The current element to analyse for grouping.
1916 1946
 * @param Array $vars
1917
 *   Rendering vars from the entity beïng viewed.
1947
 *   Rendering vars from the entity being viewed.
1918 1948
 */
1919 1949
function field_group_fields_nest(&$element, &$vars = NULL) {
1920 1950

  
......
1947 1977
    // Entity being viewed
1948 1978
    if ($vars) {
1949 1979
      // If not a group, check vars['content'] for empty field.
1950
      if (!isset($element['#groups'][$child_name]) && isset($vars['content'][$child_name])) {
1980
      if (!isset($element['#fieldgroups'][$child_name]) && isset($vars['content'][$child_name])) {
1951 1981
        $group_references[$parent_name][$child_name] = $vars['content'][$child_name];
1952 1982
        unset($vars['content'][$child_name]);
1953 1983
      }
1954
      elseif (!isset($element['#groups'][$child_name]) && isset($vars['user_profile'][$child_name])) {
1984
      elseif (!isset($element['#fieldgroups'][$child_name]) && isset($vars['user_profile'][$child_name])) {
1955 1985
        $group_references[$parent_name][$child_name] = $vars['user_profile'][$child_name];
1956 1986
        unset($vars['user_profile'][$child_name]);
1957 1987
      }

Formats disponibles : Unified diff