本文整理汇总了PHP中Drupal\Core\Form\FormState::getError方法的典型用法代码示例。如果您正苦于以下问题:PHP FormState::getError方法的具体用法?PHP FormState::getError怎么用?PHP FormState::getError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Form\FormState
的用法示例。
在下文中一共展示了FormState::getError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bootstrap_preprocess_form_element
/**
* Preprocess form_element.
*/
function bootstrap_preprocess_form_element(&$variables)
{
$element =& $variables['element'];
$title_display = $element['#title_display'];
$name = !empty($element['#name']) ? $element['#name'] : FALSE;
$type = !empty($element['#type']) ? $element['#type'] : FALSE;
$checkbox = $type && $type === 'checkbox';
$radio = $type && $type === 'radio';
$has_tooltip = FALSE;
// This function is invoked as theme wrapper, but the rendered form element
// may not necessarily have been processed by Drupal::formBuilder()->doBuildForm().
$element += array('#title_display' => 'before');
// Check for errors and set correct error class.
$formState = new FormState();
if (isset($element['#parents']) && $formState->getError($element) || !empty($element['#required']) && bootstrap_setting('forms_required_has_error')) {
$variables['has_error'] = TRUE;
}
if (!empty($element['#autocomplete_route_name']) && Drupal::PathValidator($element['#autocomplete_route_name'])) {
$variables['is_autocomplete'] = TRUE;
}
// See http://getbootstrap.com/css/#forms-controls.
if (isset($element['#type'])) {
if ($radio) {
$variables['is_radio'] = TRUE;
} elseif ($checkbox) {
$variables['is_checkbox'] = TRUE;
} elseif ($type != 'hidden') {
$variables['is_form_group'] = TRUE;
}
}
// If #title is not set, we don't display any label or required marker.
if (!isset($element['#title'])) {
$element['#title_display'] = 'none';
}
$variables['title_display'] = $element['#title_display'];
// Add label_display and label variables to template.
$variables['label_display'] = $element['#title_display'];
// Place single checkboxes and radios in the label field.
if (($checkbox || $radio) && $title_display != 'none' && $title_display != 'invisible') {
$variables['label']['#children'] = $variables['children'];
unset($variables['children']);
unset($variables['description']);
// Pass the label attributes to the label, if available.
if (isset($variables['element']['#label_attributes'])) {
$variables['label']['#label_attributes'] = $variables['element']['#label_attributes'];
}
}
// Create variables for #input_group and #input_group_button flags.
if (isset($element['#input_group'])) {
$variables['input_group'] = $element['#input_group'];
}
if (isset($element['#input_group_button'])) {
$variables['input_group_button'] = $element['#input_group_button'];
}
$prefix = '';
$suffix = '';
if (isset($element['#field_prefix']) || isset($element['#field_suffix'])) {
// Determine if "#input_group" was specified.
if (!empty($element['#input_group'])) {
$prefix = array('#markup' => '<div class="input-group">' . (isset($element['#field_prefix']) ? '<span class="input-group-addon">' . $element['#field_prefix'] . '</span>' : ''));
$suffix = array('#markup' => (isset($element['#field_suffix']) ? '<span class="input-group-addon">' . $element['#field_suffix'] . '</span>' : '') . '</div>');
} elseif (!empty($element['#input_group_button'])) {
$prefix = array('#markup' => '<div class="input-group">' . (isset($element['#field_prefix']) ? '<span class="input-group-btn">' . $element['#field_prefix'] . '</span>' : ''));
$suffix = array('#markup' => (isset($element['#field_suffix']) ? '<span class="input-group-btn">' . $element['#field_suffix'] . '</span>' : '') . '</div>');
}
$render = \Drupal::service('renderer');
$variables['prefix'] = $render->render($prefix);
$variables['suffix'] = $render->render($suffix);
} else {
$variables['prefix'] = '';
$variables['suffix'] = '';
}
}
示例2: testGetError
/**
* Tests the getError() method.
*
* @covers ::getError
*
* @dataProvider providerTestGetError
*/
public function testGetError($errors, $parents, $error = NULL)
{
$element['#parents'] = $parents;
$form_state = new FormState(array('errors' => $errors));
$this->assertSame($error, $form_state->getError($element));
}