diff --git a/core/includes/form.inc b/core/includes/form.inc index 7d1a253..07516f5 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -1856,6 +1856,20 @@ function form_builder($form_id, &$element, &$form_state) { '#title_display' => 'before', ); + // Cheks if the element needs property validation. + if (isset($element['#property_validate']) && is_array($element['#property_validate'])) { + // Validates required properties. + foreach (array_filter($element['#property_validate']) as $property => $callback) { + if (!isset($element[$property]) || !$callback($element) == TRUE) { + throw new \UnexpectedValueException(t('@type element in form @form_id has a non-valid @property property.', array( + '@type' => $element['#type'], + '@form_id' => $form_id, + '@property' => $property, + ))); + } + } + } + // Special handling if we're on the top level form element. if (isset($element['#type']) && $element['#type'] == 'form') { if (!empty($element['#https']) && settings()->get('mixed_mode_sessions', FALSE) && @@ -5255,3 +5269,20 @@ function _batch_queue($batch_set) { /** * @} End of "defgroup batch". */ + +/** + * Validates the title property of a form component that requires it. + * @param $element + * The element definition to validate #title for. + */ +function element_validate_title(&$element) { + // Ensures that $title does not start with, end with or contain only spaces. + $title = trim($element['#title']); + // Ensures that $title contains a string by verifying its length. + if (strlen($title) !== 0) { + return TRUE; + } + else { + return false; + } +} diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index eefe926..58d66e3 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -2462,6 +2462,7 @@ function _install_configure_form($form, &$form_state, &$install_state) { ); $form['update_notifications']['update_status_module'] = array( '#type' => 'checkboxes', + '#title' => t('Update notifications'), '#options' => array( 1 => t('Check for updates automatically'), 2 => t('Receive e-mail notifications'), diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 725fcb6..e438410 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -329,6 +329,9 @@ function system_element_info() { '#autocomplete_path' => FALSE, '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'), '#pre_render' => array('form_pre_render_textfield'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'input__textfield', '#theme_wrappers' => array('form_element'), ); @@ -339,6 +342,9 @@ function system_element_info() { '#autocomplete_path' => FALSE, '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'), '#pre_render' => array('form_pre_render_tel'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'input__tel', '#theme_wrappers' => array('form_element'), ); @@ -351,6 +357,9 @@ function system_element_info() { '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'), '#element_validate' => array('form_validate_email'), '#pre_render' => array('form_pre_render_email'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'input__email', '#theme_wrappers' => array('form_element'), ); @@ -362,6 +371,9 @@ function system_element_info() { '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'), '#element_validate' => array('form_validate_url'), '#pre_render' => array('form_pre_render_url'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'input__url', '#theme_wrappers' => array('form_element'), ); @@ -372,6 +384,9 @@ function system_element_info() { '#autocomplete_path' => FALSE, '#process' => array('form_process_autocomplete', 'ajax_process_form'), '#pre_render' => array('form_pre_render_search'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'input__search', '#theme_wrappers' => array('form_element'), ); @@ -381,6 +396,9 @@ function system_element_info() { '#process' => array('ajax_process_form'), '#element_validate' => array('form_validate_number'), '#pre_render' => array('form_pre_render_number'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'input__number', '#theme_wrappers' => array('form_element'), ); @@ -392,6 +410,9 @@ function system_element_info() { '#process' => array('ajax_process_form'), '#element_validate' => array('form_validate_number'), '#pre_render' => array('form_pre_render_range'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'input__range', '#theme_wrappers' => array('form_element'), ); @@ -400,6 +421,9 @@ function system_element_info() { '#process' => array('ajax_process_form'), '#element_validate' => array('form_validate_color'), '#pre_render' => array('form_pre_render_color'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'input__color', '#theme_wrappers' => array('form_element'), ); @@ -413,6 +437,9 @@ function system_element_info() { '#process' => array('form_process_machine_name', 'form_process_autocomplete', 'ajax_process_form'), '#element_validate' => array('form_validate_machine_name'), '#pre_render' => array('form_pre_render_textfield'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'input__textfield', '#theme_wrappers' => array('form_element'), ); @@ -422,6 +449,9 @@ function system_element_info() { '#maxlength' => 128, '#process' => array('ajax_process_form', 'form_process_pattern'), '#pre_render' => array('form_pre_render_password'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'input__password', '#theme_wrappers' => array('form_element'), ); @@ -436,12 +466,18 @@ function system_element_info() { '#rows' => 5, '#resizable' => 'vertical', '#process' => array('ajax_process_form'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'textarea', '#theme_wrappers' => array('form_element'), ); $types['radios'] = array( '#input' => TRUE, '#process' => array('form_process_radios'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme_wrappers' => array('radios'), '#pre_render' => array('form_pre_render_conditional_form_element'), ); @@ -450,6 +486,9 @@ function system_element_info() { '#default_value' => NULL, '#process' => array('ajax_process_form'), '#pre_render' => array('form_pre_render_radio'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'input__radio', '#theme_wrappers' => array('form_element'), '#title_display' => 'after', @@ -458,6 +497,9 @@ function system_element_info() { '#input' => TRUE, '#process' => array('form_process_checkboxes'), '#pre_render' => array('form_pre_render_conditional_form_element'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme_wrappers' => array('checkboxes'), ); $types['checkbox'] = array( @@ -465,6 +507,9 @@ function system_element_info() { '#return_value' => 1, '#process' => array('form_process_checkbox', 'ajax_process_form'), '#pre_render' => array('form_pre_render_checkbox'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'input__checkbox', '#theme_wrappers' => array('form_element'), '#title_display' => 'after', @@ -473,6 +518,9 @@ function system_element_info() { '#input' => TRUE, '#multiple' => FALSE, '#process' => array('form_process_select', 'ajax_process_form'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'select', '#theme_wrappers' => array('form_element'), '#options' => array(), @@ -480,15 +528,24 @@ function system_element_info() { $types['language_select'] = array( '#input' => TRUE, '#default_value' => Language::LANGCODE_NOT_SPECIFIED, + '#property_validate' => array( + '#title' => 'element_validate_title', + ), ); $types['weight'] = array( '#input' => TRUE, '#delta' => 10, '#default_value' => 0, '#process' => array('form_process_weight', 'ajax_process_form'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), ); $types['date'] = array( '#input' => TRUE, + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'date', '#theme_wrappers' => array('form_element'), ); @@ -498,6 +555,9 @@ function system_element_info() { '#process' => array('form_process_file'), '#size' => 60, '#pre_render' => array('form_pre_render_file'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme' => 'input__file', '#theme_wrappers' => array('form_element'), ); @@ -543,6 +603,9 @@ function system_element_info() { '#value' => NULL, '#process' => array('form_process_group', 'ajax_process_form'), '#pre_render' => array('form_pre_render_group'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme_wrappers' => array('fieldset'), ); $types['details'] = array( @@ -550,6 +613,9 @@ function system_element_info() { '#value' => NULL, '#process' => array('form_process_group', 'ajax_process_form'), '#pre_render' => array('form_pre_render_details', 'form_pre_render_group'), + '#property_validate' => array( + '#title' => 'element_validate_title', + ), '#theme_wrappers' => array('details'), ); $types['vertical_tabs'] = array(