2012-02-23 5 views
0

コードで2つのアクションを作成しました。Drupal 7で高度なアクションとトリガーを 'パッケージ化'する方法

function userbeep_action_info() { 
    return array(
     'userbeep_beep_action' => array(
      'type' => 'system', 
      'label' => t('Beep annoyingly'), 
      'configurable' => FALSE, 
      'triggers' => array('node_view', 'node_insert', 'node_update', 'node_delete') 
     ), 
     'userbeep_multiple_beep_action' => array(
      'type' => 'system', 
      'label' => t('Beep multiple times'), 
      'configurable' => TRUE, 
      'triggers' => array('node_view', 'node_insert', 'node_update', 'node_delete') 
     ) 
    ); 
} 

今、単純なアクション(すなわち非設定可能なもの)が自動的に私のトリガーのメニューに表示されますが、私はそれを使用する前にadmin/config/system/actionsに高度なものを作成する必要があります。

私のやりたいことは、モジュールが自動的に高度なアクションを作成することです。

1)モジュールをロードすると、インストールとアンインストールのために何かを.installファイルに追加します。

2)

理想的に機能を使用して、これらの設定をパッケージ化し、私が何をしたいのですが、このプログラムで)1を使用して、私はまた、機能について学ぶことに熱心です。私はモジュールをインストールしましたが、これを行うための明白な方法は見当たりませんでした。

また、これらのアクションを使用してトリガーをパッケージ化/設定する方法もありますので、ユーザーは手動でこれを設定する必要はありませんか?

答えて

2

1)これには、アクションAPIメソッドactions_saveactions_deleteを使用できます。 (includes/actions.incを参照)。

hook_installは()

// Action configuration parameters that you can also set by clicking on the 
// Configure link that shows next to a configurable action in 
// admin/config/system/actions 
$config['beep_count'] = 10; 
$config['beep_file'] = 'sound.mp3'; 
$aid = 
    actions_save(
    'userbeep_multiple_beep_action', // Name of the action callback method 
    'system', // Action group 
    $config, // An array of key-value pairs 
    t('Beep multiple times'), // Action label helpful in the Trigger UI 
    NULL // Create a new action 
); 
variable_set('my_module_actions', array($aid)); 

hook_uninstall()

$aids = variable_get('my_module_actions', array()); 
if (!empty($aids)) { 
    actions_delete($aids); 
} 

2)機能のエクスポートアクションをサポートしていますか?設定できないアクションをパッケージ化するには、hook_action_info()が十分です。以下に示すように

3)再び、コードを使用して、明示的にtrigger_assignmentsテーブルにエントリを追加することで、トリガーにアクションを割り当てることができます。

$query = db_insert('trigger_assignments')->fields('hook', 'aid', 'weight'); 
$hooks = array('node_insert', 'node_update', 'node_view', 'node_delete'); 
foreach ($hooks as $hook) { 
    $query->values(array(
    'hook' => $hook, 
    'aid' => 'userbeep_multiple_beep_action', 
    'weight' => 0 
)); 
} 
// Multi-value insert 
$query->execute(); 
+0

パーフェクトを、どうもありがとうございました! – persepolis

関連する問題