在 drupal 中创建默认视图

发布于 2024-12-08 22:29:08 字数 6079 浏览 0 评论 0原文

我想从 mymodule 创建一个默认视图。我想使用 2 个表中的字段。我的基表是用户。显示用户的所有字段。我也想要 draagabaleviews_struct 中的字段。我查看了 hook_views_data。 draagabaleviews 组已在视图中。那么我如何加入该表?

function mymodule_views_default_views() {
$view = new view;
$view->name = 'my_view';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'users';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; 
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(

));
$handler->override_option('fields', array(

  'name' => array(
  'label' => 'Username',
  'alter' => array(
    'alter_text' => 0,
    'text' => '',
    'make_link' => 0,
    'path' => '',
    'link_class' => '',
    'alt' => '',
    'prefix' => '',
    'suffix' => '',
    'help' => '',
    'trim' => 0,
    'max_length' => '',
    'word_boundary' => 1,
    'ellipsis' => 1,
    'strip_tags' => 0,
    'html' => 0,
  ),
  'link_to_node' => 0,
  'exclude' => 0,
  'id' => 'name',
  'table' => 'users',
  'field' => 'name',
  'override' => array(
    'button' => 'Override',
  ),
  'relationship' => 'none',
 ),
'status' => array(
  'label' => 'Status',
  'alter' => array(
    'alter_text' => 0,
    'text' => '',
    'make_link' => 0,
    'path' => '',
    'link_class' => '',
    'alt' => '',
    'prefix' => '',
    'suffix' => '',
    'help' => '',
    'trim' => 0,
    'max_length' => '',
    'word_boundary' => 1,
    'ellipsis' => 1,
    'strip_tags' => 0,
    'html' => 0,
  ),
  'link_to_user' => 0,
  'overwrite_anonymous' => 0,
  'anonymous_text' => '',
  'exclude' => 0,
  'id' => 'status',
  'table' => 'users',
  'field' => 'status',
  'override' => array(
    'button' => 'Override',
  ),
  'relationship' => 'none',
 ),

'Last access' => array(
  'label' => 'Last access',
  'alter' => array(
    'alter_text' => 0,
    'text' => '',
    'make_link' => 0,
    'path' => '',
    'link_class' => '',
    'alt' => '',
    'prefix' => '',
    'suffix' => '',
    'help' => '',
    'trim' => 0,
    'max_length' => '',
    'word_boundary' => 1,
    'ellipsis' => 1,
    'strip_tags' => 0,
    'html' => 0,
  ),
 'link_to_user' => 0,
  'overwrite_anonymous' => 0,
  'anonymous_text' => '',
  'exclude' => 0,
  'id' => 'Last access',
  'table' => 'users',
  'field' => 'access',
  'override' => array(
    'button' => 'Override',
  ),
  'relationship' => 'none',
  ),
 'order' => array(
  'label' => 'Order',
  'alter' => array(
    'alter_text' => 0,
    'text' => '',
    'make_link' => 0,
    'path' => '',
    'link_class' => '',
    'alt' => '',
    'prefix' => '',
    'suffix' => '',
    'help' => '',
    'trim' => 0,
    'max_length' => '',
    'word_boundary' => 1,
    'ellipsis' => 1,
    'strip_tags' => 0,
    'html' => 0,
  ),
  'set_precision' => FALSE,
  'precision' => 0,
  'decimal' => '.',
  'separator' => ',',
  'prefix' => '',
  'suffix' => '',
  'exclude' => 0,
  'id' => 'order',
  'table' => 'draggableviews_structure',
  'field' => 'value',
  'relationship' => 'none',         
 ),
));
$handler->override_option('sorts', array(
'order' => array(
  'order' => 'ASC',
  'id' => 'Order',
  'table' => 'draggableviews_structure',
  'field' => 'value',
  'override' => array(
    'button' => 'Override',
  ),
  'relationship' => 'none',
 ),

 ));
 $handler->override_option('arguments', array(

));
$handler->override_option('access', array(
'type' => 'perm',
'perm' => 'Allow Reordering',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('empty', 'This book page doesn\'t contain any sub pages.');
$handler->override_option('empty_format', '1');
$handler->override_option('items_per_page', 20);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'draggabletable');
$handler->override_option('style_options', array(
'override' => 1,
'sticky' => 0,
'order' => 'asc',
'columns' => array(
  'title' => 'title',
  'name' => 'name',            
),
'info' => array(
  'title' => array(
    'sortable' => 0,
    'separator' => '',
  ),
  'name' => array(
    'sortable' => 0,
    'separator' => '',
  ),

),

'tabledrag_order' => array(
  'field' => 'order',
  'handler' => 'native',
),
'draggableviews_extensions' => array(
  'extension_top' => '3',
  'extension_bottom' => '3',
),
'tabledrag_order_visible' => array(
  'visible' => 1,
),
'tabledrag_hierarchy_visible' => array(
  'visible' => 0,
),
'draggableviews_depth_limit' => '0',
'draggableviews_repair' => array(
  'repair' => 'repair',
),
'tabledrag_types_add' => 'Add type',
'tabledrag_expand' => array(
  'expand_links' => 'expand_links',
  'collapsed' => 0,
  'by_draggableviews_structure' => 0,
),
'tabledrag_lock' => array(
  'lock' => 0,
),
'draggableviews_default_on_top' => '1',
'draggableviews_button_text' => 'Save order',
'draggableviews_arguments' => array(
  'use_args' => 0,
),
'draggableviews_book_radios' => '1',
'draggableviews_book_argument' => 'p',
'draggableviews_book_filter' => 'none',
));
 $handler = $view->new_display('page', 'Page', 'page_1');
 $handler->override_option('path', 'user/reorder');
 $handler->override_option('menu', array(
'type' => 'tab',
'title' => 'Rearrange',
'description' => 'Organize your book pages.',
'weight' => '10',
'name' => 'primary-links',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
 ));

 $views[$view->name] = $view;
 return $views;
}

