Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit user programmatically #1

Open
abelleflamme opened this issue Jun 16, 2017 · 1 comment
Open

Edit user programmatically #1

abelleflamme opened this issue Jun 16, 2017 · 1 comment

Comments

@abelleflamme
Copy link

Hello,

I'm trying to update users with the IP address because I have a lot of users to update.
I tried several type IP (normal, hexa, integer, ...) withouth any success.
$acc = \Drupal\user\Entity\User::load($shop_uid); $acc->set("field_ipaddress",$ip); $res = $acc->save();

Wath do I have to do here?

Thanks in advance,
Regards,
Adrien.

@bjaxelsen
Copy link
Owner

Hello Adrien

It is a little more complicated than that, if you don't go through the normal entity form field.

Have a look at Plugin\Field\FieldWidget\IpAddressWidgetBase::massageFormValues() - as you can see there are three sub elements (ip_from, ip_to and ipv6). The first two are identical for single IP numbers. They are encoded using inet_pton().

/ Bjørn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants