• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Ajax\AjaxResponse类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Drupal\Core\Ajax\AjaxResponse的典型用法代码示例。如果您正苦于以下问题:PHP AjaxResponse类的具体用法?PHP AjaxResponse怎么用?PHP AjaxResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: ajaxOperation

  /**
   * Calls a method on an entity queue and reloads the listing page.
   *
   * @param \Drupal\entityqueue\EntityQueueInterface $entity_queue
   *   The view being acted upon.
   * @param string $op
   *   The operation to perform, e.g., 'enable' or 'disable'.
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The current request.
   *
   * @return \Drupal\Core\Ajax\AjaxResponse|\Symfony\Component\HttpFoundation\RedirectResponse
   *   Either returns a rebuilt listing page as an AJAX response, or redirects
   *   back to the listing page.
   */
  public function ajaxOperation(EntityQueueInterface $entity_queue, $op, Request $request) {
    // Perform the operation.
    $entity_queue->$op()->save();

    // If the request is via AJAX, return the rendered list as JSON.
    if ($request->request->get('js')) {
      $list = $this->entityManager()->getListBuilder('entity_queue')->render();
      $response = new AjaxResponse();
      $response->addCommand(new ReplaceCommand('#entity-queue-list', $list));
      return $response;
    }

    // Otherwise, redirect back to the page.
    return $this->redirect('entity.entity_queue.collection');
  }
开发者ID:jkyto,项目名称:agolf,代码行数:29,代码来源:EntityQueueUIController.php


示例2: submitEmailAjax

 /**
  * Ajax callback to validate the email field.
  */
 public function submitEmailAjax(array &$form, FormStateInterface $form_state)
 {
     $valid = $this->validateEmail($form, $form_state);
     $response = new AjaxResponse();
     if ($valid) {
         $css = ['border' => '1px solid green'];
         $message = $this->t('Email ok.');
     } else {
         $css = ['border' => '1px solid red'];
         $message = $this->t('Email not valid.');
     }
     // $response->addCommand(new CssCommand('#edit-email', $css));.
     $response->addCommand(new OpenModalDialogCommand('Alert', 'hello', array('width' => '700')));
     return $response;
 }
开发者ID:flesheater,项目名称:drupal8_modules_experiments,代码行数:18,代码来源:AjaxForm.php


