@LionSolution
Yes, I have created a custom listview file but I did not name it
custom/modules/Contacts/views/view.list.php
since that would then override the standard Contacts ListView and I do not want to do that.
I want to keep the current Contacts list as is and add another custom view.
So, here’s what I did.
The view file is just sample code to show something; the actual beans logic and variables displayed will change.
Create new listview file at
custom/modules/Contacts/views/view.contact_product.php
with the content:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/MVC/View/views/view.list.php');
class CustomContactsViewContact_Product extends ViewList {
public function display() {
require_once("data/BeanFactory.php");
$contactBean = BeanFactory::getBean( 'Contacts' );
// The get_full_list method returns an array of all objects/beans of that module
// Each top-level array element/row is one record contained as an object
// To access each record, use normal array access syntax: $contactArray[number]
// To access the variables of each record, use normal object/bean syntax: $contactArray[number]->variable_name
$contactArray = $contactBean->get_full_list(
$order_by = "last_name",
// The where conditions require you to include the table name
//$where = "contacts.last_name = 'Walden'",
$check_dates = true,
$show_deleted = 0,
);
if ( isset($contactArray) ) {
$number_rows = count( $contactArray , 0 );
} else {
$number_rows = 0;
$contactArray = array();
}
$Contact_Product_Smarty = new Sugar_Smarty();
$Contact_Product_Smarty->assign( 'level_one_header' , "This will be the first level heading" );
$Contact_Product_Smarty->assign( 'level_two_header' , "And this is the second level heading" );
$Contact_Product_Smarty->assign( 'number_rows' , $number_rows );
$Contact_Product_Smarty->assign( 'contact_array' , $contactArray );
$Contact_Product_Smarty->display('custom/modules/Contacts/templates/contact_product.tpl');
}
}
created the Smarty tpl file at
custom/modules/Contacts/templates/contact_product.tpl
with the content (again, simplified just to show something)
<h1>L1 Label: {$level_one_header}</h1>
<h2>L2 Label: {$level_two_header}</h2>
<p>The number of rows retrieved was {$number_rows}</p>
<ul>
{foreach name=contactArrayTpl from=$contact_array key=recordNumber item=contactRecord}
<li>Record {$recordNumber} for {$contactRecord->first_name} {$contactRecord->last_name} was last modified on {$contactRecord->date_modified}</li>
{/foreach}
</ul>
Registered the entryPoint in
custom/Extension/application/Ext/EntryPointRegistry/contactProductEntry.php
with the content:
<?php
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
$entry_point_registry['cpListView'] = array(
'file' => 'custom/modules/Contacts/views/view.contact_product.php',
'auth' => true,
);
Added a new controller entry at
custom/modules/Contacts/controller.php
with the content:
<?php
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
require_once('modules/Contacts/controller.php');
class CustomContactsController extends ContactsController
{
public function action_cpListView()
{
$this->view = 'contact_product';
}
}
I successfully see the results of the (mocked up) content when I use
https://{siteName}/index.php?module=Contacts&action=cpListView
But the view does NOT include the header bar (not sure of correct term to use here) with the column labels like you see in a normal listview, followed by the variables formatted to fit the columns.