Score:1

How to programmatically set a checkbox value of an user account which field is not in /people/accounts/fields

us flag

I need to set a checkbox which has an unknown field (machine) name in the user account. the checkboxes are in the user account /user/?/edit Screenshot of subscription edit checkboxes

but they doesn't appear as fields in people/accounts/fields and are provided by the
DANSE Content Moderation Module.

I need to update them through a twig template with a custom form controller which works fine, but i cannot find the right way to update the field. I've tried:

$checkarticle = $values->get('checkmailarticle'); //--> field from custom form
$user_load = User::load($userID_current);    
$user_load->danse_subscriptions_settings_content_node_article_0_update->value = $checkarticle;

but where to find the correct

$user_load->"this field name?"->value

Or is there another way to update the settings?

us flag
anyone? --------
sanzante avatar
ph flag
I don't understand the question. You just want to alter a form and set a checkbox? If yes, have you tried with altering the form? If yes, have you tried to hook in the form after DANSE has done its work? If your module hook implementation is called before DANSE you can use hook_module_implements_alter to force your module to be called after DANSE.
us flag
The "problem" is the danse module doesn't store the user settings in 'fields', it stores it in the userObject, that i didnt know. After i found this information (which was not easy) i got it done.
Score:1
us flag

because the module stores the settings information in the userObject and not in fields you can use

$userData = \Drupal::service('user.data');
$userData->set('danse', $userID_current, 'content-node-"your content type machine name"-0-publish', 1);

for set the checkbox on, or

$userData->set('danse', $userID_current, 'content-node-"your content type machine name"-0-publish', 0);

for set it off

to find the right keys (third argument in the set function) you can log them in the service.php of the danse module

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.