| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <?php
- /**
- * @file
- * Provides callbacks for ajax endpoints.
- */
- /**
- * Page callback to handle AJAX for editing a paragraphs item.
- *
- * This is a direct page callback. The actual job of deleting the item is
- * done in the submit handler for the button, so all we really need to
- * do is process the form and then generate output. We generate this
- * output by doing a replace command on the id of the entire form element.
- */
- function paragraphs_edit_js() {
- // drupal_html_id() very helpfully ensures that all html IDS are unique
- // on a page. Unfortunately what it doesn't realize is that the IDs
- // we are generating are going to replace IDs that already exist, so
- // this actually works against us.
- if (isset($_POST['ajax_html_ids'])) {
- unset($_POST['ajax_html_ids']);
- }
- list($form, $form_state) = ajax_get_form();
- drupal_process_form($form['#form_id'], $form, $form_state);
- // Get the information on what we're removing.
- $button = $form_state['triggering_element'];
- // Go two levels up in the form, to the whole widget.
- $element = drupal_array_get_nested_value($form, array_slice($button['#array_parents'], 0, -4));
- // Now send back the proper AJAX command to replace it.
- $return = array(
- '#type' => 'ajax',
- '#commands' => array(
- ajax_command_replace('#' . $element['#id'], drupal_render($element))
- ),
- );
- // Because we're doing this ourselves, messages aren't automatic. We have
- // to add them.
- $messages = theme('status_messages');
- if ($messages) {
- $return['#commands'][] = ajax_command_prepend('#' . $element['#id'], $messages);
- }
- return $return;
- }
- /**
- * Page callback to handle AJAX for collapse a paragraphs item.
- *
- * This is a direct page callback. The actual job of deleting the item is
- * done in the submit handler for the button, so all we really need to
- * do is process the form and then generate output. We generate this
- * output by doing a replace command on the id of the entire form element.
- */
- function paragraphs_collapse_js() {
- // drupal_html_id() very helpfully ensures that all html IDS are unique
- // on a page. Unfortunately what it doesn't realize is that the IDs
- // we are generating are going to replace IDs that already exist, so
- // this actually works against us.
- if (isset($_POST['ajax_html_ids'])) {
- unset($_POST['ajax_html_ids']);
- }
- list($form, $form_state) = ajax_get_form();
- drupal_process_form($form['#form_id'], $form, $form_state);
- // Get the information on what we're removing.
- $button = $form_state['triggering_element'];
- // Go two levels up in the form, to the whole widget.
- $element = drupal_array_get_nested_value($form, array_slice($button['#array_parents'], 0, -4));
- // Now send back the proper AJAX command to replace it.
- $return = array(
- '#type' => 'ajax',
- '#commands' => array(
- ajax_command_replace('#' . $element['#id'], drupal_render($element))
- ),
- );
- // Because we're doing this ourselves, messages aren't automatic. We have
- // to add them.
- $messages = theme('status_messages');
- if ($messages) {
- $return['#commands'][] = ajax_command_prepend('#' . $element['#id'], $messages);
- }
- return $return;
- }
- /**
- * Page callback to handle AJAX for removing a paragraphs item.
- *
- * This is a direct page callback. The actual job of deleting the item is
- * done in the submit handler for the button, so all we really need to
- * do is process the form and then generate output. We generate this
- * output by doing a replace command on the id of the entire form element.
- */
- function paragraphs_remove_js() {
- // drupal_html_id() very helpfully ensures that all html IDS are unique
- // on a page. Unfortunately what it doesn't realize is that the IDs
- // we are generating are going to replace IDs that already exist, so
- // this actually works against us.
- if (isset($_POST['ajax_html_ids'])) {
- unset($_POST['ajax_html_ids']);
- }
- list($form, $form_state) = ajax_get_form();
- drupal_process_form($form['#form_id'], $form, $form_state);
- // Get the information on what we're removing.
- $button = $form_state['triggering_element'];
- // Go two levels up in the form, to the whole widget.
- $element = drupal_array_get_nested_value($form, array_slice($button['#array_parents'], 0, -4));
- // Now send back the proper AJAX command to replace it.
- $return = array(
- '#type' => 'ajax',
- '#commands' => array(
- ajax_command_replace('#' . $element['#id'], drupal_render($element))
- ),
- );
- // Because we're doing this ourselves, messages aren't automatic. We have
- // to add them.
- $messages = theme('status_messages');
- if ($messages) {
- $return['#commands'][] = ajax_command_prepend('#' . $element['#id'], $messages);
- }
- return $return;
- }
- /**
- * Page callback to handle AJAX for removing a paragraphs item.
- *
- * This is a direct page callback. The actual job of deleting the item is
- * done in the submit handler for the button, so all we really need to
- * do is process the form and then generate output. We generate this
- * output by doing a replace command on the id of the entire form element.
- */
- function paragraphs_deleteconfirm_js() {
- // drupal_html_id() very helpfully ensures that all html IDS are unique
- // on a page. Unfortunately what it doesn't realize is that the IDs
- // we are generating are going to replace IDs that already exist, so
- // this actually works against us.
- if (isset($_POST['ajax_html_ids'])) {
- unset($_POST['ajax_html_ids']);
- }
- list($form, $form_state) = ajax_get_form();
- drupal_process_form($form['#form_id'], $form, $form_state);
- // Get the information on what we're removing.
- $button = $form_state['triggering_element'];
- // Go two levels up in the form, to the whole widget.
- $element = drupal_array_get_nested_value($form, array_slice($button['#array_parents'], 0, -4));
- // Now send back the proper AJAX command to replace it.
- $return = array(
- '#type' => 'ajax',
- '#commands' => array(
- ajax_command_replace('#' . $element['#id'], drupal_render($element))
- ),
- );
- // Because we're doing this ourselves, messages aren't automatic. We have
- // to add them.
- $messages = theme('status_messages');
- if ($messages) {
- $return['#commands'][] = ajax_command_prepend('#' . $element['#id'], $messages);
- }
- return $return;
- }
- /**
- * Page callback to handle AJAX for restoring a paragraphs item.
- *
- * This is a direct page callback. The actual job of deleting the item is
- * done in the submit handler for the button, so all we really need to
- * do is process the form and then generate output. We generate this
- * output by doing a replace command on the id of the entire form element.
- */
- function paragraphs_restore_js() {
- // drupal_html_id() very helpfully ensures that all html IDS are unique
- // on a page. Unfortunately what it doesn't realize is that the IDs
- // we are generating are going to replace IDs that already exist, so
- // this actually works against us.
- if (isset($_POST['ajax_html_ids'])) {
- unset($_POST['ajax_html_ids']);
- }
- list($form, $form_state) = ajax_get_form();
- drupal_process_form($form['#form_id'], $form, $form_state);
- // Get the information on what we're removing.
- $button = $form_state['triggering_element'];
- // Go two levels up in the form, to the whole widget.
- $element = drupal_array_get_nested_value($form, array_slice($button['#array_parents'], 0, -4));
- // Now send back the proper AJAX command to replace it.
- $return = array(
- '#type' => 'ajax',
- '#commands' => array(
- ajax_command_replace('#' . $element['#id'], drupal_render($element))
- ),
- );
- // Because we're doing this ourselves, messages aren't automatic. We have
- // to add them.
- $messages = theme('status_messages');
- if ($messages) {
- $return['#commands'][] = ajax_command_prepend('#' . $element['#id'], $messages);
- }
- return $return;
- }
|