当前位置: 首页>>代码示例>>PHP>>正文


PHP FormState::getError方法代码示例

本文整理汇总了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'] = '';
    }
}
开发者ID:sathishRio,项目名称:themes,代码行数:76,代码来源:form-element.vars.php

示例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));
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:13,代码来源:FormStateTest.php


注:本文中的Drupal\Core\Form\FormState::getError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。