1

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?

3
  • anyone? --------
    – Tobi
    Commented Nov 24, 2022 at 14:18
  • 1
    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.
    – sanzante
    Commented Nov 25, 2022 at 11:29
  • 1
    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.
    – Tobi
    Commented Nov 26, 2022 at 14:36

1 Answer 1

1

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

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.