This repository has been archived by the owner on Aug 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Graph refactoring #13
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
d088448
RDF Entity module requires PHP >=7.1.
claudiu-cristea 5a05af6
Fix docs in src/RdfGraphHandler.
claudiu-cristea e404205
Add schema for 'rdf_entity_graph' and 'rdf_entity_mapping' entities.
claudiu-cristea 3532abe
Move mapping config from bundle 3rd party settings to dedicated confi…
claudiu-cristea 05be3d9
Use the mapping stored in the dedicated config entity.
claudiu-cristea a946220
Add the rdf_entity_graph config entity.
claudiu-cristea 1ea6809
Additional checks for field existence in base fields mapping.
claudiu-cristea edfdde7
Update path: move mapping configs in their dedicated storage.
claudiu-cristea d5dc9b1
Add an interface to RdfEntityGraph class.
claudiu-cristea 4d703dc
Expand the RdfEntityMapping with setters and getters.
claudiu-cristea 28ec21f
Fix the return type.
claudiu-cristea d30b89d
YAML standards on rdf_draft.info.yml.
claudiu-cristea 885d3e4
::getGraph() was renamed to ::getGraphUri().
claudiu-cristea ae40916
Add setters/getters and a new property 'entity_types' to RdfEntityGraph.
claudiu-cristea 5b62742
Refactor \Drupal\rdf_entity\RdfGraphHandler::getGraphDefinitions().
claudiu-cristea 7fa3c20
Add the 'draft' graph.
claudiu-cristea d19927b
Change the label of 'default' graph to 'Published' when rdf_draft mod…
claudiu-cristea 2f7a793
Completely modernize RdfGraphHandler & RdfEntitySparqlStorage
claudiu-cristea 5181d63
Additional fixes.
claudiu-cristea 39f4366
Add reference to #15 follow-up.
claudiu-cristea 4d00706
Rename rdf_entity_get_third_party_property() to rdf_entity_get_mappin…
claudiu-cristea 4f369a0
Allow the exception to propagate when saving a mapping in the UI.
claudiu-cristea 322d6d8
Remove stale @todo.
claudiu-cristea ccc59d8
Throw exception when invalid graphs are passed to storage loaders.
claudiu-cristea 0ae10cd
Missing strict type declaration.
claudiu-cristea 0d15115
Typo in RdfEntityGraphToggle docs.
claudiu-cristea 11b92c7
Improve wording in API.md.
claudiu-cristea de7fb03
Use the RdfGraphHandlerInterface instead of class on type hinting.
claudiu-cristea 31828f7
Unmute some exceptions.
claudiu-cristea 477f582
Add followups to some @todos.
claudiu-cristea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# RDF Entity API | ||
|
||
@todo This document is under development. | ||
|
||
## RDF Graphs | ||
|
||
Entities using the SPARQL storage can be stored in different graphs. Graphs can | ||
be used to store different versions or states of the same entity. Depending on | ||
the use case you can use graphs to store a draft version of the entity. | ||
|
||
### RDF graphs storage | ||
|
||
Graphs are handled by the `RdfGraphHandler` service which is injected in the | ||
`Query` and the `RdfEntitySparqlStorage` classes. There are a number of methods | ||
offered to handle the graphs. | ||
|
||
### Graphs CRUD | ||
|
||
Graphs are config entities of type `rdf_entity_graph` and are supported by the | ||
Drupal API. You can add, edit, delete graphs also by using the UI provided at | ||
`/admin/config/rdf_entity/graph`. The `default` graph, shipped with `rdf_entity` | ||
module cannot be deleted or restricted to specific entity types. However, you | ||
can still edit its name and description. Only enabled graphs are taken into | ||
account by the SPARQL backend. | ||
|
||
The order of graph entities is important. You can configure a priority by | ||
settings the `weight` property. Also this could be done in the UI. | ||
|
||
### Handling entities and graphs | ||
|
||
#### Entity creation | ||
|
||
Set a specific graph to a new entity: | ||
|
||
```php | ||
$storage = \Drupal::entityTypeManager()->getStorage('food'); | ||
$entity = $storage->create([ | ||
'id' => 'http://example.com', | ||
'type' => 'fruit', | ||
'graph' => 'draft', | ||
]); | ||
$entity->save(); | ||
``` | ||
|
||
If no `'graph'` is set, the entity will be saved in the topmost graph. The | ||
topmost graph is the graph witch has the lowest `weight` property. | ||
|
||
#### Reading the graph of an entity | ||
|
||
```php | ||
$graph_id = $entity->get('graph')->value; | ||
// or... | ||
$graph_id = $entity->graph->value; | ||
|
||
``` | ||
|
||
#### Loading an entity from a specific graph | ||
|
||
```php | ||
$storage = \Drupal::entityTypeManager()->getStorage('food'); | ||
|
||
// Load from the default graph (the tompost graph in the list). | ||
$entity = $storage->load($id); | ||
|
||
// Load from the 'draft' graph. | ||
$entity = $storage->load($id, ['draft']); | ||
|
||
// Load from the first graph where the entity exists. First, the storage will | ||
// attempt to load the entity from the 'draft' graph. If this entity doesn't | ||
// exist in the 'draft' graph, will fallback to the next one which is 'sync' and | ||
// so on. If the entity is not found in any of the graphs, normal behaviour is | ||
// in place: will return NULL. | ||
$entity = $storage->load($id, ['draft', 'sync', 'obsolete', ...]); | ||
|
||
// Load multiple entities using a graph candidate list. | ||
$entities = $storage->loadMultiple($ids, ['draft', 'sync', 'obsolete', ...]); | ||
``` | ||
|
||
**Note**: When the list of graph candidates is not specified (first example), | ||
the candidates are all enabled graph entities, ordered by the weight property. | ||
|
||
#### Saving in a different graph | ||
|
||
```php | ||
$storage = \Drupal::entityTypeManager()->getStorage('food'); | ||
$entity = $storage->load($id, ['draft']); | ||
$entity->set('graph', 'default')->save(); | ||
``` | ||
|
||
#### Using graphs with entity query | ||
|
||
```php | ||
$storage = \Drupal::entityTypeManager()->getStorage('food'); | ||
$query = $storage->getQuery; | ||
$ids = $query | ||
->condition('type', 'fruit') | ||
->setGraphType(['default', 'draft']) | ||
->execute(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
langcode: en | ||
status: true | ||
id: default | ||
weight: 0 | ||
name: Default | ||
description: 'Default graph. This is available for all entity types and bundles.' | ||
entity_types: null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
langcode: en | ||
status: true | ||
id: draft | ||
weight: 10 | ||
name: Draft | ||
description: 'Draft graph.' | ||
entity_types: null |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name: RDF draft | ||
name: 'RDF draft' | ||
type: module | ||
description: Brings the notion of a draft graph to RDF entities. | ||
description: 'Brings the notion of a draft graph to RDF entities.' | ||
core: 8.x | ||
package: Joinup | ||
package: Custom | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could have our own name since all of these modules are related to RDF data. 'RDF Entity' could do for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right but I expanded too much the initial scope of this issue. Opened #14 to do this change. |
||
dependencies: | ||
- rdf_entity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Includes installation functions for the rdf_draft module. | ||
*/ | ||
|
||
use Drupal\Core\Serialization\Yaml; | ||
use Drupal\rdf_entity\Entity\RdfEntityGraph; | ||
use Drupal\rdf_entity\RdfEntityGraphInterface; | ||
|
||
/** | ||
* Implements hook_install(). | ||
*/ | ||
function rdf_draft_install() { | ||
// Change the label of the 'default' graph to 'Published'. | ||
if ($default = RdfEntityGraph::load(RdfEntityGraphInterface::DEFAULT)) { | ||
$default->setName('Published')->save(); | ||
} | ||
} | ||
|
||
/** | ||
* Install the 'draft' config entity. | ||
*/ | ||
function rdf_draft_update_8001() { | ||
// Update or post-update scripts might need this config entity available when | ||
// they run. We don't wait on configuration synchronization, because that runs | ||
// usually after the database update, so we make this entity available in an | ||
// early stage of updates. | ||
$values = Yaml::decode(file_get_contents(__DIR__ . '/config/install/rdf_entity.graph.draft.yml')); | ||
RdfEntityGraph::create($values)->save(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking to be commented: I haven't looked into all the changes yet, but last time I checked, all triples were returned from the database from all available graphs. The triples were the processed by the RdfEntitySparqlStorage class and the appropriate entity was returned instead.
To be checked later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. this (
$storage
) is actually aRdfEntitySparqlStorage
class. So, it returns a single entity, not all.