protected function HubspotWebformHandler::buildSubscriptionRow in HubSpot 3.x
Build row for the subscription table.
Parameters
mixed $index: THe row id.
array $subscription_options: The subscription options.
array $default_values: The configured values.
Return value
array Render array for the row.
1 call to HubspotWebformHandler::buildSubscriptionRow()
- HubspotWebformHandler::buildConfigurationForm in src/
Plugin/ WebformHandler/ HubspotWebformHandler.php - Form constructor.
File
- src/
Plugin/ WebformHandler/ HubspotWebformHandler.php, line 387
Class
- HubspotWebformHandler
- Webform submission remote post handler.
Namespace
Drupal\hubspot\Plugin\WebformHandlerCode
protected function buildSubscriptionRow($index, array $subscription_options, array $webform_consent_fields_options, array $default_values = []) : array {
$row = [
'#attributes' => [
'id' => 'edit-settings-subscriptions-mapping-' . $index,
],
'subscription' => [
'#type' => 'select',
'#title' => $this
->t('Subscription Name'),
'#title_display' => 'invisible',
'#empty_option' => $this
->t('Select'),
'#required' => TRUE,
'#options' => $subscription_options,
'#parents' => [
'settings',
'subscriptions',
'mapping',
$index,
'subscription',
],
],
'mapping' => [
'#type' => 'container',
'#prefix' => '<div id="edit-settings-subscriptions-mapping-' . $index . '-mapping-wrapper">',
'#suffix' => '</div>',
'include' => [
'#type' => 'select',
'#title' => 'Include',
'#options' => [
'always' => $this
->t('Always'),
'conditionally' => $this
->t('Conditionally'),
],
'#ajax' => [
'callback' => [
$this,
'updateSubscriptionSource',
],
'event' => 'change',
'wrapper' => 'edit-settings-subscriptions-mapping-' . $index . '-mapping-wrapper',
],
'#required' => TRUE,
'#parents' => [
'settings',
'subscriptions',
'mapping',
$index,
'mapping',
'include',
],
],
],
'remove' => [
'#type' => 'button',
'#value' => $this
->t('Remove'),
'#ajax' => [
'callback' => [
$this,
'removeSubscription',
],
'event' => 'click',
'wrapper' => 'edit-settings-legal-consent-source-wrapper',
],
'#parents' => [
'settings',
'subscriptions',
'mapping',
$index,
'remove',
],
],
];
$components = $this->webform
->getElementsInitializedAndFlattened();
if ($default_values['mapping']['include'] == 'conditionally') {
$row['mapping']['element'] = [
'#type' => 'select',
'#title' => $this
->t('Element'),
'#states' => [
'visible' => [
'#edit-settings-subscriptions-mapping-' . $index . '-mapping-include' => [
'value' => 'conditionally',
],
],
],
'#required' => TRUE,
'#empty_option' => $this
->t('Select'),
'#options' => $webform_consent_fields_options,
'#ajax' => [
'callback' => [
$this,
'updateSubscriptionSource',
],
'event' => 'change',
'wrapper' => 'edit-settings-subscriptions-mapping-' . $index . '-mapping-wrapper',
],
'#parents' => [
'settings',
'subscriptions',
'mapping',
$index,
'mapping',
'element',
],
];
if (!empty($default_values['mapping']['element']) && isset($components[$default_values['mapping']['element']]) && isset($components[$default_values['mapping']['element']]['#options'])) {
$row['mapping']['value'] = [
'#type' => 'select',
'#title' => $this
->t('Value'),
'#required' => TRUE,
'#states' => [
'visible' => [
'#edit-settings-subscriptions-mapping-' . $index . '-include' => [
'value' => 'conditionally',
],
],
],
'#options' => $components[$default_values['mapping']['element']]['#options'],
'#parents' => [
'settings',
'subscriptions',
'mapping',
$index,
'mapping',
'option',
],
];
}
}
return $row;
}