Hi @Mac-Rae
Yes, I am learning Suite8. I am trying to add the “Send Mass Email” button in the list view.
public/legacy/modules/Contacts/metadata/listviewdefs.php
'print-as-pdf' => [
'key' => 'print-as-pdf',
'labelKey' => 'LBL_PRINT_AS_PDF',
'modes' => ['list'],
'acl' => ['view'],
'aclModule' => 'AOS_PDF_Templates',
'params' => [
'selectModal' => [
'module' => 'AOS_PDF_Templates'
],
'allowAll' => false,
'max' => 50
]
],
'send-mass-email' => [
'key' => 'send-mass-email',
'labelKey' => 'LBL_SEND_MASS_EMAIL',
'modes' => ['list'],
'acl' => ['view'],
'aclModule' => 'AOS_PDF_Templates',
'params' => [
'selectModal' => [
'module' => 'AOS_PDF_Templates'
],
'allowAll' => false,
'max' => 50
]
]
Now, I want to custom popup window instead of “AOS PDF Template” record list.
Yes, I want to rewrite the new code for Suite8. But any quick solutions for existing Suite7 existing code some changes. Later on, we will write fresh and new code for Suite8.
I read the Mass Update Bulk action code and clone the file. I do not have an idea how can I call this bulk action file?
core/backend/Process/Service/BulkActions/MassUpdateBulkAction.php clone the file and rename core/backend/Process/Service/BulkActions/SendMassEmailBulkAction.php
<?php
namespace App\Process\Service\BulkActions;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use App\Process\Entity\Process;
use App\Module\Service\ModuleNameMapperInterface;
use App\Process\Service\ProcessHandlerInterface;
class SendMassEmailBulkAction implements ProcessHandlerInterface
{
protected const MSG_OPTIONS_NOT_FOUND = 'Process options is not defined';
protected const PROCESS_TYPE = 'bulk-send-mass-email';
/**
* @var ModuleNameMapperInterface
*/
private $moduleNameMapper;
/**
* SendMassEmailBulkAction constructor.
* @param ModuleNameMapperInterface $moduleNameMapper
*/
public function __construct(ModuleNameMapperInterface $moduleNameMapper)
{
$this->moduleNameMapper = $moduleNameMapper;
}
/**
* @inheritDoc
*/
public function getProcessType(): string
{
return self::PROCESS_TYPE;
}
/**
* @inheritDoc
*/
public function requiredAuthRole(): string
{
return 'ROLE_USER';
}
/**
* @inheritDoc
*/
public function configure(Process $process): void
{
//This process is synchronous
//We aren't going to store a record on db
//thus we will use process type as the id
$process->setId(self::PROCESS_TYPE);
$process->setAsync(false);
}
/**
* @inheritDoc
*/
public function validate(Process $process): void
{
if (empty($process->getOptions())) {
throw new InvalidArgumentException(self::MSG_OPTIONS_NOT_FOUND);
}
$options = $process->getOptions();
[
'module' => $baseModule,
'ids' => $baseIds
] = $options;
['modalRecord' => $modalRecord] = $options;
[
'module' => $modalModule,
'id' => $modalId
] = $modalRecord;
if (empty($baseModule) || empty($baseIds) || empty($modalModule) || empty($modalId)) {
throw new InvalidArgumentException(self::MSG_OPTIONS_NOT_FOUND);
}
}
/**
* @inheritDoc
*/
public function run(Process $process)
{
$options = $process->getOptions();
$responseData = $this->getDownloadData($options);
$process->setStatus('success');
$process->setMessages([]);
$process->setData($responseData);
}
/**
* @param array|null $options
* @return array
*/
protected function getDownloadData(?array $options): array
{
['modalRecord' => $modalRecord] = $options;
[
'id' => $modalId
] = $modalRecord;
$responseData = [
'handler' => 'export',
'params' => [
'url' => 'legacy/index.php?templateID='.$modalId.'&entryPoint=formLetter',
'formData' => []
]
];
if (!empty($options['ids'])) {
$responseData = $this->getIdBasedRequestData($options, $responseData);
return $responseData;
}
return $responseData;
}
/**
* Get request data based on a list of ids
* @param array|null $options
* @param array $responseData
* @return array
*/
protected function getIdBasedRequestData(?array $options, array $responseData): array
{
[
'module' => $baseModule,
'ids' => $baseIds
] = $options;
$responseData['params']['formData'] = [
'uid' => implode(',', $baseIds),
'module' => $this->moduleNameMapper->toLegacy($baseModule),
'action' => 'index'
];
return $responseData;
}
}
Thanks
Asif Khalyani