1

I have a ConfigFormBase called TextConfiguration where I have defined several fields for the address, phone number, etc...

These variables are shown in the contact form on my website. When I modify them and enter as anonymous in /contact, the value is not updated.

I've tried this in my ConfigFormBase form submit, but it does not work.

// Additionally, clear cache to prevent mismatch data.
$tags = $this->config(static::COMPET_SETTINGS)->getCacheTags();
if ($tags) {
  Cache::invalidateTags($tags);
}

I'm doing something wrong? I need to configure or do something to get it to update the data when a value is changed? Thanks all!

Edit: Example of how I'm rendering the fields.

enter image description here

3
  • How do you render the fields, did you add the cache tags there as well?
    – 4uk4
    Commented Apr 6, 2020 at 9:51
  • I'm adding the fields as markups to the $form var, in a FormAlter.
    – Javier Rey
    Commented Apr 6, 2020 at 10:00
  • I've uploaded a photo showing how I do it.
    – Javier Rey
    Commented Apr 6, 2020 at 10:02

1 Answer 1

2

You have to add the cache tags to the rendered output of the config field:

$form['example'] = [
  '#markup' => $settings->get('name'),
  '#cache' => [
    'tags' => $settings->getCacheTags(),
  ],
];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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