function BlockController::performOperation

Same name and namespace in other branches
  1. 11.x core/modules/block/src/Controller/BlockController.php \Drupal\block\Controller\BlockController::performOperation()
  2. 10 core/modules/block/src/Controller/BlockController.php \Drupal\block\Controller\BlockController::performOperation()
  3. 9 core/modules/block/src/Controller/BlockController.php \Drupal\block\Controller\BlockController::performOperation()
  4. 8.9.x core/modules/block/src/Controller/BlockController.php \Drupal\block\Controller\BlockController::performOperation()

Calls a method on a block and reloads the listing page.

Attributes

#[Route(path: '/admin/structure/block/manage/{block}/enable', name: 'entity.block.enable', requirements: [ '_entity_access' => 'block.enable', '_csrf_token' => 'TRUE', ], defaults: [ 'op' => 'enable', ])] #[Route(path: '/admin/structure/block/manage/{block}/disable', name: 'entity.block.disable', requirements: [ '_entity_access' => 'block.disable', '_csrf_token' => 'TRUE', ], defaults: [ 'op' => 'disable', ])]

Parameters

\Drupal\block\BlockInterface $block: The block being acted upon.

string $op: The operation to perform, e.g., 'enable' or 'disable'.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse A redirect back to the listing page.

File

core/modules/block/src/Controller/BlockController.php, line 36

Class

BlockController
Controller routines for admin block routes.

Namespace

Drupal\block\Controller

Code

public function performOperation(BlockInterface $block, $op) {
  $block->{$op}()
    ->save();
  $this->messenger()
    ->addStatus($this->t('The block settings have been updated.'));
  return $this->redirect('block.admin_display');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.