/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
function ajax_add_to_my_vocabulary($form,&$form_state, $entity){ global $user ; // データがすでに存在するか否かのチェック $my_voca_result = db_query("SELECT entity_id FROM my_ch_vocabulary WHERE vid=".$entity->vid . " AND uid=".$user->uid)->fetchAll(); // ajaxコールバック時に使用するパラメーター $form_state['has_my_voca_result'] = count($my_voca_result)>0 ? true:false ; $form_state['ch_vocabulary'] = $entity ; // ajaxのチェックボックスフォーム定義 $form['ch_voca_form']=array( '#type' => 'checkbox', '#disabled' => $user->uid == 0 ? true : false , '#title' => count($my_voca_result)>0 ? t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>') : t('<span id="ch-voca-check-op-'.$entity->vid.'">Add</span>'), '#default_value' => count($my_voca_result)>0 ? 1 : 0, '#ajax' => array( 'callback' => 'add_to_my_vocabulary_callback', 'wrapper' => 'ch-voca-check-op-'.$entity->vid, 'method' => 'replace', 'effect' => 'fade', ), ); return $form ; } // ajaxのコールバック関数 function add_to_my_vocabulary_in_views($form, $form_state){ global $user; $entity = $form_state['ch_vocabulary'] ; // DBにデータがある場合に削除処理 if( $form_state['has_my_voca_result'] ) { db_delete( 'my_ch_vocabulary' )->condition( 'vid', $entity->vid )->condition('uid', $user->uid )->execute(); // チェックボックスのラベルを「Add」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Add</span>'); } // データがなければ、ch_vocabuaryをmy_vocabuaryにコピー $my_voca = entity_create('my_ch_vocabulary', array('vid'=>$entity->vid)); $my_voca_wrapper = entity_metadata_wrapper( 'my_ch_vocabulary', $my_voca ); $my_voca_wrapper->vocabulary->set( $ch_voca->vocabulary ) ; .... //各種フィールド、プロパティのセット $my_voca_wrapper->save(); // コピーされたデータの保存 // チェックボックスのラベルを「Remove」に変更 return t('<span id="ch-voca-check-op-'.$vid.'">Remove</span>'); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'ajax_add_to_my_vocabulary', 'page arguments' => array(array(), array(), 2) , 'access arguments' => array('create my vocabulary'), ); }
YOUR_MODULE_NAME_menu(){ $items['your/path/%entity'] = array( 'title' => 'Copy and Remove', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_add_to_my_vocabulary', 2) , 'access arguments' => array('create my vocabulary'), ); }
/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }
hook_menuで定義したページへのアクセス権限設定は「access callback」と「access arguments」で行います。特定なユーザーロール、特定なユーザーのみなどの制御が可能となります。特に、ユーザーのアクセス権限管理ページ(ホーム » 管理 » ユーザー » 権限)で各ページのアクセス権限管理が一般的で、よく利用されます。hook_menuがこのアクセス権限管理の実装方法を纏めます。
/** * Implements hook_permission(). */ function [my-module-name]_permission() { return array( 'authorize fbauth_connect' => array( 'title' => t('Connect Facebook account and store access token'), ), ); }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }