Loading block_class.routing.yml +8 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,14 @@ block_class.confirm_deletion: requirements: _permission: 'administer block classes' block_class.confirm_deletion_attribute: path: '/admin/config/content/block-class/delete-attribute/{bid}' defaults: _form: '\Drupal\block_class\Form\BlockClassConfirmDeletionAttributeForm' _title: 'Confirm Deletion Attribute' requirements: _permission: 'administer block classes' block_class.class_list: path: '/admin/config/content/block-class/class-list' defaults: Loading src/Controller/BlockClassController.php +1 −1 Original line number Diff line number Diff line Loading @@ -209,7 +209,7 @@ class BlockClassController extends ControllerBase { $table .= '<td>' . $attributes . '</td>'; $table .= '<td>' . '<a href="/admin/structure/block/manage/' . $block->id() . '">' . $this->t('Edit') . '</a></td>'; $table .= '<td>' . '<a href="/admin/config/content/block-class/delete/' . $block->id() . '">' . $this->t('Delete') . '</a></td>'; $table .= '<td>' . '<a href="/admin/config/content/block-class/delete/' . $block->id() . '">' . $this->t('Delete Attributes') . '</a></td>'; $table .= '<td>' . '<a href="/admin/config/content/block-class/delete-attribute/' . $block->id() . '">' . $this->t('Delete Attributes') . '</a></td>'; $table .= '</tr>'; $index++; Loading src/Form/BlockClassConfirmDeletionAttributeForm.php 0 → 100644 +96 −0 Original line number Diff line number Diff line <?php namespace Drupal\block_class\Form; use Drupal\Core\Form\ConfirmFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\block\Entity\Block; use Symfony\Component\HttpFoundation\RedirectResponse; /** * Form for Block Class Confirm Deletion on Attributes. */ class BlockClassConfirmDeletionAttributeForm extends ConfirmFormBase { /** * Block ID. * * @var string */ protected $bid; /** * {@inheritdoc} */ // @codingStandardsIgnoreLine public function buildForm(array $form, FormStateInterface $form_state, $bid = NULL) { $this->bid = $bid; $message_to_confirm = (string) $this->getQuestion(); $form['message_to_confirm'] = [ '#type' => 'item', '#markup' => $message_to_confirm, ]; return parent::buildForm($form, $form_state); } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { // Load block. Todo: We'll implements DI here @codingStandardsIgnoreLine $block = Block::load($this->bid); // If there is ThirdPartySetting remove that. $block->unsetThirdPartySetting('block_class', 'attributes'); // Block save. $block->save(); // Set a messsage. \Drupal::messenger()->addStatus($this->t('Attributes deleted')); // Get the block class list path. $block_class_list_path = Url::fromRoute('block_class.list')->toString(); // Get response. $response = new RedirectResponse($block_class_list_path); // Send to confirmation. $response->send(); exit; } /** * {@inheritdoc} */ public function getFormId() : string { return "block_class_confirm_deletion_form"; } /** * {@inheritdoc} */ public function getCancelUrl() { return Url::fromRoute('block_class.list'); } /** * {@inheritdoc} */ public function getQuestion() { $message_to_confirm = $this->t('Are you sure?'); return $message_to_confirm; } } Loading
block_class.routing.yml +8 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,14 @@ block_class.confirm_deletion: requirements: _permission: 'administer block classes' block_class.confirm_deletion_attribute: path: '/admin/config/content/block-class/delete-attribute/{bid}' defaults: _form: '\Drupal\block_class\Form\BlockClassConfirmDeletionAttributeForm' _title: 'Confirm Deletion Attribute' requirements: _permission: 'administer block classes' block_class.class_list: path: '/admin/config/content/block-class/class-list' defaults: Loading
src/Controller/BlockClassController.php +1 −1 Original line number Diff line number Diff line Loading @@ -209,7 +209,7 @@ class BlockClassController extends ControllerBase { $table .= '<td>' . $attributes . '</td>'; $table .= '<td>' . '<a href="/admin/structure/block/manage/' . $block->id() . '">' . $this->t('Edit') . '</a></td>'; $table .= '<td>' . '<a href="/admin/config/content/block-class/delete/' . $block->id() . '">' . $this->t('Delete') . '</a></td>'; $table .= '<td>' . '<a href="/admin/config/content/block-class/delete/' . $block->id() . '">' . $this->t('Delete Attributes') . '</a></td>'; $table .= '<td>' . '<a href="/admin/config/content/block-class/delete-attribute/' . $block->id() . '">' . $this->t('Delete Attributes') . '</a></td>'; $table .= '</tr>'; $index++; Loading
src/Form/BlockClassConfirmDeletionAttributeForm.php 0 → 100644 +96 −0 Original line number Diff line number Diff line <?php namespace Drupal\block_class\Form; use Drupal\Core\Form\ConfirmFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\block\Entity\Block; use Symfony\Component\HttpFoundation\RedirectResponse; /** * Form for Block Class Confirm Deletion on Attributes. */ class BlockClassConfirmDeletionAttributeForm extends ConfirmFormBase { /** * Block ID. * * @var string */ protected $bid; /** * {@inheritdoc} */ // @codingStandardsIgnoreLine public function buildForm(array $form, FormStateInterface $form_state, $bid = NULL) { $this->bid = $bid; $message_to_confirm = (string) $this->getQuestion(); $form['message_to_confirm'] = [ '#type' => 'item', '#markup' => $message_to_confirm, ]; return parent::buildForm($form, $form_state); } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { // Load block. Todo: We'll implements DI here @codingStandardsIgnoreLine $block = Block::load($this->bid); // If there is ThirdPartySetting remove that. $block->unsetThirdPartySetting('block_class', 'attributes'); // Block save. $block->save(); // Set a messsage. \Drupal::messenger()->addStatus($this->t('Attributes deleted')); // Get the block class list path. $block_class_list_path = Url::fromRoute('block_class.list')->toString(); // Get response. $response = new RedirectResponse($block_class_list_path); // Send to confirmation. $response->send(); exit; } /** * {@inheritdoc} */ public function getFormId() : string { return "block_class_confirm_deletion_form"; } /** * {@inheritdoc} */ public function getCancelUrl() { return Url::fromRoute('block_class.list'); } /** * {@inheritdoc} */ public function getQuestion() { $message_to_confirm = $this->t('Are you sure?'); return $message_to_confirm; } }