ここで働く人、またはDrupalメニューのコールバックに関する情報をすばやく見つける方法

こんにちはHabrauser!



私はWEB開発者で、PHPでプログラムしています。 私の主な焦点は、CMS / CMF Drupalを使用したWebサイト開発です。 私は小さなIT組織で働いており、あらゆる種類のプロジェクト(大規模、小規模、新規、新規到着など)があります。 最近(私の場合、これはすでに1年です)、いくつかのプロジェクト、次に他のプロジェクト、そして他のプロジェクトに出くわします...そして基本的に、そのようなプロジェクトでは、顧客は原則として小さな何かを修正するように求めます(そこにフォームに要素を挿入しますただし、大規模なプロジェクトでは、「ここで何が機能しているのか」を判断できない場合があります。 どのモジュール?」 約2年前から筆は非常に便利で便利ですが、最も重要なことはページのレンダリングに時間を浪費しないことです(ページの作成には多くの時間がかかります)。 そして、コンソールを介してこのようなささいな情報を何らかの方法で学習することは素晴らしいことであることに気づきました。



ある種の既製のモジュラーベース(Drupalなど)に基づくほとんどのプロジェクトには、特定のプロジェクト、モジュール専用に作成された独自のモジュールが常にあります。 まあ、私たちの場合、それらの1つをdrushとの統合に使用する価値があります。 モジュールをcmと呼びます。 Drupal 6が使用されます。次に、ファイルcm.drush.incからコードを提供します。



ブラシコマンドの機能を記述するための標準フック:

/** * Implementation of hook_drush_help(). */ function cm_drush_help($section) { switch ($section) { case 'drush:browse-url': return dt('Show URL\'s info'); case 'drush:browse-theme': return dt('Show theme function info'); } } /** * Implements hook_drush_command(). */ function cm_drush_command() { $items = array(); $items['browse-url'] = array( 'description' => dt('Show URL\'s info.'), 'arguments' => array( 'url' => dt('URL from browser'), ), 'aliases' => array('burl'), ); $items['browse-theme'] = array( 'description' => dt('Show theme function info.'), 'arguments' => array( 'theme_item' => dt('theme function'), ), 'aliases' => array('btheme'), ); return $items; }
      
      







今すぐチームに直接



browse-url(burl)


このコマンドに渡されたコールバック情報を表示します

 function drush_cm_browse_url($url) { $url = drupal_get_normal_path($url); drush_print(dt('Original path is: "!path"', array('!path' => $url))); $router_item = menu_get_item($url); if($router_item['file']) { require_once($router_item['file']); } $data = array(); $data['path'] = $router_item['path']; $data['access_callback'] = $router_item['access_callback']; $data['access_arguments'] = implode(", ", unserialize($router_item['access_arguments'])); $data['page_callback'] = $router_item['page_callback']; $data['page_arguments'] = implode(", ", unserialize($router_item['page_arguments'])); $data['tab_root'] = $router_item['tab_root']; $data['title'] = $router_item['title']; $data['title_callback'] = $router_item['title_callback']; drush_print(_cm_getting_function_info($router_item['page_callback'])); drush_print_table(drush_key_value_to_array_table($data)); } function _cm_getting_function_info($function_name) { include_once './includes/install.inc'; drupal_load_updates(); if (strpos($function_name, '::') === FALSE) { if (!function_exists($function_name)) { return drush_set_error(dt('Function not found')); } $reflect = new ReflectionFunction($function_name); } else { list($class, $method) = explode('::', $function_name); if (!method_exists($class, $method)) { return drush_set_error(dt('Method not found')); } $reflect = new ReflectionMethod($class, $method); } $func_info = array('!file' => $reflect->getFileName(), '!startline' => $reflect->getStartLine(), '!endline' => $reflect->getEndLine()); //drush_print_pipe(dt("!file -line !startline", $func_info)); return dt("Execute in : !file, lines !startline-!endline", $func_info); }
      
      





チームの結果はかなりきれいです

 $ drush burl admin Original path is: "admin" Execute in : /var/www/d6/modules/system/system.admin.inc, lines 11-59 path : admin access_callback : user_access access_arguments : access administration pages page_callback : system_main_admin_page page_arguments : tab_root : admin title : Administer title_callback : t
      
      





元のパス(これは、突然エイリアスシステムが既に試行している場合)、どのファイル、どの行、メニューの適切な説明が表示されます。 とても便利ですね。 しかし真実は、たとえば次のようなコールバック `i-フォームがあります:

 drush burl admin/settings/file-system Original path is: "admin/settings/file-system" Execute in : /var/www/d6/includes/form.inc, lines 70-149 path : admin/settings/file-system access_callback : user_access access_arguments : administer site configuration page_callback : drupal_get_form page_arguments : system_file_system_settings tab_root : admin/settings/file-system title : File system title_callback : t
      
      





この場合、スクリプトは少なくともフォームを生成するための関数の名前を少なくとも表示するという観点からは有用です。



フックの説明には別のコマンドがあります。

閲覧テーマ(btheme)


 function drush_cm_browse_theme($theme_item) { init_theme(); $hooks = theme_get_registry(); var_dump($hooks[$theme_item]); }
      
      





テーマ機能に関する情報を示していますが、ここでの真実は、それがそのままドラフト形式で作成されたということです。

 $ drush btheme item_list array(7) { ["arguments"]=> array(4) { ["items"]=> array(0) { } ["title"]=> NULL ["type"]=> string(2) "ul" ["attributes"]=> NULL } ["type"]=> string(6) "module" ["theme path"]=> string(14) "modules/system" ["function"]=> string(15) "theme_item_list" ["include files"]=> array(0) { } ["theme paths"]=> array(1) { [0]=> string(14) "modules/system" } ["preprocess functions"]=> array(1) { [0]=> string(19) "template_preprocess" } }
      
      





これは、テーマ関数item_listに関する情報を出力する例です




これらすべてをDrupal 7に適応させるために、多くの時間は必要ありません(または、まったく必要ないかもしれません。正直に確認しませんでした)。



All Articles