示例3: ajaxSample

 /**
  * Ajax callback to render a sample of the input date format.
  *
  * @param array $form
  *   Form API array structure.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   Form state information.
  *
  * @return AjaxResponse
  *   Ajax response with the rendered sample date using the given format. If
  *   the given format cannot be identified or was empty, the response will
  *   be empty as well.
  */
 public static function ajaxSample(array $form, FormStateInterface $form_state)
 {
     $response = new AjaxResponse();
     $format_value = NestedArray::getValue($form_state->getValues(), $form_state->getTriggeringElement()['#array_parents']);
     if (!empty($format_value)) {
         // Format the date with a custom date format with the given pattern.
         // The object is not instantiated in an Ajax context, so $this->t()
         // cannot be used here.
         $format = t('Displayed as %date_format', array('%date_format' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', $format_value)));
         // Return a command instead of a string, since the Ajax framework
         // automatically prepends an additional empty DIV element for a string,
         // which breaks the layout.
         $response->addCommand(new ReplaceCommand('#edit-date-format-suffix', '<small id="edit-date-format-suffix">' . $format . '</small>'));
     }
     return $response;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:29,代码来源:DateFormat.php


示例4: ajaxSubmit

 public function ajaxSubmit(array &$form, FormStateInterface $form_state)
 {
     //---------------------------------------------------------------
     //            get the own attributes values of the swap
     //---------------------------------------------------------------
     //get all the swaps plugins
     $manager = \Drupal::service('plugin.manager.swaps');
     $swaps = $manager->getDefinitions();
     $swap = $swaps['column'];
     $input = $form_state->getUserInput();
     $settings = array();
     $settings['size'] = $input['swaps_column_size'];
     $settings['number'] = $input['swaps_column_number'];
     //---------------------------------------------------------------
     // get the default attributes values of the swap (required for visual help)
     //---------------------------------------------------------------
     $settings['swapId'] = $swap['id'];
     $settings['swapName'] = $swap['name'];
     $settings['container'] = $swap['container'];
     SwapDefaultAttributes::getDefaultFormElementsValues($settings, $input);
     //---------------------------------------------------------------
     //            create the ajax response
     //---------------------------------------------------------------
     $visualSettings = array('visualContentLayout' => array('attributes' => $settings));
     $response = new AjaxResponse();
     $response->addCommand(new CloseModalDialogCommand());
     $response->addCommand(new SettingsCommand($visualSettings, FALSE));
     return $response;
 }
开发者ID:KevinVillanuevaCordero,项目名称:visual-content-layout,代码行数:29,代码来源:ColumnAttributesForm.php


示例5: checkboxCallback

 /**
  * Ajax callback triggered by checkbox.
  */
 function checkboxCallback($form, FormStateInterface $form_state)
 {
     $response = new AjaxResponse();
     $response->addCommand(new HtmlCommand('#ajax_checkbox_value', (int) $form_state->getValue('checkbox')));
     $response->addCommand(new DataCommand('#ajax_checkbox_value', 'form_state_value_select', (int) $form_state->getValue('checkbox')));
     return $response;
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:10,代码来源:Callbacks.php


示例6: ajaxCallback

 /**
  * AJAX callback.
  */
 public function ajaxCallback($form, FormStateInterface $form_state)
 {
     $item = ['#type' => 'item', '#title' => $this->t('Ajax value'), '#markup' => microtime()];
     $response = new AjaxResponse();
     $response->addCommand(new HtmlCommand('#ajax-value', $item));
     return $response;
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:10,代码来源:AjaxTestImageEffect.php


示例7: validateEmailAjax

 public function validateEmailAjax(array &$form, FormStateInterface $form_state)
 {
     $httpClient = \Drupal::httpClient();
     $configuration = $this->config('gestiondenuncias.configuration');
     $pwd = $configuration->get('contrasena_verifyemail');
     $usr = $configuration->get('nombre_ususario_verifyemail');
     $email = $form_state->getValues('denunciante')['email'];
     $serverResponse = json_decode($httpClient->request('POST', "http://api.verify-email.org/api.php?usr={$usr}&pwd={$pwd}&check={$email}")->getBody()->getContents());
     $response = new AjaxResponse();
     if ($serverResponse->authentication_status != 1) {
         \Drupal::logger('gestiondenuncias.verify-email')->error('Los parametros de conexion a verify-email son incorrectos');
     } else {
         if ($serverResponse->limit_status) {
             \Drupal::logger('gestiondenuncias.verify-email')->error('Se llego al limite de consultas de verify-email');
         } else {
             if ($serverResponse->verify_status) {
                 $css = ['border' => '1px solid green'];
                 $message = $this->t('Email válido');
             } else {
                 $css = ['border' => '1px solid red'];
                 $message = $this->t('Email parece ser inválido');
             }
             $message = $message . $form_state->getValues()['denunciante']['email'];
             $response->addCommand(new CssCommand('#edit-email', $css));
             $response->addCommand(new HtmlCommand('.email-valid-message', $message));
         }
     }
     return $response;
 }
开发者ID:ErickMR19,项目名称:gestiondenuncias,代码行数:29,代码来源:EnviarDenunciaForm.php


示例8: checkboxCallback

 /**
  * Ajax callback triggered by checkbox.
  */
 function checkboxCallback($form, $form_state)
 {
     $response = new AjaxResponse();
     $response->addCommand(new HtmlCommand('#ajax_checkbox_value', (int) $form_state['values']['checkbox']));
     $response->addCommand(new DataCommand('#ajax_checkbox_value', 'form_state_value_select', (int) $form_state['values']['checkbox']));
     return $response;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:10,代码来源:Callbacks.php


示例9: onException

 /**
  * Catches a form AJAX exception and build a response from it.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
  *   The event to process.
  */
 public function onException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $request = $event->getRequest();
     // Render a nice error message in case we have a file upload which exceeds
     // the configured upload limit.
     if ($exception instanceof BrokenPostRequestException && $request->query->has(FormBuilderInterface::AJAX_FORM_REQUEST)) {
         $this->drupalSetMessage($this->t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', ['@size' => $this->formatSize($exception->getSize())]), 'error');
         $response = new AjaxResponse();
         $status_messages = ['#type' => 'status_messages'];
         $response->addCommand(new ReplaceCommand(NULL, $status_messages));
         $response->headers->set('X-Status-Code', 200);
         $event->setResponse($response);
         return;
     }
     // Extract the form AJAX exception (it may have been passed to another
     // exception before reaching here).
     if ($exception = $this->getFormAjaxException($exception)) {
         $request = $event->getRequest();
         $form = $exception->getForm();
         $form_state = $exception->getFormState();
         // Set the build ID from the request as the old build ID on the form.
         $form['#build_id_old'] = $request->get('form_build_id');
         try {
             $response = $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, []);
             // Since this response is being set in place of an exception, explicitly
             // mark this as a 200 status.
             $response->headers->set('X-Status-Code', 200);
             $event->setResponse($response);
         } catch (\Exception $e) {
             // Otherwise, replace the existing exception with the new one.
             $event->setException($e);
         }
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:41,代码来源:FormAjaxSubscriber.php


示例10: add

 /**
  * Custom ajax form submission handler.
  *
  * @param array $form
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *
  * @return \Drupal\Core\Ajax\AjaxResponse
  */
 public function add(array &$form, FormStateInterface $form_state)
 {
     $context = $form_state->getValue('contexts');
     $content = \Drupal::formBuilder()->getForm($this->getContextClass(), $context, $this->getTempstoreId(), $this->machine_name);
     $content['#attached']['library'][] = 'core/drupal.dialog.ajax';
     $response = new AjaxResponse();
     $response->addCommand(new OpenModalDialogCommand($this->t('Configure Required Context'), $content, array('width' => '700')));
     return $response;
 }
开发者ID:Wylbur,项目名称:gj,代码行数:17,代码来源:RequiredContext.php


示例11: getUntransformedText

 /**
  * Returns an Ajax response to render a text field without transformation filters.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity of which a formatted text field is being rerendered.
  * @param string $field_name
  *   The name of the (formatted text) field that that is being rerendered
  * @param string $langcode
  *   The name of the language for which the formatted text field is being
  *   rerendered.
  * @param string $view_mode_id
  *   The view mode the formatted text field should be rerendered in.
  *
  * @return \Drupal\Core\Ajax\AjaxResponse
  *   The Ajax response.
  */
 public function getUntransformedText(EntityInterface $entity, $field_name, $langcode, $view_mode_id)
 {
     $response = new AjaxResponse();
     // Direct text editing is only supported for single-valued fields.
     $field = $entity->getTranslation($langcode)->{$field_name};
     $editable_text = check_markup($field->value, $field->format, $langcode, array(FilterInterface::TYPE_TRANSFORM_REVERSIBLE, FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE));
     $response->addCommand(new GetUntransformedTextCommand($editable_text));
     return $response;
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:25,代码来源:EditorController.php


示例12: ajaxFormCallback

 public function ajaxFormCallback(array &$form, FormStateInterface $form_state)
 {
     dd('callback');
     //dd(array_keys($form['ajax_wrapper']));
     $response = new AjaxResponse();
     $response->addCommand(new HtmlCommand('#ajax_wrapper', $form['ajax_wrapper']));
     $status_messages = ['#type' => 'status_messages'];
     $response->addCommand(new HtmlCommand('.highlighted aside .region', $status_messages));
     return $response;
 }
开发者ID:mgrimard,项目名称:drupal8_ajax_form,代码行数:10,代码来源:AjaxForm.php


示例13: testPrepareResponseForIeFormRequestsWithFileUpload

 /**
  * Tests the support for IE specific headers in file uploads.
  *
  * @cover ::prepareResponse
  */
 public function testPrepareResponseForIeFormRequestsWithFileUpload()
 {
     $request = Request::create('/example', 'POST');
     $request->headers->set('Accept', 'text/html');
     $response = new AjaxResponse([]);
     $response->headers->set('Content-Type', 'application/json; charset=utf-8');
     $response->prepare($request);
     $this->assertEquals('text/html; charset=utf-8', $response->headers->get('Content-Type'));
     $this->assertEquals($response->getContent(), '<textarea>[]</textarea>');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:15,代码来源:AjaxResponseTest.php


示例14: switchViewMode

 /**
  * Returns an node through JSON.
  *
  * @param Request $request
  *  The global request object.
  * @param string $entityType
  *  The type of the requested entity.
  * @param string $entityId
  *  The id of the requested entity.
  * @param string $viewMode
  *  The view mode you wish to render for the requested entity.
  *
  * @return array
  *   The Views fields report page.
  */
 public function switchViewMode(Request $request, $entityType, $entityId, $viewMode)
 {
     $response = new AjaxResponse();
     $entity = entity_load($entityType, $entityId);
     if ($entity->access('view')) {
         $element = entity_view($entity, $viewMode);
         $content = \Drupal::service('renderer')->render($element, FALSE);
         $response->addCommand(new ReplaceCommand('.' . $request->get('selector'), $content));
     }
     return $response;
 }
开发者ID:neeravbm,项目名称:unify-d8,代码行数:26,代码来源:DsExtrasController.php


示例15: add

 public function add(array &$form, FormStateInterface $form_state)
 {
     $condition = $form_state->getValue('conditions');
     $content = \Drupal::formBuilder()->getForm($this->getConditionClass(), $condition, $this->getTempstoreId(), $this->machine_name);
     $content['#attached']['library'][] = 'core/drupal.dialog.ajax';
     list(, $route_parameters) = $this->getOperationsRouteInfo($this->machine_name, $form_state->getValue('conditions'));
     $content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $this->url($this->getAddRoute(), $route_parameters, ['query' => [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]]);
     $response = new AjaxResponse();
     $response->addCommand(new OpenModalDialogCommand($this->t('Configure Required Context'), $content, array('width' => '700')));
     return $response;
 }
开发者ID:AllieRays,项目名称:debugging-drupal-8,代码行数:11,代码来源:ManageConditions.php


示例16: preview

 /**
  * Returns an Ajax response to generate preview of embedded items.
  *
  * Expects the the HTML element as GET parameter.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  * @param \Drupal\filter\FilterFormatInterface $filter_format
  *   The filter format.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  *   Throws an exception if 'value' parameter is not found in the request.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *   The preview of the embedded item specified by the data attributes.
  */
 public function preview(Request $request, FilterFormatInterface $filter_format)
 {
     $text = $request->get('value');
     if ($text == '') {
         throw new NotFoundHttpException();
     }
     $output = check_markup($text, $filter_format->id());
     $response = new AjaxResponse();
     $response->addCommand(new EmbedInsertCommand($output));
     return $response;
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:27,代码来源:EmbedController.php


示例17: testPrepareResponseForIeFormRequestsWithFileUpload

 /**
  * Tests the support for IE specific headers in file uploads.
  *
  * @cover ::prepareResponse
  */
 public function testPrepareResponseForIeFormRequestsWithFileUpload()
 {
     $request = Request::create('/example', 'POST');
     $request->headers->set('Accept', 'text/html');
     $response = new AjaxResponse([]);
     $response->headers->set('Content-Type', 'application/json; charset=utf-8');
     $ajax_response_attachments_processor = $this->getMock('\\Drupal\\Core\\Render\\AttachmentsResponseProcessorInterface');
     $subscriber = new AjaxResponseSubscriber($ajax_response_attachments_processor);
     $event = new FilterResponseEvent($this->getMock('\\Symfony\\Component\\HttpKernel\\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST, $response);
     $subscriber->onResponse($event);
     $this->assertEquals('text/html; charset=utf-8', $response->headers->get('Content-Type'));
     $this->assertEquals($response->getContent(), '<textarea>[]</textarea>');
 }
开发者ID:318io,项目名称:318-io,代码行数:18,代码来源:AjaxResponseTest.php


示例18: AjaxResponse

 function er_browser_widget_search_content(array &$form, FormStateInterface $form_state)
 {
     $form = \Drupal::formBuilder()->getForm('Drupal\\er_browser_widget\\Form\\EntityReferenceBrowserWidgetForm');
     $response = new AjaxResponse();
     $title = $this->t('Entity Search and Reference.');
     $form['#attached']['library'][] = 'core/drupal.dialog.ajax';
     $response->setAttachments($form['#attached']);
     $content = views_embed_view('entity_reference_browser_widget');
     $options = array('dialogClass' => 'test-dialog', 'width' => '75%');
     $modal = new OpenModalDialogCommand($title, $form, $options);
     $response->addCommand($modal);
     return $response;
 }
开发者ID:karthikvaluebound,项目名称:er_browser_widget,代码行数:13,代码来源:EntityReferenceBrowserWidget.php


示例19: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $response = new AjaxResponse();
     if ($form_state->getErrors()) {
         unset($form['#prefix'], $form['#suffix']);
         $form['status_messages'] = ['#type' => 'status_messages', '#weight' => -10];
         $response->addCommand(new HtmlCommand('#editor-link-dialog-form', $form));
     } else {
         $response->addCommand(new EditorDialogSave($form_state->getValues()));
         $response->addCommand(new CloseModalDialogCommand());
     }
     return $response;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:16,代码来源:EditorLinkDialog.php


示例20: dialog

 /**
  * Util to render dialog in ajax callback.
  *
  * @param bool $is_modal
  *   (optional) TRUE if modal, FALSE if plain dialog. Defaults to FALSE.
  *
  * @return \Drupal\Core\Ajax\AjaxResponse
  *   An ajax response object.
  */
 protected function dialog($is_modal = FALSE)
 {
     $content = ajax_test_dialog_contents();
     $response = new AjaxResponse();
     $title = $this->t('AJAX Dialog contents');
     $html = drupal_render($content);
     if ($is_modal) {
         $response->addCommand(new OpenModalDialogCommand($title, $html));
     } else {
         $selector = '#ajax-test-dialog-wrapper-1';
         $response->addCommand(new OpenDialogCommand($selector, $title, $html));
     }
     return $response;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:23,代码来源:AjaxTestDialogForm.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Block\BlockBase类代码示例发布时间:2022-05-23
下一篇:
PHP Access\AccessResult类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap