Commit db4068d5 authored by renatog's avatar renatog Committed by renatog
Browse files

Issue #3270032 by RenatoG: Implement auxiliar methods to call instead of long...

Issue #3270032 by RenatoG: Implement auxiliar methods to call instead of long code inside of conditional logic on confirmBulkOperation
parent 9d073650
Loading
Loading
Loading
Loading
+102 −62
Original line number Diff line number Diff line
@@ -115,6 +115,58 @@ class BlockClassConfirmBulkOperationForm extends ConfirmFormBase {

        case 'insert':

          $this->insertOperation($block);

          continue 2;

        case 'insert_attributes':

          $this->insertAttributes($block);

          continue 2;

        case 'update':

          $this->updateOperation($block);

          continue 2;

        case 'delete':

          $this->deleteOperation($block);

          continue 2;

        case 'delete_attributes':

          $this->deleteAttributes($block);

          continue 2;

      }
    }

    // Clear the session because the confirmation is done.
    \Drupal::service('session')->remove('block_class_confirm_bulk_operation');

    \Drupal::messenger()->addStatus($this->t('Bulk operation concluded'));

    // Get path bulk operation.
    $bulk_operation_path = Url::fromRoute('block_class.bulk_operations')->toString();

    // Get response.
    $response = new RedirectResponse($bulk_operation_path);

    // Send to confirmation.
    $response->send();
    exit;
  }

  /**
   * Method to do the Insert Operation.
   */
  public function insertOperation(&$block) {

    // Get the current block classes configured.
    $current_classes = $block->getThirdPartySetting('block_class', 'classes');

@@ -129,11 +181,12 @@ class BlockClassConfirmBulkOperationForm extends ConfirmFormBase {

    // Save the block.
    $block->save();
  }

          // Go to the next iteration.
          continue;

        case 'insert_attributes':
  /**
   * Method to do the Insert Attributes.
   */
  public function insertAttributes(&$block) {

    // Get the current block attributes configured.
    $current_attributes = $block->getThirdPartySetting('block_class', 'attributes');
@@ -149,18 +202,19 @@ class BlockClassConfirmBulkOperationForm extends ConfirmFormBase {

    // Save the block.
    $block->save();
  }

          // Go to the next iteration.
          continue;

        case 'update':
  /**
   * Method to do the Update Operation.
   */
  public function updateOperation(&$block) {

    // Get the current block classes configured.
    $current_block_classes = $block->getThirdPartySetting('block_class', 'classes');

    // If the current block class doesn't have this current class, skip.
    if (!preg_match("/\b" . $this->currentClass . "\b/i", $current_block_classes)) {
            continue;
      return FALSE;
    }

    // Update the new block classes value with this replace.
@@ -172,10 +226,12 @@ class BlockClassConfirmBulkOperationForm extends ConfirmFormBase {
    // Save the block.
    $block->save();

          // Go to the next iteration.
          continue;
  }

        case 'delete':
  /**
   * Method to do the delete Operation.
   */
  public function deleteOperation(&$block) {

    // If there is ThirdPartySetting remove that.
    $block->unsetThirdPartySetting('block_class', 'classes');
@@ -183,9 +239,12 @@ class BlockClassConfirmBulkOperationForm extends ConfirmFormBase {
    // Block save.
    $block->save();

          continue;
  }

        case 'delete_attributes':
  /**
   * Method to do the delete attributes.
   */
  public function deleteAttributes(&$block) {

    // If there is ThirdPartySetting remove that.
    $block->unsetThirdPartySetting('block_class', 'attributes');
@@ -193,25 +252,6 @@ class BlockClassConfirmBulkOperationForm extends ConfirmFormBase {
    // Block save.
    $block->save();

          continue;

      }
    }

    // Clear the session because the confirmation is done.
    \Drupal::service('session')->remove('block_class_confirm_bulk_operation');

    \Drupal::messenger()->addStatus($this->t('Bulk operation concluded'));

    // Get path bulk operation.
    $bulk_operation_path = Url::fromRoute('block_class.bulk_operations')->toString();

    // Get response.
    $response = new RedirectResponse($bulk_operation_path);

    // Send to confirmation.
    $response->send();
    exit;
  }

  /**