Skip to content

Commit

Permalink
Merge pull request #29 from mailjet/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
goshon authored Jul 17, 2018
2 parents f350fe6 + 4550d85 commit 7d51fe6
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 17 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ Configuration
Author

## Changelog
= 8.x-2.0 =
* Remove depricated Global $language from stats module
* Enable user to sort subscription form parameters
* Add sort_fields field to the subscrioption form

= 8.x-1.3 =
* Fix Saving settings with "Send emails through Mailjet" unchecked overrides non-default Mail system
* Fix adding inline css and js with the subscription form
Expand Down
4 changes: 2 additions & 2 deletions mailjet.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Mailjet
description: Send your emails by your Mailjet API.
package: Mailjet
type: module
version: 8.x-1.3
version: 8.x-2.0
core: 8.x
configure: mailjet.settings

dependencies:
- libraries
- libraries
2 changes: 1 addition & 1 deletion modules/mailjet_stats/mailjet_stats.module
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function mailjet_stats_iframe() {

if (!empty($token)) {
global $base_url;
global $language;
$language = \Drupal::languageManager()->getCurrentLanguage();

$lang_codes_map = [
'en' => 'en_US',
Expand Down
38 changes: 38 additions & 0 deletions modules/mailjet_subscription/js/sort_properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(function ($) {

// Sorted field is empty by default
var sortedFieldsArray = [];

// Get last saved data value
var sortFieldsValue = $('#edit-sort-fields').val();
if (sortFieldsValue !== '') {
// Split last saved data to an array
sortedFieldsArray = $('#edit-sort-fields').val().split(',');
}

$("#mailjet-subscription-form-edit-form .form-checkboxes .form-checkbox").click(function () {
// Value of the checkbox that just has been clicked
var selectedProperty = $(this).val();

// Check if the property is alredy in the sorted array
var index = sortedFieldsArray.indexOf(selectedProperty);

if (index === -1) {
// Add property to the sorted array
sortedFieldsArray.push(selectedProperty);
} else {
// Remove property from the sorted array
sortedFieldsArray.splice($.inArray(selectedProperty, sortedFieldsArray), 1);
}

var sortedFieldsString = '';
if (sortedFieldsArray.length > 0) {
// Implode as string comma separated string
sortedFieldsString = sortedFieldsArray.join(',');
}

// Fill the sort field
$('#edit-sort-fields').val(sortedFieldsString);
});

})(jQuery);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sort_properties:
version: 1.0
js:
js/sort_properties.js: {}
dependencies:
- core/jquery
1 change: 1 addition & 0 deletions modules/mailjet_subscription/mailjet_subscription.module
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function mailjet_subscription_form_alter(&$form, FormStateInterface $form_state)
'#value' => t('Edit Labels'),
];
}
$form['#attached']['library'][] = 'mailjet_subscirption/sort_properties';
}

function mailjet_subscription_redicrect_to_edit_form(&$form, FormStateInterface $form_state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$counter_prop++;
}

// $form['mailjet_lists']['sort_fields'] = [];
// $form['mailjet_lists']['sort_fields'] = [
// '#type' => 'textfield',
// '#title' => t('You can sort the fields in your subscription form. To do that, enter their names in the desired order in the field below separated by <b> comma. </b>'),
// '#description' => t('Example: You have selected firstname, lastname and age. You wish to display them in <b> alphabetical order </b>. Do so by entering: <b>age, firstname, lastname</b>. Note: the email field is always displayed in first position.'),
// '#default_value' => $entity->sort_fields,
// ];
$form['mailjet_lists']['sort_fields'] = [];
$form['mailjet_lists']['sort_fields'] = [
'#type' => 'textfield',
'#title' => t('You can sort the fields in your subscription form. To do that, enter their names in the desired order in the field below separated by <b> comma. </b>'),
'#description' => t('Example: You have selected firstname, lastname and age. You wish to display them in <b> alphabetical order </b>. Do so by entering: <b>age, firstname, lastname</b>. Note: the email field is always displayed in first position.'),
'#default_value' => $entity->sort_fields,
];

$form['mailjet_lists']['ml_fields'] = [
'#type' => 'checkboxes',
Expand Down
14 changes: 7 additions & 7 deletions src/Form/MailjetSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$config_mailjet = $this->config('mailjet.settings');

$config1 = \Drupal::getContainer()
$config = \Drupal::getContainer()
->get('config.factory')
->getEditable('system.mail');

Expand All @@ -52,10 +52,10 @@ public function buildForm(array $form, FormStateInterface $form_state) {
];

if ($config_mailjet->get('mailjet_mail') == '1') {
$config1->set('interface.default', 'mailjet_mail')->save();
$config->set('interface.default', 'mailjet_mail')->save();
}

if ($config1->get('interface.default') == 'mailjet_mail') {
if ($config->get('interface.default') == 'mailjet_mail') {
$mailjet_on = TRUE;
}

Expand Down Expand Up @@ -335,16 +335,16 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
->get('config.factory')
->getEditable('mailjet.settings');

$config1 = \Drupal::getContainer()
$config = \Drupal::getContainer()
->get('config.factory')
->getEditable('system.mail');


if (!empty($form_state->getValue('mailjet_on'))) {
$config1->set('interface.default', 'mailjet_mail')->save();
$config->set('interface.default', 'mailjet_mail')->save();
}
else if($config1->get('interface.default') == 'mailjet_mail') {
$config1->set('interface.default', 'php_mail')->save();
else if($config->get('interface.default') == 'mailjet_mail') {
$config->set('interface.default', 'php_mail')->save();
}

$config_mailjet->set('mailjet_mail', 0);
Expand Down

0 comments on commit 7d51fe6

Please sign in to comment.