Commit 5ce7b70a authored by renatog's avatar renatog Committed by renatog
Browse files

Issue #3269004 by RenatoG: Implement the confirmation for bulk operations...

Issue #3269004 by RenatoG: Implement the confirmation for bulk operations where the user can cancel that or continue
parent 98a644cf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ block_class.bulk_operations:
    _permission: 'administer block classes'

block_class.confirm_bulk_operation:
  path: '/admin/config/content/block-class/confirm-bulk-operation/{operation}/{current_class}/{new_class}'
  path: '/admin/config/content/block-class/confirm-bulk-operation/{operation}/{classes_to_be_added}/{current_class}/{new_class}'
  defaults:
    _form: '\Drupal\block_class\Form\BlockClassConfirmBulkOperationForm'
    _title: 'Confirm Deletion'
+39 −5
Original line number Diff line number Diff line
@@ -21,14 +21,21 @@ class BlockClassConfirmBulkOperationForm extends ConfirmFormBase {
  protected $operation;

  /**
   * Bulk Operation type.
   * Classes to be added.
   *
   * @var string
   */
  protected $classesToBeAdded;

  /**
   * Current class.
   *
   * @var string
   */
  protected $currentClass;

  /**
   * Bulk Operation type.
   * New class.
   *
   * @var string
   */
@@ -38,7 +45,7 @@ class BlockClassConfirmBulkOperationForm extends ConfirmFormBase {
   * {@inheritdoc}
   */
  // @codingStandardsIgnoreLine
  public function buildForm(array $form, FormStateInterface $form_state, $operation = NULL, $current_class = NULL, $new_class = NULL) {
  public function buildForm(array $form, FormStateInterface $form_state, $operation = NULL, $classes_to_be_added = NULL, $current_class = NULL, $new_class = NULL) {

    // If the user doesn't have the sessions, restrict it.
    if (empty(\Drupal::service('session')->get('block_class_confirm_bulk_operation'))) {
@@ -54,6 +61,7 @@ class BlockClassConfirmBulkOperationForm extends ConfirmFormBase {

    // Get the default parameters.
    $this->operation = $operation;
    $this->classesToBeAdded = $classes_to_be_added;
    $this->currentClass = $current_class;
    $this->newClass = $new_class;

@@ -94,9 +102,27 @@ class BlockClassConfirmBulkOperationForm extends ConfirmFormBase {

    foreach ($blocks as $block) {

      // If there is no ThirdPartySetting with block class, skip.
      if (empty($block->getThirdPartySetting('block_class', 'classes'))) {
      // If is insert include this class to all blocks.
      if ($this->operation == 'insert') {

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

        // Add the new classes in the current ones.
        $current_classes = ' ' . $this->classesToBeAdded;

        // Using trim to remove spaces.
        $current_classes = trim($current_classes);

        // Store that in the Third Party Setting.
        $block->setThirdPartySetting('block_class', 'classes', $current_classes);

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

        // Go to the next iteration.
        continue;

      }

      // If is update get all values to update.
@@ -174,6 +200,14 @@ class BlockClassConfirmBulkOperationForm extends ConfirmFormBase {

    switch ($this->operation) {

      case 'insert':

        $message_to_confirm = $this->t('Do you want to insert class(es): <strong>@classes_to_be_added@</strong> to all blocks?', [
          '@classes_to_be_added@' => $this->classesToBeAdded,
        ]);

        break;

      case 'update':

        $message_to_confirm = $this->t('Do you want to update all block classes that have <strong>@current_class@</strong> to <strong>@new_class@</strong>?', [