30 окт. 2012 г.

Аналог функции var_dump() в JavaScript


Как известно, в PHP функция var_dump() выводит в окно браузера дамп информации о переменной. Аналог в JavaScript:













<script type="text/javascript">
function dump(obj) {
    var out = "";
    if(obj && typeof(obj) == "object"){
        for (var i in obj) {
            out += i + ": " + obj[i] + "\n";
        }
    } else {
        out = obj;
    }
    alert(out);
}
</script>


29 окт. 2012 г.

Переопределение шаблона views в хуке views_view_fields

Hello! Today I'll tell you how to place views template files in your custom module's directory. It's easy to override views template within theme, but to achieve our goal we need write some code. We will override template for Views Row style output. Please, search views-view-fields.tpl.php file in views module directory.
Imagine, we have a view with name articles and page display. Let's go!
We need adjust module's weight through hook_install(). Place next code to your_module.install file.


Now place next code to your_module.module file.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
 * Implementation of hook_theme().
 */
function your_module_theme($existing) {
  $path = drupal_get_path('module', 'your_module');
  return array(
    'views_view_fields__articles__page_1' => array (
      'arguments' => array('view' => NULL, 'options' => NULL, 'row' => NULL),
      'template' => 'views-view-fields--articles--page-1',
      'original hook' => 'views_view_fields',
      'path' => $path,
    ),
  );
}
Note, you have to replace string in the brackets in this code with your data.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
 * Implementation of hook_theme().
 */
function your_module_theme($existing) {
  $path = drupal_get_path('module', 'your_module');
  return array(
    'views_view_fields__[view name]__[display id]' => array (
      'arguments' => array('view' => NULL, 'options' => NULL, 'row' => NULL),
      'template' => 'views-view-fields--[view name]--[display id]',
      'original hook' => 'views_view_fields',
      'path' => $path,
    ),
  );
}
Now views will find views-view-fields--articles--page-1.tpl.php file in your module's directory.
That's all!