I have created a form using which I want to make changes in the configuration.Currently I am submitting form doing something like this:
public function submitForm(array &$form, FormStateInterface $form_state) {
\Drupal::service('config.factory')
->getEditable('module.settings')
->set('module_entities', $form_state->getValue('module_entities'))
->save();
}
But the problem is when I have submitted the form changes in the configuration are not reflected.But when I clear the cache after submitting the form the changes are reflected.what changes should I make so that when user submits form the changes are reflected thereafter?
Update: I tried to find my mistake and found out that configuration is getting updated but somehow the changes getting lost and not being reflected in the block which I have created. In the block creation code I am creating blocks for different entities depending on the entities present in the configuration.But the configuration is not showing correct values so block for required entities is not being created.Surprisingly when I clear cache the code works(which means configuration becomes updated).Does this mean for block creation I need to clear cache? I am currently using this code:
`public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives[$entity_type] = $base_plugin_definition;
$this->derivatives[$entity_type]['admin_label'] .= ' (' . $entity_definition->getLabel() .')';
$this->derivatives[$entity_type]['cache'] = ?;
}`
What should I add over here to make block depend on configuration without clearing cache? In the plugin I am returning:
public function build() {
return array(
'#theme' => 'links__entity__module',
'#links' => $this->linkBuilder->buildLinks($this->request->attributes->get($entity_type)),
);
}