Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\JsonResponse;
- use Symfony\Component\HttpFoundation\Response;
- /**
- * Implements hook_node_presave().
- */
- function abc_node_presave($node)
- {
- if($enable_field_full_json_string && ($node->bundle() == "dynamic_api")){
- $json_response_arr = abc($node);
- $ref_link_entities = $node->get('field_api_key_value_pairs')->referencedEntities();
- $key_value = $ref_link_node->get('field_pair_api_key')->value;
- foreach ($ref_link_entities as $ref_link_node){
- $json_response = json_encode($json_response_arr, JSON_PRETTY_PRINT | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
- $node->set('field_full_json_string', $json_response);
- }
- }
- $json_value = $node->get('field_json_api_content')->value;
- $response = new Response();
- $response->setContent($json_value);
- $response->headers->set('Content-Type', 'application/json');
- return $response;
- $query = \Drupal::entityQuery('node')
- ->condition('status', 1)
- ->condition('field_content_api_id.value', $node_api_id);
- $nids = $query->execute();
- $node = \Drupal\node\Entity\Node::load(reset($nids));
- if(empty($node)){
- $response = "Not found";
- return new JsonResponse($response);
- }
- $response = abc($node);
- if ($functioncall) {
- return $response;
- } else {
- return new JsonResponse($response);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement