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


PHP FormStateInterface::setResponse方法代码示例

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


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

示例1: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if (!empty($form_state['json'])) {
         $form_state->setResponse(new JsonResponse($form_state['values']));
     } else {
         $form_state['redirect'] = FALSE;
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:11,代码来源:FormTestCheckboxesZeroForm.php

示例2: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->get('json')) {
         $form_state->setResponse(new JsonResponse($form_state->getValues()));
     } else {
         $form_state->disableRedirect();
     }
 }
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:11,代码来源:FormTestCheckboxesZeroForm.php

示例3: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     /** @var \Drupal\payment\Entity\PaymentInterface $payment */
     $payment = $this->getEntity();
     /** @var \Drupal\payment\Plugin\Payment\Method\PaymentMethodCapturePaymentInterface $payment_method */
     $payment_method = $payment->getPaymentMethod();
     $result = $payment_method->capturePayment();
     if ($result->isCompleted()) {
         $form_state->setRedirectUrl($payment->urlInfo());
     } else {
         $form_state->setResponse($result->getCompletionResponse()->getResponse());
     }
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:16,代码来源:PaymentCaptureForm.php

示例4: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $form_state->setResponse(new JsonResponse($form_state['values']));
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:7,代码来源:FormTestCheckboxForm.php

示例5: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $form_connection_settings = $form_state->getValue('connection_settings');
     switch ($form_state->getTriggeringElement()['#name']) {
         case 'process_updates':
             // Save the connection settings to the DB.
             $filetransfer_backend = $form_connection_settings['authorize_filetransfer_default'];
             // If the database is available then try to save our settings. We have
             // to make sure it is available since this code could potentially (will
             // likely) be called during the installation process, before the
             // database is set up.
             try {
                 $connection_settings = array();
                 foreach ($form_connection_settings[$filetransfer_backend] as $key => $value) {
                     // We do *not* want to store passwords in the database, unless the
                     // backend explicitly says so via the magic #filetransfer_save form
                     // property. Otherwise, we store everything that's not explicitly
                     // marked with #filetransfer_save set to FALSE.
                     if (!isset($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save'])) {
                         if ($form['connection_settings'][$filetransfer_backend][$key]['#type'] != 'password') {
                             $connection_settings[$key] = $value;
                         }
                     } elseif ($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save']) {
                         $connection_settings[$key] = $value;
                     }
                 }
                 // Set this one as the default authorize method.
                 $this->config('system.authorize')->set('filetransfer_default', $filetransfer_backend);
                 // Save the connection settings minus the password.
                 $this->config('system.authorize')->set('filetransfer_connection_settings_' . $filetransfer_backend, $connection_settings);
                 $filetransfer = $this->getFiletransfer($filetransfer_backend, $form_connection_settings[$filetransfer_backend]);
                 // Now run the operation.
                 $response = $this->runOperation($filetransfer);
                 if ($response instanceof Response) {
                     $form_state->setResponse($response);
                 }
             } catch (\Exception $e) {
                 // If there is no database available, we don't care and just skip
                 // this part entirely.
             }
             break;
         case 'enter_connection_settings':
             $form_state->setRebuild();
             break;
         case 'change_connection_type':
             $form_state->setRebuild();
             $form_state->unsetValue(array('connection_settings', 'authorize_filetransfer_default'));
             break;
     }
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:53,代码来源:FileTransferAuthorizeForm.php

示例6: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $local_cache = NULL;
     if ($form_state->getValue('project_url')) {
         $local_cache = update_manager_file_get($form_state->getValue('project_url'));
         if (!$local_cache) {
             drupal_set_message($this->t('Unable to retrieve Drupal project from %url.', array('%url' => $form_state->getValue('project_url'))), 'error');
             return;
         }
     } elseif ($_FILES['files']['name']['project_upload']) {
         $validators = array('file_validate_extensions' => array(archiver_get_extensions()));
         if (!($finfo = file_save_upload('project_upload', $validators, NULL, 0, FILE_EXISTS_REPLACE))) {
             // Failed to upload the file. file_save_upload() calls
             // drupal_set_message() on failure.
             return;
         }
         $local_cache = $finfo->getFileUri();
     }
     $directory = _update_manager_extract_directory();
     try {
         $archive = update_manager_archive_extract($local_cache, $directory);
     } catch (\Exception $e) {
         drupal_set_message($e->getMessage(), 'error');
         return;
     }
     $files = $archive->listContents();
     if (!$files) {
         drupal_set_message($this->t('Provided archive contains no files.'), 'error');
         return;
     }
     // Unfortunately, we can only use the directory name to determine the
     // project name. Some archivers list the first file as the directory (i.e.,
     // MODULE/) and others list an actual file (i.e., MODULE/README.TXT).
     $project = strtok($files[0], '/\\');
     $archive_errors = $this->moduleHandler->invokeAll('verify_update_archive', array($project, $local_cache, $directory));
     if (!empty($archive_errors)) {
         drupal_set_message(array_shift($archive_errors), 'error');
         // @todo: Fix me in D8: We need a way to set multiple errors on the same
         // form element and have all of them appear!
         if (!empty($archive_errors)) {
             foreach ($archive_errors as $error) {
                 drupal_set_message($error, 'error');
             }
         }
         return;
     }
     // Make sure the Updater registry is loaded.
     drupal_get_updaters();
     $project_location = $directory . '/' . $project;
     try {
         $updater = Updater::factory($project_location, $this->root);
     } catch (\Exception $e) {
         drupal_set_message($e->getMessage(), 'error');
         return;
     }
     try {
         $project_title = Updater::getProjectTitle($project_location);
     } catch (\Exception $e) {
         drupal_set_message($e->getMessage(), 'error');
         return;
     }
     if (!$project_title) {
         drupal_set_message($this->t('Unable to determine %project name.', array('%project' => $project)), 'error');
     }
     if ($updater->isInstalled()) {
         drupal_set_message($this->t('%project is already installed.', array('%project' => $project_title)), 'error');
         return;
     }
     $project_real_location = drupal_realpath($project_location);
     $arguments = array('project' => $project, 'updater_name' => get_class($updater), 'local_url' => $project_real_location);
     // This process is inherently difficult to test therefore use a state flag.
     $test_authorize = FALSE;
     if (drupal_valid_test_ua()) {
         $test_authorize = \Drupal::state()->get('test_uploaders_via_prompt', FALSE);
     }
     // If the owner of the directory we extracted is the same as the owner of
     // our configuration directory (e.g. sites/default) where we're trying to
     // install the code, there's no need to prompt for FTP/SSH credentials.
     // Instead, we instantiate a Drupal\Core\FileTransfer\Local and invoke
     // update_authorize_run_install() directly.
     if (fileowner($project_real_location) == fileowner($this->sitePath) && !$test_authorize) {
         $this->moduleHandler->loadInclude('update', 'inc', 'update.authorize');
         $filetransfer = new Local($this->root);
         $response = call_user_func_array('update_authorize_run_install', array_merge(array($filetransfer), $arguments));
         if ($response instanceof Response) {
             $form_state->setResponse($response);
         }
     } else {
         // The page title must be passed here to ensure it is initially used when
         // authorize.php loads for the first time with the FTP/SSH credentials
         // form.
         system_authorized_init('update_authorize_run_install', __DIR__ . '/../../update.authorize.inc', $arguments, $this->t('Update manager'));
         $form_state->setRedirectUrl(system_authorized_get_url());
     }
 }
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:98,代码来源:UpdateManagerInstall.php

示例7: setResponse

 /**
  * {@inheritdoc}
  */
 public function setResponse(Response $response)
 {
     $this->mainFormState->setResponse($response);
     return $this;
 }
开发者ID:Laudanum,项目名称:authorization,代码行数:8,代码来源:SubFormState.php

示例8: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // If template is required, language code is not given.
     if ($form_state->getValue('langcode') != LanguageInterface::LANGCODE_SYSTEM) {
         $language = $this->languageManager->getLanguage($form_state->getValue('langcode'));
     } else {
         $language = NULL;
     }
     $content_options = $form_state->getValue('content_options', array());
     $reader = new PoDatabaseReader();
     $language_name = '';
     if ($language != NULL) {
         $reader->setLangcode($language->getId());
         $reader->setOptions($content_options);
         $languages = $this->languageManager->getLanguages();
         $language_name = isset($languages[$language->getId()]) ? $languages[$language->getId()]->getName() : '';
         $filename = $language->getId() . '.po';
     } else {
         // Template required.
         $filename = 'drupal.pot';
     }
     $item = $reader->readItem();
     if (!empty($item)) {
         $uri = tempnam('temporary://', 'po_');
         $header = $reader->getHeader();
         $header->setProjectName($this->config('system.site')->get('name'));
         $header->setLanguageName($language_name);
         $writer = new PoStreamWriter();
         $writer->setUri($uri);
         $writer->setHeader($header);
         $writer->open();
         $writer->writeItem($item);
         $writer->writeItems($reader);
         $writer->close();
         $response = new BinaryFileResponse($uri);
         $response->setContentDisposition('attachment', $filename);
         $form_state->setResponse($response);
     } else {
         drupal_set_message($this->t('Nothing to export.'));
     }
 }
开发者ID:brstde,项目名称:gap1,代码行数:44,代码来源:ExportForm.php

示例9: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Store maintenance_mode setting so we can restore it when done.
     $_SESSION['maintenance_mode'] = $this->state->get('system.maintenance_mode');
     if ($form_state->getValue('maintenance_mode') == TRUE) {
         $this->state->set('system.maintenance_mode', TRUE);
     }
     if (!empty($_SESSION['update_manager_update_projects'])) {
         // Make sure the Updater registry is loaded.
         drupal_get_updaters();
         $updates = array();
         $directory = _update_manager_extract_directory();
         $projects = $_SESSION['update_manager_update_projects'];
         unset($_SESSION['update_manager_update_projects']);
         $project_real_location = NULL;
         foreach ($projects as $project => $url) {
             $project_location = $directory . '/' . $project;
             $updater = Updater::factory($project_location, $this->root);
             $project_real_location = drupal_realpath($project_location);
             $updates[] = array('project' => $project, 'updater_name' => get_class($updater), 'local_url' => $project_real_location);
         }
         // If the owner of the last directory we extracted is the same as the
         // owner of our configuration directory (e.g. sites/default) where we're
         // trying to install the code, there's no need to prompt for FTP/SSH
         // credentials. Instead, we instantiate a Drupal\Core\FileTransfer\Local
         // and invoke update_authorize_run_update() directly.
         if (fileowner($project_real_location) == fileowner($this->sitePath)) {
             $this->moduleHandler->loadInclude('update', 'inc', 'update.authorize');
             $filetransfer = new Local($this->root);
             $response = update_authorize_run_update($filetransfer, $updates);
             if ($response instanceof Response) {
                 $form_state->setResponse($response);
             }
         } else {
             // The page title must be passed here to ensure it is initially used
             // when authorize.php loads for the first time with the FTP/SSH
             // credentials form.
             system_authorized_init('update_authorize_run_update', __DIR__ . '/../../update.authorize.inc', array($updates), $this->t('Update manager'));
             $form_state->setRedirectUrl(system_authorized_get_url());
         }
     }
 }
开发者ID:318io,项目名称:318-io,代码行数:45,代码来源:UpdateReady.php

示例10: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $values = $form_state->getValues();
     $form_state->setResponse(new JsonResponse($values['content'], (int) $values['status']));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:8,代码来源:FormTestResponseForm.php

示例11: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $form_connection_settings = $form_state->getValue('connection_settings');
     switch ($form_state->getTriggeringElement()['#name']) {
         case 'process_updates':
             // Save the connection settings to the DB.
             $filetransfer_backend = $form_connection_settings['authorize_filetransfer_default'];
             // If the database is available then try to save our settings. We have
             // to make sure it is available since this code could potentially (will
             // likely) be called during the installation process, before the
             // database is set up.
             try {
                 $filetransfer = $this->getFiletransfer($filetransfer_backend, $form_connection_settings[$filetransfer_backend]);
                 // Now run the operation.
                 $response = $this->runOperation($filetransfer);
                 if ($response instanceof Response) {
                     $form_state->setResponse($response);
                 }
             } catch (\Exception $e) {
                 // If there is no database available, we don't care and just skip
                 // this part entirely.
             }
             break;
         case 'enter_connection_settings':
             $form_state->setRebuild();
             break;
         case 'change_connection_type':
             $form_state->setRebuild();
             $form_state->unsetValue(array('connection_settings', 'authorize_filetransfer_default'));
             break;
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:35,代码来源:FileTransferAuthorizeForm.php

示例12: setResponse

 /**
  * {@inheritdoc}
  */
 public function setResponse(Response $response)
 {
     $this->decoratedFormState->setResponse($response);
     return $this;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:8,代码来源:FormStateDecoratorBase.php

示例13: testSetResponse

 /**
  * @covers ::setResponse
  */
 public function testSetResponse()
 {
     $response = $this->getMock(Response::class);
     $this->decoratedFormState->setResponse($response)->shouldBeCalled();
     $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setResponse($response));
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:9,代码来源:FormStateDecoratorBaseTest.php


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