personnal notes on materails on modalCard is ok

This commit is contained in:
2021-01-26 16:36:27 +01:00
parent 1dd65af561
commit 1f9b5a0053
25 changed files with 746 additions and 11 deletions

View File

@@ -27,6 +27,13 @@ type Materiau implements NodeInterface {
# index: Int
reference: String
samples: [Sample]
note: Note
}
type Note implements NodeInterface {
id: Int!
contenu: String
target: Int
}
type Article implements NodeInterface {

View File

@@ -31,6 +31,8 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
$this->addMateriau($registry, $builder);
$this->addNote($registry, $builder);
$this->addSearchResult($registry, $builder);
$this->addSample($registry, $builder);
@@ -271,6 +273,58 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_samples'))
);
$registry->addFieldResolver('Materiau', 'note',
$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())
)
);
}
// _ _ _
// | \| |___| |_ ___
// | .` / _ \ _/ -_)
// |_|\_\___/\__\___|
protected function addNote(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
$registry->addFieldResolver('Note', 'id',
$builder->produce('entity_id')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Note', 'contenu',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_contenu.value'))
);
$registry->addFieldResolver('Note', 'target',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_target.target_id'))
);
}
// ___ _ ___ _ _