Everytime a node is created, I have a Rules Action that serialized the data into json and send it to OneSignal.

I have the below code that does it...

    $entity_id = $entity->id(); // Getting dynamic entity ID
    $controller = \Drupal::entityManager()->getStorage('node');
    $node = $controller->load($entity_id);

    $output = $serializer->serialize($node, 'json');
    \Drupal::logger('pattern')->notice('Serialize: ' . $output);

And this is the trimmed result from Drupal logs:

Serialize: @"nid":[{"value":"20922"],"uuid":[@"value":"XXXXX-XXXXX"],"type":[@"target_id":"pattern"],"title":[@"value":"Test Title"],"field_first_x":[@"value":"123456789"],"field_first_y":[@"value":"12"],"field_second_y":[@"value":"34"]...}

I have 20 custom fields in a one content type and can't anymore add new field as Im getting a limit issue when sending data via REST POST of more than 2bytes. So im planning to remove the field_ in each label, not in the database/Drupal but just in the $output variable to reduce the data size im sending.

This is my expected $output result:

Serialize: @"nid":[{"value":"20922"],"uuid":[@"value":"XXXXX-XXXXX"],"type":[@"target_id":"pattern"],"title":[@"value":"Test Title"],"first_x":[@"value":"123456789"],"first_y":[@"value":"12"],"second_y":[@"value":"34"]...}

Appreciate your help! TIA

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.