I have created a function in my module to show a view display, but it always show the default display. I have truncated all my cache* tables and nothing changed.
I am trying "page" display which have more fields than "default" view but it don't work. But if I go to the path of the view everything is OK. My function call is:
views_embed_view('cc_assentaments_view', 'page');
And my view code:
$view = new view;
$view->name = 'cc_assentaments_view';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'title' => array(
'label' => 'Title',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'valor' => array(
'label' => 'Valor de l\'assentament',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'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' => 'valor',
'table' => 'node_cc_assentaments',
'field' => 'valor',
'relationship' => 'none',
),
'data_assentament' => array(
'label' => 'Data de l\'assentament',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'date_format' => 'custom',
'custom_date_format' => 'd/m/Y',
'exclude' => 0,
'id' => 'data_assentament',
'table' => 'node_cc_assentaments',
'field' => 'data_assentament',
'relationship' => 'none',
),
'title_1' => array(
'id' => 'title_1',
'table' => 'proveidors_table',
'field' => 'title',
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'despesa' => 'despesa',
'ingres' => 'ingres',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'title' => array(
'operator' => 'allwords',
'value' => '',
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'use_operator' => 0,
'operator' => 'title_op',
'identifier' => 'Títol',
'label' => 'Títol',
'optional' => 1,
'remember' => 0,
),
'case' => 1,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'valor' => array(
'operator' => 'between',
'value' => array(
'value' => '',
'min' => '',
'max' => '',
),
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'use_operator' => 0,
'operator' => 'valor_op',
'identifier' => 'valor',
'label' => 'import entre',
'optional' => 1,
'remember' => 0,
),
'id' => 'valor',
'table' => 'node_cc_assentaments',
'field' => 'valor',
'relationship' => 'none',
),
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('use_ajax', TRUE);
$handler->override_option('items_per_page', 30);
$handler->override_option('use_pager', '1');
$handler->override_option('use_more', 1);
$handler->override_option('link_display', 'page_1');
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
'grouping' => '',
'override' => 1,
'sticky' => 0,
'order' => 'asc',
'columns' => array(
'title' => 'title',
'valor' => 'valor',
'data_assentament' => 'data_assentament',
),
'info' => array(
'title' => array(
'sortable' => 1,
'separator' => '',
),
'valor' => array(
'sortable' => 1,
'separator' => '',
),
'data_assentament' => array(
'sortable' => 1,
'separator' => '',
),
),
'default' => '-1',
));
$handler = $view->new_display('page', 'assentaments_projecte', 'page_1');
$handler->override_option('arguments', array(
'project_nid' => array(
'default_action' => 'ignore',
'style_plugin' => 'default_summary',
'style_options' => array(),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '',
'default_argument_type' => 'fixed',
'default_argument' => '',
'validate_type' => 'none',
'validate_fail' => 'not found',
'break_phrase' => 0,
'not' => 0,
'id' => 'project_nid',
'table' => 'node_cc_assentaments',
'field' => 'project_nid',
'validate_user_argument_type' => 'uid',
'validate_user_roles' => array(
'2' => 0,
'3' => 0,
),
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
'default_options_div_prefix' => '',
'default_argument_user' => 0,
'default_argument_fixed' => '',
'default_argument_php' => '',
'validate_argument_node_type' => array(
'despesa' => 0,
'ingres' => 0,
'prestec' => 0,
'cc_compte' => 0,
'cc_projecte' => 0,
'proveidor' => 0,
'working_unit' => 0,
'page' => 0,
'story' => 0,
),
'validate_argument_node_access' => 0,
'validate_argument_nid_type' => 'nid',
'validate_argument_vocabulary' => array(),
'validate_argument_type' => 'tid',
'validate_argument_transform' => 0,
'validate_user_restrict_roles' => 0,
'validate_argument_php' => '',
),
));
$handler->override_option('path', 'comptacau/cc_assentaments_view/assentaments_projecte');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
$handler = $view->new_display('page', 'assentaments_proveidor', 'page_2');
$handler->override_option('arguments', array(
'proveidor_nid' => array(
'default_action' => 'ignore',
'style_plugin' => 'default_summary',
'style_options' => array(),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '',
'default_argument_type' => 'fixed',
'default_argument' => '',
'validate_type' => 'none',
'validate_fail' => 'not found',
'break_phrase' => 1,
'not' => 0,
'id' => 'proveidor_nid',
'table' => 'node_cc_assentaments',
'field' => 'proveidor_nid',
'validate_user_argument_type' => 'uid',
'validate_user_roles' => array(
'2' => 0,
'3' => 0,
),
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
'default_options_div_prefix' => '',
'default_argument_user' => 0,
'default_argument_fixed' => '',
'default_argument_php' => '',
'validate_argument_node_type' => array(
'despesa' => 0,
'ingres' => 0,
'prestec' => 0,
'cc_compte' => 0,
'cc_projecte' => 0,
'proveidor' => 0,
'working_unit' => 0,
'page' => 0,
'story' => 0,
),
'validate_argument_node_access' => 0,
'validate_argument_nid_type' => 'nid',
'validate_argument_vocabulary' => array(),
'validate_argument_type' => 'tid',
'validate_argument_transform' => 0,
'validate_user_restrict_roles' => 0,
'validate_argument_php' => '',
),
));
$handler->override_option('path', 'comptacau/cc_assentaments_view/assentaments_proveidor');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
$handler = $view->new_display('page', 'projectes_assentaments', 'page_3');
$handler->override_option('fields', array(
'proveidor_nid' => array(
'label' => 'Nid del proveidor',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'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' => 1,
'link_to_node' => 0,
'id' => 'proveidor_nid',
'table' => 'node_cc_assentaments',
'field' => 'proveidor_nid',
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
),
'title' => array(
'label' => 'Nom proveïdor',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 1,
'path' => 'node/[proveidor_nid]',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'exclude' => 0,
'id' => 'title',
'table' => 'proveidors_table',
'field' => 'title',
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
),
'valor' => array(
'label' => 'Valor de l\'assentament',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'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' => 'valor',
'table' => 'node_cc_assentaments',
'field' => 'valor',
'relationship' => 'none',
),
'views_sql_groupedfields' => array(
'label' => 'Group By Fields',
'alter' => array(
'alter_text' => FALSE,
'text' => '',
'make_link' => FALSE,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'trim' => FALSE,
'max_length' => '',
'word_boundary' => TRUE,
'ellipsis' => TRUE,
'strip_tags' => FALSE,
'html' => FALSE,
),
'exclude' => '1',
'id' => 'views_sql_groupedfields',
'table' => 'views_groupby',
'field' => 'views_sql_groupedfields',
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
'views_groupby_fields_to_group' => array(
'proveidor_nid' => 'proveidor_nid',
'title' => 'title',
),
'views_groupby_sql_function' => 'sum',
'views_groupby_fields_to_aggregate' => array(
'valor' => 'valor',
),
'views_groupby_field_sortby' => 'title',
'views_groupby_sortby_direction' => 'asc',
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'despesa' => 'despesa',
'ingres' => 'ingres',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
'title' => array(
'operator' => 'allwords',
'value' => '',
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'use_operator' => 0,
'operator' => 'title_op',
'identifier' => 'title',
'label' => 'ComptaCAU assentaments: Nom proveïdor',
'optional' => 1,
'remember' => 0,
),
'case' => 1,
'id' => 'title',
'table' => 'proveidors_table',
'field' => 'title',
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
),
));
$handler->override_option('path', 'comptacau/cc_assentaments_view/proveidors_assentaments');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
$handler = $view->new_display('page', 'Page', 'page_4');
$handler->override_option('fields', array(
'title' => array(
'label' => 'Title',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'valor' => array(
'label' => 'Valor de l\'assentament',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'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' => 'valor',
'table' => 'node_cc_assentaments',
'field' => 'valor',
'relationship' => 'none',
),
'data_assentament' => array(
'label' => 'Data de l\'assentament',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'date_format' => 'custom',
'custom_date_format' => 'd/m/Y',
'exclude' => 0,
'id' => 'data_assentament',
'table' => 'node_cc_assentaments',
'field' => 'data_assentament',
'relationship' => 'none',
),
'title_1' => array(
'label' => 'Nom proveïdor',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'exclude' => 0,
'id' => 'title_1',
'table' => 'proveidors_table',
'field' => 'title',
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
),
'created' => array(
'label' => 'Post date',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'date_format' => 'small',
'custom_date_format' => '',
'exclude' => 0,
'id' => 'created',
'table' => 'node',
'field' => 'created',
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'despesa' => 'despesa',
'ingres' => 'ingres',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
));
$handler->override_option('path', 'prvoesafsdfaf');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
EDIT: Changed PHP to CODE filter because post was not displaying
Comments
Comment #1
merlinofchaos commentedThe problem is a relatively simple one: You don't have a display with the ID 'page'. You have have 'page_1', 'page_2', 'page_3', and 'page_4'.
Perhaps you want:
views_embed_view('cc_assentaments_view', 'page_1');Comment #2
merlinofchaos commentedBTW, we are not sure why but your post was coming up totally blank. My theory is that something in the code filter was barfing on the export.
Comment #3
enboig commentedbesides exporting my view, is there another way of knowing the id of a display?
Comment #4
merlinofchaos commentedYes, go to the theme: information link while looking at the display you're using. THe ID of your display will make up part of the theming possibilities. You may have to pick out the ID from the data you see rather than having it easily just pointed out to you; there are definitely improvements that still need to be made to this data.
Comment #6
grobemo commentedThanks for the pointer, Earl. This is just what I needed.
For the benefit for others looking to embed a particular display of a view, besides the default, here's what I did to find the ID for one of mine:
In the Views UI, choose the display that you want to embed. (For instance, if you have a block-type display called 'my_block', click 'my_block' near the top left corner of the UI.) Then click 'Theme: Information'. This will give you a long list of templates that Views consults in theming your view.
The first list of templates (in my case, at least) is 'Display output'. The last entry in that list should look something like views-view--YOUR-VIEW-NAME--block-1.tpl.php or views-view--YOUR-VIEW-NAME--page-2.tpl.php, etc. The ID for the view is the last part of that template name, with hyphens replaced by underscores. For instance, mine was views-view--blog-posts--block-1.tpl.php. The ID for my view was 'block_1' (note the underscore in place of the hyphen).
So, to embed that display from my view, I used the following code in my template.php file:
<?php $vars['blog_post'] = views_embed_view('blog_posts', 'block_1'); ?>And then I used
<?php print $blog_post; ?>in page.tpl.php to put that view exactly where I wanted it.Comment #7
JennySmith commentedYes, thank you, Earl.
I did find one simpler way to locate the view ID..... Click on the view you want to use. Mouseover any of the links in the edit menu. The text in between the next-to-last '/*/' is the view ID. For example, I see
.../admin/build/views/nojs/display/VIEW_NAME/page_1/style_plugin
when I mouseover the edit title link. "page_1" is my view ID.