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


PHP Ajax\AjaxResponse类代码示例

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


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


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