Commit c4926e56 authored by James Yao's avatar James Yao Committed by Joseph Olstad
Browse files

Issue #3320470 by jamesyao, joseph.olstad: Make the bulk publish verification...

Issue #3320470 by jamesyao, joseph.olstad: Make the bulk publish verification configurable to allow the user to perform the bulk publish action on the pages in a particular user case
parent cf88f05c
Loading
Loading
Loading
Loading
+90 −1
Original line number Diff line number Diff line
@@ -264,6 +264,90 @@ function safedelete_node_predelete(EntityInterface $entity) {
  }
}

/**
 * Implements safedelete_form_validate_HOOK().
 */
function safedelete_form_validate_enable_bulkpublish(array $form, FormStateInterface $form_state) {
  $username = \Drupal::currentUser()->getAccountName();
  if ($form_state->hasValue('enable_bulk_publish_validate')) {
    $tmpvar = $form_state->getValue('enable_bulk_publish_validate');
    $tmpconfig = \Drupal::config('safedelete.settings')->get('enforce_bulk_publish_verify_checkpagepublished');
    if ($tmpvar != $tmpconfig) {
      //Update SafeDelete settings enforce_bulk_publish_verify_checkpagepublished
      $config = \Drupal::service('config.factory')->getEditable('safedelete.settings');
      if ($tmpvar == 0 ) {
        \Drupal::logger('safedelete')->notice( $username . " disable the checkbox (Enable bulk publish validation to check if the linked pages are unpublished.)");
        $config->set('enforce_bulk_publish_verify_checkpagepublished', $tmpvar)->save();
      }
    }
  }
}

/**
 * Implements safedelete_form_submit_HOOK().
 */
function safedelete_form_submit_enable_bulkpublish(array $form, FormStateInterface $form_state) {
  $tmpconfig = \Drupal::config('safedelete.settings')->get('enforce_bulk_publish_verify_checkpagepublished');
  if (!$tmpconfig) {
    //Update Settings
    $config = \Drupal::service('config.factory')->getEditable('safedelete.settings');
    \Drupal::logger('safedelete')->notice( "Enable the checkbox (Enable bulk publish validation to check if the linked pages are unpublished.)");
    $config->set('enforce_bulk_publish_verify_checkpagepublished', TRUE)->save();
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function safedelete_form_views_form_moderated_content_moderated_content_alter(&$form, FormStateInterface $form_state, $form_id) {
  $route_name = \Drupal::routeMatch()->getRouteName();
  if ($route_name != 'content_moderation.admin_moderated_content') {
    return;
  }
  if (isset($form['header']['node_bulk_form']['action']['#options']['publish_latest'])) {
    //only add this option when publish latest version actoin is available
    if (($form_id == 'views_form_moderated_content_moderated_content')) {
      if ((!isset($form['enable_bulk_publish_validate']))) {
        $form['enable_bulk_publish_validate'] = [
          '#type' => 'checkbox',
          '#title' => t('Enable bulk publish validation to check if the linked pages are unpublished.'),
          '#default_value' => \Drupal::config('safedelete.settings')->get('enforce_bulk_publish_verify_checkpagepublished')? \Drupal::config('safedelete.settings')->get('enforce_bulk_publish_verify_checkpagepublished') : 0,
          '#required' => FALSE
          ];
        $form['enable_bulk_publish_validate']['#weight'] =  -1;
        $form['#validate'][] = 'safedelete_form_validate_enable_bulkpublish';
        $form['#submit'][] = 'safedelete_form_submit_enable_bulkpublish';
      }
    }
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function safedelete_form_views_form_content_page_1_alter(&$form, FormStateInterface $form_state, $form_id) {
  $route_name = \Drupal::routeMatch()->getRouteName();
  if ($route_name != 'system.admin_content') {
    return;
  }
  if (isset($form['header']['node_bulk_form']['action']['#options']['publish_latest'])) {
    //only add this option when publish latest version actoin is available
    if ($form_id == 'views_form_content_page_1') {
      if ((!isset($form['enable_bulk_publish_validate']))) {
        $form['enable_bulk_publish_validate']['widget'][0] =  [
          '#type' => 'checkbox',
          '#title' => t('Enable bulk publish validation to check if the linked pages are unpublished.'),
          '#default_value' => \Drupal::config('safedelete.settings')->get('enforce_bulk_publish_verify_checkpagepublished')? \Drupal::config('safedelete.settings')->get('enforce_bulk_publish_verify_checkpagepublished') : 0,
          '#required' => FALSE
        ];
        $form['enable_bulk_publish_validate']['#weight'] =  -1;
        $form['#validate'][] = 'safedelete_form_validate_enable_bulkpublish';
        $form['#submit'][] = 'safedelete_form_submit_enable_bulkpublish';
      }
   }
  }
}

/**
 * Implements hook_form_alter().
 */
@@ -678,8 +762,13 @@ function safedelete_moderated_content_bulk_publish_verify_publish($hookObject) {
  $state = 'publish';
  $body_field_val = $hookObject->body_field_val;
  $nid = $hookObject->nid;
  AdminHelper::checkUrlToken($body_field_val, $found_token_href, $msgdetail_isToken);
  $enforce_bulk_publish_verify_checkpagepublished = \Drupal::config('safedelete.settings')->get('enforce_bulk_publish_verify_checkpagepublished');
  $found_unpublished_node = FALSE;
  $msgdetail_isPublished = '';
  if ($enforce_bulk_publish_verify_checkpagepublished) {
    AdminHelper::checkPagePublished($body_field_val, $found_unpublished_node, $msgdetail_isPublished);
  }
  AdminHelper::checkUrlToken($body_field_val, $found_token_href, $msgdetail_isToken);
  AdminHelper::checkAbsoluteUrl($body_field_val, $found_absolute_url, $msgdetail_isAbsoluteURL);
  if ($found_token_href || $found_unpublished_node || $found_absolute_url) {
    $msgtitle = t('Unable to publish node %nid. See warning message(s).',['%nid' =>$nid]);
+9 −0
Original line number Diff line number Diff line
@@ -110,6 +110,14 @@ class SafedeleteSettingsForm extends ConfigFormBase {
      '#default_value' => $config->get('exceptionofnodes'),
    ];

    /* Enforce the bulk publish verification to check page published */
    $form['enforce_bulk_publish_verify_checkpagepublished'] = [
      '#title' => t('Enforce the bulk publish verification to check if the linked pages are published'),
      '#type' => 'checkbox',
      '#description' => t('Check if the linked pages are published'),
      '#default_value' => (!empty($config->get('enforce_bulk_publish_verify_checkpagepublished'))) ? $config->get('enforce_bulk_publish_verify_checkpagepublished') : FALSE
    ];

    // Buttons are only required for testing and debugging reasons.
    $orphdescription = '<p>' . $this->t('The section will run checking orphaned nodes proccess.') ;
    $form['clear'] = [
@@ -139,6 +147,7 @@ class SafedeleteSettingsForm extends ConfigFormBase {
      ->set('orphanedpagedefinition', $form_state->getValue('orphanedpagedefinition'))
      ->set('orphanedpagewithoutmenulink', $form_state->getValue('orphanedpagewithoutmenulink'))
      ->set('safearchive', $form_state->getValue('safearchive'))
      ->set('enforce_bulk_publish_verify_checkpagepublished', $form_state->getValue('enforce_bulk_publish_verify_checkpagepublished'))
      ->save();

    parent::submitForm($form, $form_state);