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


PHP Drupal::formBuilder方法代码示例

本文整理汇总了PHP中Drupal::formBuilder方法的典型用法代码示例。如果您正苦于以下问题:PHP Drupal::formBuilder方法的具体用法?PHP Drupal::formBuilder怎么用?PHP Drupal::formBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal的用法示例。


在下文中一共展示了Drupal::formBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getForm

 /**
  * Gets a form submitted via #ajax during an Ajax callback.
  *
  * This will load a form from the form cache used during Ajax operations. It
  * pulls the form info from the request body.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request object.
  *
  * @return array
  *   An array containing the $form and $form_state. Use the list() function
  *   to break these apart:
  *   @code
  *     list($form, $form_state, $form_id, $form_build_id) = $this->getForm();
  *   @endcode
  *
  * @throws Symfony\Component\HttpKernel\Exception\HttpExceptionInterface
  */
 protected function getForm(Request $request)
 {
     $form_state = \Drupal::formBuilder()->getFormStateDefaults();
     $form_build_id = $request->request->get('form_build_id');
     // Get the form from the cache.
     $form = form_get_cache($form_build_id, $form_state);
     if (!$form) {
         // If $form cannot be loaded from the cache, the form_build_id must be
         // invalid, which means that someone performed a POST request onto
         // system/ajax without actually viewing the concerned form in the browser.
         // This is likely a hacking attempt as it never happens under normal
         // circumstances.
         watchdog('ajax', 'Invalid form POST data.', array(), WATCHDOG_WARNING);
         throw new BadRequestHttpException();
     }
     // Since some of the submit handlers are run, redirects need to be disabled.
     $form_state['no_redirect'] = TRUE;
     // When a form is rebuilt after Ajax processing, its #build_id and #action
     // should not change.
     // @see \Drupal\Core\Form\FormBuilderInterface::rebuildForm()
     $form_state['rebuild_info']['copy']['#build_id'] = TRUE;
     $form_state['rebuild_info']['copy']['#action'] = TRUE;
     // The form needs to be processed; prepare for that by setting a few internal
     // variables.
     $form_state['input'] = $request->request->all();
     $form_id = $form['#form_id'];
     return array($form, $form_state, $form_id, $form_build_id);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:46,代码来源:FormAjaxController.php

示例2: view

 /**
  * {@inheritdoc}
  */
 public function view(OrderInterface $order, $view_mode)
 {
     if ($view_mode != 'customer') {
         // @todo Merge OrderUpdateForm into this plugin?
         return \Drupal::formBuilder()->getForm('\\Drupal\\uc_order\\Form\\OrderUpdateForm', $order);
     }
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:10,代码来源:UpdateOrder.php

示例3: testActionUrlBehavior

 /**
  * Tests form behaviour.
  */
 public function testActionUrlBehavior()
 {
     // Create a new request which has a request uri with multiple leading
     // slashes and make it the master request.
     $request_stack = \Drupal::service('request_stack');
     $original_request = $request_stack->pop();
     $request = Request::create($original_request->getSchemeAndHttpHost() . '//example.org');
     $request_stack->push($request);
     $form = \Drupal::formBuilder()->getForm($this);
     $markup = \Drupal::service('renderer')->renderRoot($form);
     $this->setRawContent($markup);
     $elements = $this->xpath('//form/@action');
     $action = (string) $elements[0];
     $this->assertEqual($original_request->getSchemeAndHttpHost() . '//example.org', $action);
     // Create a new request which has a request uri with a single leading slash
     // and make it the master request.
     $request_stack = \Drupal::service('request_stack');
     $original_request = $request_stack->pop();
     $request = Request::create($original_request->getSchemeAndHttpHost() . '/example.org');
     $request_stack->push($request);
     $form = \Drupal::formBuilder()->getForm($this);
     $markup = \Drupal::service('renderer')->renderRoot($form);
     $this->setRawContent($markup);
     $elements = $this->xpath('//form/@action');
     $action = (string) $elements[0];
     $this->assertEqual('/example.org', $action);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:30,代码来源:ExternalFormUrlTest.php

示例4: formBuilder

 /**
  * Returns the form builder.
  *
  * @return \Drupal\Core\Form\FormBuilderInterface
  *   The form builder.
  */
 protected function formBuilder()
 {
     if (!$this->formBuilder) {
         $this->formBuilder = \Drupal::formBuilder();
     }
     return $this->formBuilder;
 }
开发者ID:sedurzu,项目名称:ildeposito8,代码行数:13,代码来源:WorkflowConfigTransitionListBuilder.php

示例5: validateElement

 /**
  * Form validation handler for widget elements.
  *
  * @param array $element
  *   The form element.
  * @param array $form_state
  *   The form state.
  */
 public static function validateElement(array $element, array &$form_state)
 {
     if ($element['#required'] && $element['#value'] == '_none') {
         \Drupal::formBuilder()->setError($element, $form_state, t('!name field is required.', array('!name' => $element['#title'])));
     }
     // Massage submitted form values.
     // Drupal\Core\Field\WidgetBase::submit() expects values as
     // an array of values keyed by delta first, then by column, while our
     // widgets return the opposite.
     if (is_array($element['#value'])) {
         $values = array_values($element['#value']);
     } else {
         $values = array($element['#value']);
     }
     // Filter out the 'none' option. Use a strict comparison, because
     // 0 == 'any string'.
     $index = array_search('_none', $values, TRUE);
     if ($index !== FALSE) {
         unset($values[$index]);
     }
     // Transpose selections from field => delta to delta => field.
     $items = array();
     foreach ($values as $value) {
         $items[] = array($element['#key_column'] => $value);
     }
     form_set_value($element, $items, $form_state);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:35,代码来源:OptionsWidgetBase.php

示例6: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     // Return form inside block
     return $form = \Drupal::formBuilder()->getForm('Drupal\\krishna\\Form\\KrishnaForm');
     // Return simple text inside block
     return array('#type' => 'markup', '#markup' => $form);
 }
开发者ID:krknth,项目名称:d8p,代码行数:10,代码来源:KrishnaBlock.php

示例7: submitFormPage

 /**
  * Page that triggers a programmatic form submission.
  *
  * Returns the validation errors triggered by the form submission as json.
  */
 public function submitFormPage()
 {
     $form_state = new FormState();
     $values = ['name' => 'robo-user', 'mail' => 'robouser@example.com', 'op' => t('Submit')];
     $form_state->setValues($values);
     \Drupal::formBuilder()->submitForm('\\Drupal\\user\\Form\\UserPasswordForm', $form_state);
     return new JsonResponse($form_state->getErrors());
 }
开发者ID:systemick3,项目名称:systemick.co.uk,代码行数:13,代码来源:HoneypotTestController.php

示例8: validateFocalPoint

 /**
  * {@inheritDocs}
  *
  * Validate callback for the focal point field.
  */
 public static function validateFocalPoint($element, FormStateInterface $form_state)
 {
     $field_name = array_pop($element['#parents']);
     $focal_point_value = $form_state->getValue($field_name);
     if (!is_null($focal_point_value) && !FocalPoint::validate($focal_point_value)) {
         \Drupal::formBuilder()->setError($element, $form_state, t('The !title field should be in the form "leftoffset,topoffset" where offsets are in percents. Ex: 25,75.', array('!title' => $element['#title'])));
     }
 }
开发者ID:matt-schuh,项目名称:westminster-drops-8,代码行数:13,代码来源:FocalPointImageWidget.php

示例9: overview

 /**
  * {@inheritdoc}
  */
 public function overview(RouteMatchInterface $route_match, $entity_type_id = NULL)
 {
     $build = parent::overview($route_match, $entity_type_id);
     if (\Drupal::entityManager()->getAccessControlHandler('tmgmt_job')->createAccess()) {
         $build = \Drupal::formBuilder()->getForm('Drupal\\tmgmt_content\\Form\\ContentTranslateForm', $build);
     }
     return $build;
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:11,代码来源:ContentTranslationControllerOverride.php

示例10: update_selection_page

/**
 * Renders a form with a list of available database updates.
 */
function update_selection_page()
{
    // Make sure there is no stale theme registry.
    \Drupal::cache()->deleteAll();
    $build = \Drupal::formBuilder()->getForm('Drupal\\Core\\Update\\Form\\UpdateScriptSelectionForm');
    $build['#title'] = 'Drupal database update';
    return $build;
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:11,代码来源:update.php

示例11: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $build = [];
     $builder = \Drupal::formBuilder();
     $form = $builder->getForm('\\Drupal\\dday2015\\Form\\NodeGeneratorForm');
     $build['form'] = $form;
     return $build;
 }
开发者ID:drupalday,项目名称:drupalday_2015_drupal8_bedev,代码行数:11,代码来源:DDay2015Block.php

示例12: itemPage

 /**
  * {@inheritdoc}
  */
 public function itemPage(Request $request, RouteMatchInterface $route_match, $plugin_id)
 {
     $build = parent::itemPage($request, $route_match, $plugin_id);
     if (\Drupal::entityManager()->getAccessControlHandler('tmgmt_job')->createAccess()) {
         $build = \Drupal::formBuilder()->getForm('Drupal\\tmgmt_config\\Form\\ConfigTranslateForm', $build, $plugin_id);
     }
     return $build;
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:11,代码来源:ConfigTranslationControllerOverride.php

示例13: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $build = [];
     $build['default_block_my_text_area']['#markup'] = '<p>' . $this->configuration['my_text_area'] . '</p>';
     // Add a form to block.
     $build['default_block_new_form'] = \Drupal::formBuilder()->getForm('Drupal\\add_block\\Form\\NewForm');
     return $build;
 }
开发者ID:heykarthikwithu,项目名称:add_form_in_block,代码行数:11,代码来源:DefaultBlock.php

示例14: adminOverview

 /**
  * Returns an administrative overview of Imce Profiles.
  */
 public function adminOverview(Request $request)
 {
     // Build the settings form first.(may redirect)
     $output['settings_form'] = \Drupal::formBuilder()->getForm('Drupal\\imce\\Form\\ImceSettingsForm') + array('#weight' => 10);
     // Buld profile list.
     $output['profile_list'] = array('#type' => 'container', '#attributes' => array('class' => array('imce-profile-list')), 'title' => array('#markup' => '<h2>' . $this->t('Configuration Profiles') . '</h2>'), 'list' => $this->entityManager()->getListBuilder('imce_profile')->render());
     return $output;
 }
开发者ID:badelas,项目名称:afroweb,代码行数:11,代码来源:ImceController.php

示例15: testFormCheckbox

 function testFormCheckbox()
 {
     // Ensure that the checked state is determined and rendered correctly for
     // tricky combinations of default and return values.
     foreach (array(FALSE, NULL, TRUE, 0, '0', '', 1, '1', 'foobar', '1foobar') as $default_value) {
         // Only values that can be used for array indices are supported for
         // #return_value, with the exception of integer 0, which is not supported.
         // @see \Drupal\Core\Render\Element\Checkbox::processCheckbox().
         foreach (array('0', '', 1, '1', 'foobar', '1foobar') as $return_value) {
             $form_array = \Drupal::formBuilder()->getForm('\\Drupal\\form_test\\Form\\FormTestCheckboxTypeJugglingForm', $default_value, $return_value);
             $form = \Drupal::service('renderer')->renderRoot($form_array);
             if ($default_value === TRUE) {
                 $checked = TRUE;
             } elseif ($return_value === '0') {
                 $checked = $default_value === '0';
             } elseif ($return_value === '') {
                 $checked = $default_value === '';
             } elseif ($return_value === 1 || $return_value === '1') {
                 $checked = $default_value === 1 || $default_value === '1';
             } elseif ($return_value === 'foobar') {
                 $checked = $default_value === 'foobar';
             } elseif ($return_value === '1foobar') {
                 $checked = $default_value === '1foobar';
             }
             $checked_in_html = strpos($form, 'checked') !== FALSE;
             $message = format_string('#default_value is %default_value #return_value is %return_value.', array('%default_value' => var_export($default_value, TRUE), '%return_value' => var_export($return_value, TRUE)));
             $this->assertIdentical($checked, $checked_in_html, $message);
         }
     }
     // Ensure that $form_state->getValues() is populated correctly for a
     // checkboxes group that includes a 0-indexed array of options.
     $results = json_decode($this->drupalPostForm('form-test/checkboxes-zero/1', array(), 'Save'));
     $this->assertIdentical($results->checkbox_off, array(0, 0, 0), 'All three in checkbox_off are zeroes: off.');
     $this->assertIdentical($results->checkbox_zero_default, array('0', 0, 0), 'The first choice is on in checkbox_zero_default');
     $this->assertIdentical($results->checkbox_string_zero_default, array('0', 0, 0), 'The first choice is on in checkbox_string_zero_default');
     $edit = array('checkbox_off[0]' => '0');
     $results = json_decode($this->drupalPostForm('form-test/checkboxes-zero/1', $edit, 'Save'));
     $this->assertIdentical($results->checkbox_off, array('0', 0, 0), 'The first choice is on in checkbox_off but the rest is not');
     // Ensure that each checkbox is rendered correctly for a checkboxes group
     // that includes a 0-indexed array of options.
     $this->drupalPostForm('form-test/checkboxes-zero/0', array(), 'Save');
     $checkboxes = $this->xpath('//input[@type="checkbox"]');
     $this->assertIdentical(count($checkboxes), 9, 'Correct number of checkboxes found.');
     foreach ($checkboxes as $checkbox) {
         $checked = isset($checkbox['checked']);
         $name = (string) $checkbox['name'];
         $this->assertIdentical($checked, $name == 'checkbox_zero_default[0]' || $name == 'checkbox_string_zero_default[0]', format_string('Checkbox %name correctly checked', array('%name' => $name)));
     }
     $edit = array('checkbox_off[0]' => '0');
     $this->drupalPostForm('form-test/checkboxes-zero/0', $edit, 'Save');
     $checkboxes = $this->xpath('//input[@type="checkbox"]');
     $this->assertIdentical(count($checkboxes), 9, 'Correct number of checkboxes found.');
     foreach ($checkboxes as $checkbox) {
         $checked = isset($checkbox['checked']);
         $name = (string) $checkbox['name'];
         $this->assertIdentical($checked, $name == 'checkbox_off[0]' || $name == 'checkbox_zero_default[0]' || $name == 'checkbox_string_zero_default[0]', format_string('Checkbox %name correctly checked', array('%name' => $name)));
     }
 }
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:58,代码来源:CheckboxTest.php


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