|
@@ -365,6 +365,33 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
->map('id', $builder->fromParent())
|
|
|
)
|
|
|
);
|
|
|
+ $registry->addFieldResolver('Materiau', 'note_id',
|
|
|
+ $builder->compose(
|
|
|
+ $builder->callback(function($parent, $args){
|
|
|
+ // get the current user id
|
|
|
+ $user = \Drupal::currentUser()->id();
|
|
|
+ // get the current material id
|
|
|
+ $target = $parent->id();
|
|
|
+ // query the note for these user AND material (if any)
|
|
|
+ // if null, UI will create it with rest api
|
|
|
+ $entity_storage = \Drupal::entityTypeManager()->getStorage('node');
|
|
|
+ $query = $entity_storage->getQuery()
|
|
|
+ ->condition('type', 'note')
|
|
|
+ ->condition('uid', $user)
|
|
|
+ ->condition('field_target', $target)
|
|
|
+ ->accessCheck(TRUE);
|
|
|
+ $results = $query->execute();
|
|
|
+ // $test="test";
|
|
|
+ return array_shift($results);
|
|
|
+ }),
|
|
|
+ $builder->produce('entity_load')
|
|
|
+ ->map('type', $builder->fromValue('node'))
|
|
|
+ ->map('bundle', $builder->fromValue('note'))
|
|
|
+ ->map('id', $builder->fromParent()),
|
|
|
+ $builder->produce('entity_id')
|
|
|
+ ->map('entity', $builder->fromParent())
|
|
|
+ )
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
// _ _ _
|
|
@@ -419,6 +446,13 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
->map('ids', $builder->fromArgument('ids'))
|
|
|
->map('language', $builder->fromArgument('lang'))
|
|
|
);
|
|
|
+
|
|
|
+ $registry->addFieldResolver('Query', 'searchresult',
|
|
|
+ $builder->produce('entity_load')
|
|
|
+ ->map('type', $builder->fromValue('node'))
|
|
|
+ ->map('id', $builder->fromArgument('id'))
|
|
|
+ ->map('language', $builder->fromArgument('lang'))
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
// ___ _
|