0

I am trying to ignore the content of some fields in a custom defined block plugin.

In my block plugin (class MyAwesomeBlock extends BlockBase implements BlockPluginInterface { ... })

I've declared some fields with the blockForm function.

$form['my_awesome_field'] = [
  '#type' => 'text_format',
  '#title' => $this->t('Title'),
  ...
];

Now, I would like the content of this field in the block configuration to be ignored, but the general block settings (placement, weight etc.) should be kept.

I've tried some things in the config_ignore settings like:

  • block.block.myawesomeblock:my_awesome_field
  • block.block.myawesomeblock:settings.my_awesome_field
  • block.block.myawesomeblock.my_awesome_field
  • block.block.myawesomeblock.settings.my_awesome_field

But they don't seem to work. Any ideas what I'm missing?

  • Block configuration is a simple configuration, meaning all its configuration is referenced from a single yml file. Your config_ignore list should match to a yml file that you get from a configuration export. Although I would first ask why are you ignoring this value? If it's because of switching between environments, then the value should be stored as a reference to something that lives in the db (block content, perhaps) and referenced via an identifier. The block could be imported, but the value in the db doesn't. – stacey.mosier Nov 5 at 17:00
  • @stacey.mosier Thank you for the answer. The reason is that content editors want to change the content of the block on a regular basis. We opted for a block since the blocks wouldn't change throughout a whole list of pages defined in the block configuration. I tried to use config_ignore based on an exported file but that didn't work. – Bram Nov 6 at 13:02
  • 1
    Create a custom block type, that will take fields. The field value will exist in the db in its own table. Which might seem overkill if there is only ever 1 block and 1 field value. Otherwise, ignore the complete block? – stacey.mosier Nov 7 at 1:10
  • That might be indeed the most easiest solution :-) – Bram Nov 7 at 10:47

Your Answer

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

Browse other questions tagged or ask your own question.