diff --git a/scheduler.module b/scheduler.module index d7d5d9c..25f9eec 100644 --- a/scheduler.module +++ b/scheduler.module @@ -550,6 +550,7 @@ function scheduler_form_alter(&$form, $form_state) { '#required' => $publishing_required, '#default_value' => isset($defaults->publish_on) && $defaults->publish_on ? format_date($defaults->publish_on, 'custom', $internal_date_format) : '', '#description' => filter_xss(implode(' ', $descriptions)), + '#value_callback' => 'scheduler_date_value_callback', ); if ($use_date_popup) { // Make this a popup calendar widget. @@ -576,6 +577,7 @@ function scheduler_form_alter(&$form, $form_state) { '#required' => $unpublishing_required, '#default_value' => isset($defaults->unpublish_on) && $defaults->unpublish_on ? format_date($defaults->unpublish_on, 'custom', $internal_date_format) : '', '#description' => filter_xss(implode(' ', $descriptions)), + '#value_callback' => 'scheduler_date_value_callback', ); if ($use_date_popup) { @@ -593,6 +595,25 @@ function scheduler_form_alter(&$form, $form_state) { } /** + * Callback function for the Scheduler date entry elements. + */ +function scheduler_date_value_callback(&$element, $input = FALSE, &$form_state) { + // When processing a delete operation the user should not be forced to enter a + // date. Hence set the scheduler date element's #required attribute to FALSE. + // Test the input operation against $form_state['values']['delete'] as this + // will match the value of the Delete button even if translated. + if (isset($form_state['input']['op']) && isset($form_state['values']['delete']) && $form_state['input']['op'] == $form_state['values']['delete']) { + $element['#required'] = FALSE; + } + // If using date popup then process the callback that would have been done had + // Scheduler not replaced this with its own one. If using plain text entry + // then no return value is needed. + if (_scheduler_use_date_popup()) { + return date_popup_element_value_callback($element, $input, $form_state); + } +} + +/** * Displays a list of nodes that are scheduled for (un)publication. * * This will appear as a tab on the content admin page ('admin/content'). diff --git a/scheduler.test b/scheduler.test index b9c9498..cb515e6 100644 --- a/scheduler.test +++ b/scheduler.test @@ -41,7 +41,7 @@ class SchedulerTestCase extends DrupalWebTestCase { $this->drupalCreateContentType(array('type' => 'page', 'name' => t('Basic page'))); // Create an administrator user. - $this->admin_user = $this->drupalCreateUser(array('access content', 'administer scheduler', 'create page content', 'edit own page content', 'view own unpublished content', 'administer nodes', 'schedule (un)publishing of nodes')); + $this->admin_user = $this->drupalCreateUser(array('access content', 'administer scheduler', 'create page content', 'edit own page content', 'delete own page content', 'view own unpublished content', 'administer nodes', 'schedule (un)publishing of nodes')); // Add scheduler functionality to the page node type. variable_set('scheduler_publish_enable_page', 1); @@ -595,4 +595,31 @@ class SchedulerTestCase extends DrupalWebTestCase { } } + /** + * Tests the deletion of a scheduled node. + * + * This tests if it is possible to delete a node that does not have a + * publication date set, when scheduled publishing is required. + * @see https://drupal.org/node/1614880 + */ + public function testScheduledNodeDelete() { + // Log in. + $this->drupalLogin($this->admin_user); + + // Create a published and an unpublished node, both without scheduling. + $unpublished_node = $this->drupalCreateNode(array('type' => 'page', 'status' => 0)); + $published_node = $this->drupalCreateNode(array('type' => 'page', 'status' => 1)); + + // Make scheduled publishing and unpublishing required. + variable_set('scheduler_publish_required_page', TRUE); + variable_set('scheduler_unpublish_required_page', TRUE); + + // Check that deleting the nodes does not throw form validation errors. + $this->drupalPost('node/' . $published_node->nid . '/edit', array(), t('Delete')); + $this->assertNoRaw(t('Error message'), 'No error messages are shown when trying to delete a published node with no scheduling information.'); + + $this->drupalPost('node/' . $unpublished_node->nid . '/edit', array(), t('Delete')); + $this->assertNoRaw(t('Error message'), 'No error messages are shown when trying to delete an unpublished node with no scheduling information.'); + } + }