// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
/** * Implements hook_init(). */ function YOUR_MODULE_NAME_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); }
<a href="text/ajax/nojs/1234" class="use-ajax">ajaxリンク</a>
/** * Implements hook_init(). */ function test_module_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system','drupal.ajax'); } /** * Implementation of hook_menu() */ function test_module_menu() { $items['test/ajax/%/%']=array( // URLの2,3番目がクライアント側で生成 'page callback' => 'ajax_node_response', 'page arguments' => array(2,3), // URLの2,3番目の引数をコールバック関数に渡す 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } function ajax_node_response($type="ajax", $nid=0){ $node = node_load( $nid, NULL, false ); $vnode = node_view($node); $output = theme('node', $vnode); if( $type="ajax" ){ $commands=array(); $commands[]=ajax_command_replace( '#block-system-main','<section id="block-system-main">'.$output.'</section>' ) ; $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver( $page ) ; // ajax対応ブラウザの結果 } else { $output = '<div id="content">'.$output.'</div>'; // ajax非対応ブラウザの結果 return $output; } }
function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ foreach( $form_state['input']['options']['vbo_operations'] as $key => $operation) { if( $operation['redirect_check'] && strlen( trim($operation['redirect_url']))>0 ) { variable_set( $key, $operation['redirect_url'] ); } else { if( !empty( variable_get($key) ) ) variable_del( $key ) ; } } foreach( $form['options']['vbo_operations'] as $key => &$operation ){ if( !is_array($operation) ) continue ; $redirect_url = variable_get($key); $dep_key = "edit-options-vbo-operations-" . str_replace("_", "-", str_replace("::","",$key) ) ; $operation['redirect_check'] = array( '#type' => 'checkbox', '#title' => t('Redirect page to after operation'), '#default_value' => $redirect_url ? 1 : 0 , '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), ), ); $operation['redirect_url'] = array( '#type' => 'textfield', '#title' => t('Provide label'), '#title_display' => 'invisible', '#default_value' => empty($redirect_url) ? "" : $redirect_url, '#dependency' => array( // Ctoolsのdependent systemに依存 $dep_key."-selected" => array(1), $dep_key . '-redirect-check' => array(1), ), '#dependency_count' => 2, ); } } }
function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { // collect all operations that has contained redirect_rul $redirect_arr = array(); foreach( $vbo->options['vbo_operations'] as $key => $operation ) { if( !empty( variable_get($key) ) ){ $redirect_arr[$key] = $key ; } } // add redirect step to #submit element if(isset($form['select'])) { // this is the form start step foreach( $form['select'] as $key => &$element ){ if( isset($redirect_arr[$key]) ){ // we check if there is any operation has redirect_url $element['#submit'][] = 'vbo_redirect_after_operation'; // only one is enough, we will detect witch one in the callback function break; } } // do operation with confirmation step // this is the confirmation step } else if( !$form_state['operation']->getAdminOption('skip_confirmation') ) { $form['actions']['submit']['#submit'][] = "vbo_redirect_after_operation_with_confirmation"; $form_state['redirect_to_after_operation'] = $form_state['operation']->getAdminOption('redirect_url'); } } /** * callback function that has called by operation * this is the form start step, we don't know if it has confirmation step or not * @param $form * @param $form_state */ function vbo_redirect_after_operation(&$form, &$form_state){ // the are multiple element can be operated // the right one that has be sent to this step // we need get redirect_url if the it has if( isset($form_state['operation']) ){ // get redirect_url by operation_id $redirec=variable_get($form_state['operation']->operationId) ; if( !empty($redirec) ){ if( $form_state['operation']->getAdminOption('skip_confirmation') ) { $form_state['redirect'] = $redirec; } } } } /** * callback function that has be called by operation with confirmation step * @param $form * @param $form_state */ function vbo_redirect_after_operation_with_confirmation( $form, &$form_state ){ // there is only operation that has be sent here with the confirmation step if( isset($form_state['redirect_to_after_operation']) ){ // set redirect_url that should be stored in $form_state $form_state['redirect'] = $form_state['redir ect_to_after_operation']; } }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.77 KB) | 1.77 KB |
/** * Implements hook_form_alter(). */ function vbo_redirect_option_form_alter(&$form, &$form_state, $form_id) { // VBOの処理かのチェック if( isset($form_state['id']) && $form_state['id'] === "views_bulk_operations"){ // ここで、画面遷移先の保存処理は少し反則 // vbo_settingsに画面遷移先の追加は難しい(クラス構造体内にあるため) // 環境変数に画面遷移先(uri)を保存 if( isset($form_state['input']['options']['vbo_settings'][vbo_redirect_url]) ){ variable_set( 'vbo_redirect_url', $form_state['input']['options']['vbo_settings'][vbo_redirect_url] ) ; } // 画面遷移先のテキストフィールドを追加 $form['options']['vbo_settings']['vbo_redirect_url'] = array( '#type' => 'textfield', '#title' => t('Page to direct to after completion of batch'), '#description' => t('Redirects to the view when finished the operation'), '#default_value' => variable_get('vbo_redirect_url'), ); } }
/** * Implements hook_views_bulk_operations_form_alter(). */ function vbo_redirect_option_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) { $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; if( isset($vbo_redirect_url) && strlen($vbo_redirect_url) >0 ){ // check if vbo operation skip confirmation $skip_confirmation = false ; foreach( $vbo->options['vbo_operations'] as $key => $operation ){ if( $operation['selected'] && $operation['skip_confirmation'] ){ if( isset($form['select'][$key]) ) { $form['select'][$key]['#submit'][] = 'vbo_redirect_after_operation'; $skip_confirmation = true ; } } } // set redirect method when vbo has confirmation step if( !$skip_confirmation ){ $form['actions']['submit']['#submit'][] = 'vbo_redirect_after_operation' ; } } } // callback function to set redirect url function vbo_redirect_after_operation($form, &$form_state){ $vbo_redirect_url = trim( variable_get('vbo_redirect_url') ) ; $form_state['redirect'] = $vbo_redirect_url; }
添付 | サイズ |
---|---|
vbo_redirect_option.zip (1.19 KB) | 1.19 KB |
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = ajax_command_invoke( null, 'removeElement', array("#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側で実行されるカスタム関数(removeElement) jQuery.fn.removeElement = function(ele_id) { jQuery( ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) // cssで要素の透明度をゼロにする .delay(1000).queue(function(){jQuery( ele_id ).remove()} ) ; // 1秒後に要素の削除 };
// サーバ側でカスタム関数(removeElement)にパラメータを渡して実行させる $commands = array(); $commands[] = array( 'command' => 'removeElement', 'ele_id' => "#del-div-".$entity->entity_id) ); return array( '#type'=>"ajax", '#commands' => $commands,); // クライアント側のカスタム関数(removeElement)の実行 Drupal.ajax.prototype.commands.removeElement = function(ajax, response, status) { jQuery( response.ele_id ) .css({'opacity':0, 'transition': 'all 1s' }) .delay(1000).queue(function(){jQuery( response.ele_id ).remove()}) ; }
// 削除エレメントID:123 (例) <a href="/delete/element/id/123/nojs" class="use-ajax del-link" id="del-link-123"> <i class="fa fa-trash-o" aria-hidden="true"></i> </a>
// 要素削除URLの設定 $items['delete/element/%/nojs'] = array( 'page callback' => 'delete_element', 'page arguments' => array( 2, 3 ) , 'access callback' => 'delete_access', 'type' => MENU_CALLBACK, ); // ajaxが以下のURLでリクエストをします(クライアント側でnojs->ajaxに変換) $items['delete/element/%/ajax'] = array( 'delivery callback' => 'ajax_deliver', )+$items['delete/element/%/nojs'] ; // 要素削除定義に遷移
function delete_element ($id, $ajax){ $is_ajax = $ajax === "ajax" ; // ajaxと通用のリクエスト両方対応のため // 要素をDBから削除 db_delete("element_table")->condition("entity_id", $id)->execute() ; // 画面要素も削除コマンドを返す if( $is_ajax ){ // ajaxで要素削除後の処理 $commands = array(); $commands[] = ajax_command_remove( '#element-123'); return array( '#type'=>"ajax", '#commands' => $commands, ); } else { // 通常での要素削除後の処理 drupal_set_message(t('Deleted 1 vocabulary')); drupal_goto(); } }