i want to create a default view from mymodule. i want to use fields from 2 tables.My base table is users. All the fields from usres are showing. i want the fields from draagabaleviews_structure also. i had a look on hook_views_data. draagabaleviews group is already there in view.then how can i join that table??

function mymodule_views_default_views() {
$view = new view;
$view->name = 'my_view';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'users';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; 
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(

));
$handler->override_option('fields', array(

  'name' => array(
  'label' => 'Username',
  'alter' => array(
    'alter_text' => 0,
    'text' => '',
    'make_link' => 0,
    'path' => '',
    'link_class' => '',
    'alt' => '',
    'prefix' => '',
    'suffix' => '',
    'help' => '',
    'trim' => 0,
    'max_length' => '',
    'word_boundary' => 1,
    'ellipsis' => 1,
    'strip_tags' => 0,
    'html' => 0,
  ),
  'link_to_node' => 0,
  'exclude' => 0,
  'id' => 'name',
  'table' => 'users',
  'field' => 'name',
  'override' => array(
    'button' => 'Override',
  ),
  'relationship' => 'none',
 ),
'status' => array(
  'label' => 'Status',
  'alter' => array(
    'alter_text' => 0,
    'text' => '',
    'make_link' => 0,
    'path' => '',
    'link_class' => '',
    'alt' => '',
    'prefix' => '',
    'suffix' => '',
    'help' => '',
    'trim' => 0,
    'max_length' => '',
    'word_boundary' => 1,
    'ellipsis' => 1,
    'strip_tags' => 0,
    'html' => 0,
  ),
  'link_to_user' => 0,
  'overwrite_anonymous' => 0,
  'anonymous_text' => '',
  'exclude' => 0,
  'id' => 'status',
  'table' => 'users',
  'field' => 'status',
  'override' => array(
    'button' => 'Override',
  ),
  'relationship' => 'none',
 ),

'Last access' => array(
  'label' => 'Last access',
  'alter' => array(
    'alter_text' => 0,
    'text' => '',
    'make_link' => 0,
    'path' => '',
    'link_class' => '',
    'alt' => '',
    'prefix' => '',
    'suffix' => '',
    'help' => '',
    'trim' => 0,
    'max_length' => '',
    'word_boundary' => 1,
    'ellipsis' => 1,
    'strip_tags' => 0,
    'html' => 0,
  ),
 'link_to_user' => 0,
  'overwrite_anonymous' => 0,
  'anonymous_text' => '',
  'exclude' => 0,
  'id' => 'Last access',
  'table' => 'users',
  'field' => 'access',
  'override' => array(
    'button' => 'Override',
  ),
  'relationship' => 'none',
  ),
 'order' => array(
  'label' => 'Order',
  'alter' => array(
    'alter_text' => 0,
    'text' => '',
    'make_link' => 0,
    'path' => '',
    'link_class' => '',
    'alt' => '',
    'prefix' => '',
    'suffix' => '',
    'help' => '',
    'trim' => 0,
    'max_length' => '',
    'word_boundary' => 1,
    'ellipsis' => 1,
    'strip_tags' => 0,
    'html' => 0,
  ),
  'set_precision' => FALSE,
  'precision' => 0,
  'decimal' => '.',
  'separator' => ',',
  'prefix' => '',
  'suffix' => '',
  'exclude' => 0,
  'id' => 'order',
  'table' => 'draggableviews_structure',
  'field' => 'value',
  'relationship' => 'none',         
 ),
));
$handler->override_option('sorts', array(
'order' => array(
  'order' => 'ASC',
  'id' => 'Order',
  'table' => 'draggableviews_structure',
  'field' => 'value',
  'override' => array(
    'button' => 'Override',
  ),
  'relationship' => 'none',
 ),

 ));
 $handler->override_option('arguments', array(

));
$handler->override_option('access', array(
'type' => 'perm',
'perm' => 'Allow Reordering',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('empty', 'This book page doesn\'t contain any sub pages.');
$handler->override_option('empty_format', '1');
$handler->override_option('items_per_page', 20);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'draggabletable');
$handler->override_option('style_options', array(
'override' => 1,
'sticky' => 0,
'order' => 'asc',
'columns' => array(
  'title' => 'title',
  'name' => 'name',            
),
'info' => array(
  'title' => array(
    'sortable' => 0,
    'separator' => '',
  ),
  'name' => array(
    'sortable' => 0,
    'separator' => '',
  ),

),

'tabledrag_order' => array(
  'field' => 'order',
  'handler' => 'native',
),
'draggableviews_extensions' => array(
  'extension_top' => '3',
  'extension_bottom' => '3',
),
'tabledrag_order_visible' => array(
  'visible' => 1,
),
'tabledrag_hierarchy_visible' => array(
  'visible' => 0,
),
'draggableviews_depth_limit' => '0',
'draggableviews_repair' => array(
  'repair' => 'repair',
),
'tabledrag_types_add' => 'Add type',
'tabledrag_expand' => array(
  'expand_links' => 'expand_links',
  'collapsed' => 0,
  'by_draggableviews_structure' => 0,
),
'tabledrag_lock' => array(
  'lock' => 0,
),
'draggableviews_default_on_top' => '1',
'draggableviews_button_text' => 'Save order',
'draggableviews_arguments' => array(
  'use_args' => 0,
),
'draggableviews_book_radios' => '1',
'draggableviews_book_argument' => 'p',
'draggableviews_book_filter' => 'none',
));
 $handler = $view->new_display('page', 'Page', 'page_1');
 $handler->override_option('path', 'user/reorder');
 $handler->override_option('menu', array(
'type' => 'tab',
'title' => 'Rearrange',
'description' => 'Organize your book pages.',
'weight' => '10',
'name' => 'primary-links',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
 ));

 $views[$view->name] = $view;
 return $views;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天暗了我发光 2024-12-15 22:29:08

我遇到了同样的问题,我需要加入视图中的两个表。幸运的是,我找到了这些链接

http://drupalmodules.com/module/reverse-node-reference 模块通过节点引用字段的反向关系增强视图。

您可能还需要 http://drupal.org/project/noderelationships

这些是贡献的模块。因此,如果您想以编程方式执行相同的操作,那么您需要研究反向节点引用模块。

I was caught with the same issue where i needed to join the two table in view. fortunately i found these links

http://drupalmodules.com/module/reverse-node-reference module enhances views with reverse relationships for node reference fields.

you may also need http://drupal.org/project/noderelationships

These are contributed module. So if you want to do the same thing programmatically then you need to look into reverse-node-reference modules.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文