refactored loadMaterials vuex mixins with graphql
This commit is contained in:
@@ -50,18 +50,18 @@ class MaterioFlagActionsController extends ActionLinkController {
|
||||
public function flaglistentity(Request $request) {
|
||||
$post_data = json_decode( $request->getContent(),TRUE);
|
||||
$flagid = $post_data['flagid'];
|
||||
$uuid = $post_data['uuid'];
|
||||
$id = $post_data['id'];
|
||||
$flagcollid = $post_data['flagcollid'];
|
||||
|
||||
// $flagcoll = $this->flagListsService->getFlaggingCollectionById($flagcollid);
|
||||
// $flag = $flagcoll->getRelatedFlag();
|
||||
$flag = $this->flagService->getFlagById($flagid);
|
||||
|
||||
$node = \Drupal::service('entity.repository')->loadEntityByUuid('node', $uuid);
|
||||
$nid = $node->id();
|
||||
// $node = \Drupal::service('entity.repository')->loadEntityByUuid('node', $uuid);
|
||||
// $nid = $node->id();
|
||||
|
||||
// call the parent flag function
|
||||
$this->flag($flag, $nid, $flagcollid);
|
||||
$this->flag($flag, $id, $flagcollid);
|
||||
|
||||
// // OR rewrite it entirely
|
||||
// $entity = $this->flagService->getFlaggableById($flag, $nid);
|
||||
@@ -82,8 +82,8 @@ class MaterioFlagActionsController extends ActionLinkController {
|
||||
$data = [
|
||||
'flag' => $flag->toArray(),
|
||||
'flagid' => $flagid,
|
||||
'entity_id' => $nid,
|
||||
'entity_uuid' => $uuid,
|
||||
'entity_id' => $id,
|
||||
// 'entity_uuid' => $uuid,
|
||||
'flagcollid' => $flagcollid,
|
||||
// 'post_data' => $post_data,
|
||||
// 'flaggableEntityTypeId' => $flag->getFlaggableEntityTypeId(),
|
||||
@@ -96,21 +96,21 @@ class MaterioFlagActionsController extends ActionLinkController {
|
||||
public function unFlaglistentity(Request $request) {
|
||||
$post_data = json_decode( $request->getContent(),TRUE);
|
||||
$flagid = $post_data['flagid'];
|
||||
$uuid = $post_data['uuid'];
|
||||
$id = $post_data['id'];
|
||||
$flagcollid = $post_data['flagcollid'];
|
||||
// get flag
|
||||
$flag = $this->flagService->getFlagById($flagid);
|
||||
// get the nid from uuid
|
||||
$node = \Drupal::service('entity.repository')->loadEntityByUuid('node', $uuid);
|
||||
$nid = $node->id();
|
||||
// $node = \Drupal::service('entity.repository')->loadEntityByUuid('node', $uuid);
|
||||
// $nid = $node->id();
|
||||
// call the parent flag function
|
||||
$this->unflag($flag, $nid, $flagcollid);
|
||||
$this->unflag($flag, $id, $flagcollid);
|
||||
// response
|
||||
$data = [
|
||||
'flag' => $flag->toArray(),
|
||||
'flagid' => $flagid,
|
||||
'entity_id' => $nid,
|
||||
'entity_uuid' => $uuid,
|
||||
'entity_id' => $id,
|
||||
// 'entity_uuid' => $uuid,
|
||||
'flagcollid' => $flagcollid,
|
||||
];
|
||||
return new JsonResponse($data);
|
||||
|
@@ -76,20 +76,20 @@ class MaterioFlagController extends ControllerBase {
|
||||
// 'name' => $item->getName(),
|
||||
// 'connected_entity_id' => $item->getConnectedEntityId(),
|
||||
// );
|
||||
$items[] = $item->getConnectedEntityId();
|
||||
}
|
||||
$items_uuids = [];
|
||||
foreach ($items as $nid) {
|
||||
$node = $this->entityTypeManager->getStorage('node')->load($nid);
|
||||
$items_uuids[] = $node->uuid();
|
||||
$items[] = (int)$item->getConnectedEntityId();
|
||||
}
|
||||
// $items_uuids = [];
|
||||
// foreach ($items as $nid) {
|
||||
// $node = $this->entityTypeManager->getStorage('node')->load($nid);
|
||||
// $items_uuids[] = $node->uuid();
|
||||
// }
|
||||
|
||||
$data[$collection->id()] = array(
|
||||
"id" => $collection->id(),
|
||||
"name" => $collection->getName(),
|
||||
"flag_id" => $flag_id,
|
||||
"items" => $items,
|
||||
"items_uuids" => $items_uuids,
|
||||
"items" => $items
|
||||
// "items_uuids" => $items_uuids
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,10 @@ extend type Query {
|
||||
materiau(id: Int!): Materiau
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
materiaux(ids: [Int]): [Materiau]
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
article(id: Int!): Article
|
||||
}
|
||||
|
@@ -71,6 +71,13 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||
->map('id', $builder->fromArgument('id'))
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('Query', 'materiaux',
|
||||
$builder->produce('entity_load_multiple')
|
||||
->map('type', $builder->fromValue('node'))
|
||||
// ->map('bundles', $builder->fromValue(['materiau']))
|
||||
->map('ids', $builder->fromArgument('ids'))
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('Materiau', 'id',
|
||||
$builder->produce('entity_id')
|
||||
->map('entity', $builder->fromParent())
|
||||
@@ -204,10 +211,8 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||
->map('value', $builder->fromParent())
|
||||
->map('path', $builder->fromValue('field_samples'))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ___ _
|
||||
// / __| __ _ _ __ _ __| |___
|
||||
// \__ \/ _` | ' \| '_ \ / -_)
|
||||
|
Reference in New Issue
Block a user