Skip to content

Commit

Permalink
Added simple json paragraph behavior values
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Dec 14, 2023
1 parent 17087d6 commit 76d56ed
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions modules/stanford_graphql/stanford_graphql.module
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeFieldTypeInterface;
use Drupal\paragraphs\ParagraphInterface;

/**
* Implements hook_graphql_compose_field_results_alter().
Expand All @@ -30,4 +31,24 @@ function stanford_graphql_graphql_compose_field_results_alter(array &$results, $
$result->setDisplay($result->current_display . '_graphql');
}
}

foreach ($results as $result) {
if ($result instanceof ParagraphInterface) {
$result->set('behavior_settings', json_encode($result->getAllBehaviorSettings()));
}
}
}

/**
* Implements hook_graphql_compose_entity_base_fields_alter().
*/
function stanford_graphql_graphql_compose_entity_base_fields_alter(array &$fields, string $entity_type_id) {
if ($entity_type_id == 'paragraph') {
$fields['behavior_settings'] = [
'field_type' => 'string',
'name_sdl' => 'behaviors',
'required' => FALSE,
'description' => t('Paragraph Behavior Settings.'),
];
}
}

0 comments on commit 76d56ed

Please sign in to comment.