Показаны сообщения с ярлыком views. Показать все сообщения
Показаны сообщения с ярлыком views. Показать все сообщения

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!

31 авг. 2012 г.

Views group by по одному полю

В вьюсе для drupal 6 есть такой замечательный косяк, если добавляешь в хендлере

$this->query->add_groupby("node.nid");

то в group by добавляются все поля


чтобы все таки сделать группировку по нужным полям добавленным вручную
нужно сначала всем полям запретить добавляться в группировку:

//delete from group by all fields
       foreach($this->query->fields as $fieldname => $param){
         $this->query->fields[$fieldname]['aggregate'] = 1;  
       }
      
       $this->query->add_groupby("node.nid");


ps:
всавлял этот код в своем хендлере вроле работало,
еще можно вставить в hook_views_query_alter