Project

General

Profile

Revision 01f36513

Added by Assos Assos about 6 years ago

Weekly update of contrib modules

View differences:

drupal7/sites/all/modules/webform/components/grid.inc
324 324
 * @return array
325 325
 *   The merged array.
326 326
 */
327
function webform_grid_merge_options($existing, $new) {
327
function webform_grid_merge_options(array $existing, array $new) {
328 328
  $insert = NULL;
329 329
  $queue = array();
330 330
  foreach ($new as $key => $value) {
......
369 369
 * @return array
370 370
 *   The $row_options with any missing options replaced with empty values.
371 371
 */
372
function webform_grid_remove_options($header, $row_options) {
372
function webform_grid_remove_options(array $header, array $row_options) {
373 373
  foreach ($header as $key => $value) {
374 374
    if (!isset($row_options[$key])) {
375 375
      $header[$key] = '';
......
672 672
}
673 673

  
674 674
/**
675
 *
675
 * Theme function to render a grid component.
676 676
 */
677 677
function theme_webform_grid($variables) {
678 678
  $element = $variables['element'];
......
728 728
    $rows[] = array(
729 729
      'data' => $row,
730 730
      'class' => empty($question_element['#grid_question'])
731
      ? array('webform-component', 'webform-component-' . str_replace('_', '-', $question_element['#type']), 'webform-component--' . $parents)
731
      ? array(
732
        'webform-component',
733
        'webform-component-' . str_replace('_', '-', $question_element['#type']),
734
        'webform-component--' . $parents,
735
      )
732 736
      : array(),
733 737
    );
734 738
  }
735 739

  
736 740
  $option_count = count($header) - 1;
737
  return theme('table', array('header' => $header, 'rows' => $rows, 'sticky' => $element['#sticky'], 'attributes' => array('class' => array('webform-grid', 'webform-grid-' . $option_count))));
741
  return theme('table', array(
742
    'header' => $header,
743
    'rows' => $rows,
744
    'sticky' => $element['#sticky'],
745
    'attributes' => array(
746
      'class' => array(
747
        'webform-grid',
748
        'webform-grid-' . $option_count,
749
      ),
750
    ),
751
  ));
738 752
}
739 753

  
740 754
/**
741 755
 * Generate a table header suitable for form or html display.
756
 *
757
 * @param array $element
758
 *   The element array.
759
 * @param bool $right_titles
760
 *   If TRUE, display a right-side title column.
761
 *
762
 * @return array
763
 *   An array of headers.
742 764
 */
743
function _webform_grid_header($element, $right_titles) {
765
function _webform_grid_header(array $element, $right_titles) {
744 766
  $titles = explode('|', $element['#title'], 2);
745
  $header = array(array('data' => _webform_grid_header_title($element, $titles[0]), 'class' => array('webform-grid-question')));
767
  $header = array(
768
    array(
769
      'data' => _webform_grid_header_title($element, $titles[0]),
770
      'class' => array('webform-grid-question'),
771
    ),
772
  );
746 773
  foreach ($element['#grid_options'] as $option) {
747
    $header[] = array('data' => webform_filter_xss($option), 'class' => array('checkbox', 'webform-grid-option'));
774
    $header[] = array(
775
      'data' => webform_filter_xss($option),
776
      'class' => array('checkbox', 'webform-grid-option'),
777
      'scope' => 'col',
778
    );
748 779
  }
749 780
  if ($right_titles) {
750
    $header[] = array('data' => _webform_grid_header_title($element, isset($titles[1]) ? $titles[1] : ''), 'class' => array('webform-grid-question'));
781
    $header[] = array(
782
      'data' => _webform_grid_header_title($element, isset($titles[1]) ? $titles[1] : ''),
783
      'class' => array('webform-grid-question'),
784
    );
751 785
  }
752 786
  return $header;
753 787
}
......
801 835
    foreach ($element['#parents'] as $key) {
802 836
      $values = isset($values[$key]) ? $values[$key] : $values;
803 837
    }
804
    // Remove any values that aren't grid question (i.e. nested components)
838
    // Remove any values that aren't grid question (i.e. nested components).
805 839
    $grid_questions = $element['#grid_questions'];
806 840
    $values = array_intersect_key($values, $grid_questions);
807 841
    // Remove any unanswered grid questions.
......
810 844
    });
811 845
    // Give required errors for any questions that aren't answered.
812 846
    foreach (array_diff_key($grid_questions, $answers) as $question_key => $question) {
813
      form_error($element[$question_key], t('!question field within !name is required.', array('!question' => $question, '!name' => $element['#title'])));
847
      // If the question is still required (e.g not modified by an after_build
848
      // function), give the required error.
849
      if (!empty($element[$question_key]['#required'])) {
850
        form_error($element[$question_key], t('!question field within !name is required.', array('!question' => $question, '!name' => $element['#title'])));
851
      }
814 852
    }
815 853
  }
816 854
}

Also available in: Unified diff