diff --git a/src/Form/NodeTabForm.php b/src/Form/NodeTabForm.php index fd27fab..5024b3a 100644 --- a/src/Form/NodeTabForm.php +++ b/src/Form/NodeTabForm.php @@ -36,7 +36,7 @@ class NodeTabForm extends FormBase { $form['#title'] = t('Newsletter @title', array('@title' => $node->getTitle())); - // We will need the node + // We will need the node. $form_state->set('node', $node); // Show newsletter sending options if newsletter has not been send yet. @@ -88,7 +88,7 @@ class NodeTabForm extends FormBase { ), ); - // Get the handler class + // Get the handler class. $handler_definitions = $recipient_handler_manager->getDefinitions(); $handler = $handler_definitions[$default_handler]; $class = $handler['class']; @@ -107,28 +107,36 @@ class NodeTabForm extends FormBase { else { $form['send']['recipient_handler']['#suffix'] = '
'; } - // Generate text to display in send field. + + // Add some text to describe the send situation. + $form['send']['count'] = array( + '#type' => 'item', + '#markup' => t('Send newsletter to @count subscribers.', array('@count' => $subscriber_count)), + ); if (!$config->get('mail.use_cron')) { - $send_text = t('Send newsletter to @count subscribers. Mails will be sent immediately.', array('@count' => $subscriber_count)); + $send_text = t('Mails will be sent immediately.', array('@count' => $subscriber_count)); } else { - $send_text = t('Send newsletter to @count subscribers. Mails will be sent when cron runs.', array('@count' => $subscriber_count)); - } - if(!$node->isPublished()){ - $send_text .= t('Sending is delayed until node is published.'); + $send_text = t('Mails will be sent when cron runs.', array('@count' => $subscriber_count)); } - $form['send']['text'] = array( + $form['send']['method'] = array( '#type' => 'item', - '#title' => $send_text, + '#markup' => $send_text, ); $form['send']['send_button'] = array( '#type' => 'submit', '#button_type' => 'primary', - '#value' => t('Send newsletter issue'), '#name' => 'send_now', - '#submit' => $node->isPublished() ? array('::submitSendNow') : array('::submitSendLater'), ); + if ($node->isPublished()) { + $form['send']['send_button']['#submit'] = array('::submitSendNow'); + $form['send']['send_button']['#value'] = t('Send now'); + } + else { + $form['send']['send_button']['#submit'] = array('::submitSendLater'); + $form['send']['send_button']['#value'] = t('Send on publish'); + } } else { $form['status'] = array( @@ -172,7 +180,7 @@ class NodeTabForm extends FormBase { $handler = $values['recipient_handler']; $handler_definitions = \Drupal::service('plugin.manager.simplenews_recipient_handler')->getDefinitions(); - // Get the handler class + // Get the handler class. $handler = $handler_definitions[$handler]; $class = $handler['class']; @@ -236,7 +244,7 @@ class NodeTabForm extends FormBase { * @param array $form * An associative array containing the structure of the form. */ - public function submitTestMail(array &$form, FormStateInterface $form_state){ + public function submitTestMail(array &$form, FormStateInterface $form_state) { module_load_include('inc', 'simplenews', 'includes/simplenews.mail'); simplenews_send_test($form_state->get('node'), $form_state->get('test_addresses')); } @@ -247,7 +255,7 @@ class NodeTabForm extends FormBase { * @param array $form * An associative array containing the structure of the form. */ - public function submitSendNow(array &$form, FormStateInterface $form_state){ + public function submitSendNow(array &$form, FormStateInterface $form_state) { $node = $form_state->get('node'); module_load_include('inc', 'simplenews', 'includes/simplenews.mail'); simplenews_add_node_to_spool($node); @@ -256,7 +264,7 @@ class NodeTabForm extends FormBase { drupal_set_message(t('Newsletter %title sent.', array('%title' => $node->getTitle()))); } else { - drupal_set_message(t('Newsletter %title pending.', array('%title' => $node->getTitle()))); + drupal_set_message(t('Newsletter issue %title pending.', array('%title' => $node->getTitle()))); } $node->save(); } @@ -267,10 +275,11 @@ class NodeTabForm extends FormBase { * @param array $form * An associative array containing the structure of the form. */ - public function submitSendLater(array &$form, FormStateInterface $form_state){ + public function submitSendLater(array &$form, FormStateInterface $form_state) { $node = $form_state->get('node'); // Set the node to pending status. $node->simplenews_issue->status = SIMPLENEWS_STATUS_SEND_PUBLISH; + drupal_set_message(t('Newsletter issue %title will be sent when published.', array('%title' => $node->getTitle()))); $node->save(); } diff --git a/src/Tests/SimplenewsAdministrationTest.php b/src/Tests/SimplenewsAdministrationTest.php index 239f84e..1955e06 100644 --- a/src/Tests/SimplenewsAdministrationTest.php +++ b/src/Tests/SimplenewsAdministrationTest.php @@ -39,7 +39,7 @@ class SimplenewsAdministrationTest extends SimplenewsTestBase { // Allow registration of new accounts without approval. $site_config = $this->config('user.settings'); - $site_config->set('verify_mail', false); + $site_config->set('verify_mail', FALSE); $site_config->save(); // Allow authenticated users to subscribe. @@ -245,10 +245,14 @@ class SimplenewsAdministrationTest extends SimplenewsTestBase { * Test newsletter subscription management. * * Steps performed: - * */ function testSubscriptionManagement() { - $admin_user = $this->drupalCreateUser(array('administer newsletters', 'administer simplenews settings', 'administer simplenews subscriptions', 'administer users')); + $admin_user = $this->drupalCreateUser(array( + 'administer newsletters', + 'administer simplenews settings', + 'administer simplenews subscriptions', + 'administer users' + )); $this->drupalLogin($admin_user); // Create a second newsletter. @@ -545,7 +549,7 @@ class SimplenewsAdministrationTest extends SimplenewsTestBase { // Get the subscriber id from the path. $this->assertTrue(preg_match('|admin/people/simplenews/edit/(\d+)$|', $this->getUrl(), $matches), 'Subscriber found'); - $subscriber = Subscriber::load($matches[1]); + $subscriber = Subscriber::load($matches[1]); $this->assertTitle(t('Edit subscriber @mail', array('@mail' => $subscriber->getMail())) . ' | Drupal'); $this->assertFieldChecked('edit-status'); @@ -603,7 +607,17 @@ class SimplenewsAdministrationTest extends SimplenewsTestBase { * Test content type configuration. */ function testContentTypes() { - $admin_user = $this->drupalCreateUser(array('administer blocks', 'administer content types', 'administer nodes', 'access administration pages', 'administer permissions', 'administer newsletters', 'administer simplenews subscriptions', 'bypass node access', 'send newsletter')); + $admin_user = $this->drupalCreateUser(array( + 'administer blocks', + 'administer content types', + 'administer nodes', + 'access administration pages', + 'administer permissions', + 'administer newsletters', + 'administer simplenews subscriptions', + 'bypass node access', + 'send newsletter' + )); $this->drupalLogin($admin_user); $this->drupalGet('admin/structure/types'); diff --git a/src/Tests/SimplenewsSendTest.php b/src/Tests/SimplenewsSendTest.php index 6041cf2..f900bb3 100644 --- a/src/Tests/SimplenewsSendTest.php +++ b/src/Tests/SimplenewsSendTest.php @@ -178,7 +178,8 @@ class SimplenewsSendTest extends SimplenewsTestBase { // The last newsletter shouldn't be published. if ($i != 2) { $this->drupalPostForm(NULL, $edit, ('Save and publish')); - } else { + } + else { $this->drupalPostForm(NULL, $edit, ('Save as unpublished')); } $this->assertTrue(preg_match('|node/(\d+)$|', $this->getUrl(), $matches), 'Node created');