Commit 6f6288e2 authored by jaapjansma's avatar jaapjansma
Browse files

Added pre and post text

parent c51c50bf
......@@ -132,6 +132,9 @@ abstract class AbstractToken implements OutputInterface, TokenOutput {
));
$form->assign('help_text', $this->getHelpText());
$form->add('textarea', 'pre_text', E::ts('Pre text'), array('class' => 'huge'), false);
$form->add('textarea', 'post_text', E::ts('Post text'), array('class' => 'huge'), false);
$defaults = array();
if ($output) {
if (isset($output['configuration']) && is_array($output['configuration'])) {
......@@ -150,6 +153,12 @@ abstract class AbstractToken implements OutputInterface, TokenOutput {
if (isset($output['configuration']['all_data_setting'])) {
$defaults['all_data_setting'] = $output['configuration']['all_data_setting'];
}
if (isset($output['configuration']['pre_text'])) {
$defaults['pre_text'] = $output['configuration']['pre_text'];
}
if (isset($output['configuration']['post_text'])) {
$defaults['post_text'] = $output['configuration']['post_text'];
}
}
}
if (!isset($defaults['default_limit'])) {
......@@ -182,6 +191,8 @@ abstract class AbstractToken implements OutputInterface, TokenOutput {
$configuration['hidden_fields'] = $submittedValues['hidden_fields'];
$configuration['sort'] = $submittedValues['sortfield'];
$configuration['all_data_setting'] = $submittedValues['all_data_setting'];
$configuration['pre_text'] = $submittedValues['pre_text'];
$configuration['post_text'] = $submittedValues['post_text'];
return $configuration;
}
......@@ -273,7 +284,7 @@ abstract class AbstractToken implements OutputInterface, TokenOutput {
if ($allDataSetting) {
$allRecords = $dataProcessorClass->getDataFlow()->allRecords();
if ($allRecords) {
$this->processAllData($allDataSetting, $allRecords, $values, $availableFields, $name);
$this->processAllData($allDataSetting, $allRecords, $values, $availableFields, $name, $configuration);
$record = reset($allRecords);
}
} else {
......@@ -282,7 +293,7 @@ abstract class AbstractToken implements OutputInterface, TokenOutput {
} catch (EndOfFlowException $e) {
}
}
$this->process($record, $values, $availableFields, $name);
$this->process($record, $values, $availableFields, $name, $configuration);
}
/**
......@@ -292,12 +303,15 @@ abstract class AbstractToken implements OutputInterface, TokenOutput {
* @param array $values
* @param \Civi\DataProcessor\DataSpecification\FieldSpecification[] $availableFields
* @param string $name
* @param array $configuration
*
* @throws \Civi\DataProcessor\DataFlow\InvalidFlowException
*/
protected function process($record, &$values, $availableFields, $name) {
protected function process($record, &$values, $availableFields, $name, $configuration) {
$pre_text = isset($configuration['pre_text']) ? html_entity_decode($configuration['pre_text']) : '';
$post_text = isset($configuration['post_text']) ? html_entity_decode($configuration['post_text']) : '';
foreach($availableFields as $field) {
$values[$name.'.'.$field->alias] = $record[$field->alias]->formattedValue;
$values[$name.'.'.$field->alias] = $pre_text.$record[$field->alias]->formattedValue.$post_text;
}
}
......@@ -309,13 +323,16 @@ abstract class AbstractToken implements OutputInterface, TokenOutput {
* @param array $values
* @param \Civi\DataProcessor\DataSpecification\FieldSpecification[] $availableFields
* @param string $name
* @param array $configuration
*
* @throws \Civi\DataProcessor\DataFlow\InvalidFlowException
*/
protected function processAllData($allDataSetting, $records, &$values, $availableFields, $name) {
protected function processAllData($allDataSetting, $records, &$values, $availableFields, $name, $configuration) {
$pre_text = isset($configuration['pre_text']) ? html_entity_decode($configuration['pre_text']) : '';
$post_text = isset($configuration['post_text']) ? html_entity_decode($configuration['post_text']) : '';
$allDataOptions = $this->allDataOptions();
if (isset($allDataOptions[$allDataSetting]) && isset($allDataOptions[$allDataSetting]['callback'])) {
$values[$name.'.'.$allDataOptions[$allDataSetting]['token_name']] = call_user_func($allDataOptions[$allDataSetting]['callback'], $records, $availableFields);
$values[$name.'.'.$allDataOptions[$allDataSetting]['token_name']] = $pre_text.call_user_func($allDataOptions[$allDataSetting]['callback'], $records, $availableFields).$post_text;
}
}
......
......@@ -13,8 +13,8 @@
<url desc="Documentation">https://lab.civicrm.org/extensions/dataprocessor-token-output/blob/master/README.md</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2020-10-23</releaseDate>
<version>1.3</version>
<releaseDate>2020-11-25</releaseDate>
<version>1.4</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.13</ver>
......
......@@ -24,5 +24,19 @@
<div class="content">{$form.all_data_setting.html}</div>
<div class="clear"></div>
</div>
<div class="crm-section">
<div class="label">{$form.pre_text.label}</div>
<div class="content">{$form.pre_text.html}
<p class="description">{ts}The pre text is shown just before the rendered value of the token.{/ts}</p>
</div>
<div class="clear"></div>
</div>
<div class="crm-section">
<div class="label">{$form.post_text.label}</div>
<div class="content">{$form.post_text.html}
<p class="description">{ts}The post text is shown just after the rendered value of the token.{/ts}</p>
</div>
<div class="clear"></div>
</div>
{/crmScope}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment