Working on anther variation of implementing smarty and customcode in editview.
I have the dropdown sales stage. I want it to be editable by the admins (I’m passing this value to the editview as $isAdministrator). This part is working. However, if it’s closed won or closed lost, I no longer wish the stage to be editable.
I can ouput the “value” of sales_stage no problem, but struggling to output the Label for the value.
I’m currently trying this, but not sure if I’m implementing the syntax correctly. Anyone done this before?
6 =>
array (
0 =>
array(
'name' => 'sales_stage',
'label' =>'LBL_SALES_STAGE',
'customCode' => '{if $isAdministrator}
@@FIELD@@
{elseif $fields.sales_stage.value eq "Closed Won" || $fields.sales_stage.value eq "Closed Lost"}
<span>{$app_list_strings.sales_stage_dom[$fields.sales_stage.value]}</span>
{else}
@@FIELD@@
{/if}',
),
$app_list_strings… is always null.
Do I have to pass this value same as $isAdministrator? Or should this already be available in editview?
It never fails, I can work on something for hours, and 5 minutes after I pose a question, I figure it out. Well, at least maybe I’ll help someone else…
First you have to create a custom view.edit.php in /custom/modules/NAME OF MODULE/views
In this case I’m passing 3 things over to editview, readonly, $isAdministrator and the $app list.
class OpportunitiesViewEdit extends ViewEdit
{
public function __construct()
{
parent::__construct();
$this->useForSubpanel = true;
$this->useModuleQuickCreateTemplate = true;
}
public function display()
{
global $app_list_strings, $current_user;
// Check if the user is an administrator
$isAdministrator = $current_user->is_admin;
// Set the $readOnly variable based on the user's administrator status
$readOnly = $isAdministrator ? '' : 'readonly = "readonly"';
// Assign $readOnly to Smarty template
$this->ev->ss->assign('readOnly', $readOnly);
//Assign $isAdministrator to Smarty template
$this->ev->ss->assign('isAdministrator', $isAdministrator);
// Pass app_list_strings to Smarty template
$this->ev->ss->assign('APP_LIST', $app_list_strings);
parent::display(); // Call the parent display function to render the view
}
}
Then in editviewdefs.php, you can construct your custom code like this:
'customCode' => '{if $isAdministrator}
@@FIELD@@
{elseif $fields.sales_stage.value eq "Closed Won" || $fields.sales_stage.value eq "Closed Lost"}
<span>{$APP_LIST.sales_stage_dom[$fields.sales_stage.value]}</span>
{else}
@@FIELD@@
{/if}',
1 Like