0

I built a custom block plugin but after updating it there are configuration items that I no longer need. But removing the part that saves the configuration data in blockSubmit submit function doesn't actually remove the configuration data that existed before.

My original blockSubmit function was as follows

public function blockSubmit($form, FormStateInterface $form_state) {
        $this->configuration['row']       = $form_state->getValue('row');
        $this->configuration['columns']   = $form_state->getValue('columns');
}

But now I only want to store $this->configuration['columns'] like below

public function blockSubmit($form, FormStateInterface $form_state) {
        $this->configuration['columns']   = $form_state->getValue('columns');
}

Is there a way to delete the configuration data in $this->configuration['row'] ? I don't mind it being a work around since I'm only going to be using it once. I wouldn't mind doing something like delete($this->configuration['row']); in the build function so it's removed when you visit a page that contains it.

Is there a way to remove this lingering configuration data in this block plugin?

1

There are several options.

You can unset the configuration 'row' in submit:

unset($this->configuration['row']);

You can load each block, remove the item from settings and save it. See https://drupal.stackexchange.com/a/224362/47547 how to load blocks. You can do this in an update hook.

You can export the configuration, remove the lines you don't want from the yaml files and import the configuration again. This would be the best option for a site owner who wants to clean up a single drupal installation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.