Sub-issue for meta issue #1880976: [meta] Port examples (including submodules) to D9.4+

Problem/Motivation

D8 all the things!

Proposed resolution

Start with D7 version and figure out how to port ;)

Comments

djevans’s picture

Assigned: Unassigned » djevans
Issue summary: View changes

I'll take this :)
One thing I can see to change for D8 will be to use the EasyRdf library for testing.

djevans’s picture

Status: Active » Needs review
StatusFileSize
new14.23 KB

Here's my first attempt at an example module. I've tried to port the D7 version of this module as faithfully as possible.

Like the D7 version, this module creates a custom node type with two fields, and defines an RDF mapping for it. This is all done with YAML config files.

The module also does something the D7 version claims to, but doesn't - modify the mappings for an existing node type. The 'RDFa modification' test case uses the Configuration API to modify the mappings of the 'article' node type from the standard installation profile. As this happens inside a test rather than as part of an install hook, it avoids overwriting any active configuration.

I'd welcome any comments on the 'correctness' of this example and any suggestions on how/if you think the explanations can be made clearer.

mile23’s picture

StatusFileSize
new759 bytes
new14.58 KB

Thanks, djevans! Looks good. Just some things...

  1. --- /dev/null
    +++ b/rdf_example/config/field.field.node.recipe_photo.yml
    
    --- /dev/null
    +++ b/rdf_example/config/field.field.node.recipe_summary.yml
    
    --- /dev/null
    +++ b/rdf_example/config/field.instance.node.recipe.recipe_photo.yml
    
    --- /dev/null
    +++ b/rdf_example/config/field.instance.node.recipe.recipe_summary.yml
    
    --- /dev/null
    +++ b/rdf_example/config/node.type.recipe.yml
    
    --- /dev/null
    +++ b/rdf_example/config/rdf.mapping.node.recipe.yml
    

    Some #comments for these config yml files would help the newbie find their way through them.

  2. +++ b/rdf_example/lib/Drupal/rdf_example/Controller/RDFExampleController.php
    @@ -0,0 +1,27 @@
    +  public function description() {
    +    $build = array(
    +      '#markup' => t("The RDF Example module supplies a custom node type with
    +      prepared RDF mappings. In addition, the RDFExampleModifyMappingsTest test
    +      case illustrates the use of the Configuration API to alter a node bundle's
    +      existing mappings"),
    +    );
    

    This is a good start, but if there's a way for the user to see what's been done, provide instructions for how to do that. I think in this case it's just view source and find the mappings, right?

  3. +++ b/rdf_example/lib/Drupal/rdf_example/Tests/RDFExampleModifyMappingsTest.php
    @@ -0,0 +1,114 @@
    +class RDFExampleModifyMappingsTest extends WebTestBase {
    

    I suppose it's easier to demo the mapping modification this way, but it would be great if the user could look at the modified mappings, by viewing source or through whatever means. They can't do this in a test.

  4. +++ b/rdf_example/rdf_example.module
    @@ -0,0 +1,66 @@
    + * 'rdf.mapping.node.recipe.yml', rather than invoking hook_rdf_mapping() as
    + * would be the case in Drupal 7.
    

    +1 on talking about changes since D7.

  5. +++ b/rdf_example/rdf_example.module
    --- /dev/null
    +++ b/rdf_example/rdf_example.routing.yml
    

    Doesn't have a menu_links.yml file, but I made one. In the attached patch.

Status: Needs review » Needs work

The last submitted patch, 3: examples-rdf-example-2102705-3.patch, failed testing.

djevans’s picture

Thanks for the patch, Mile23!

Regarding modifying the mappings for the Article node type, I was trying to avoid the case where someone enables the module on an actual development site and ends up (unintentionally) clobbering existing RDF mappings. I'd also say the test has the benefit of verifying that the RDF is different before and after the config changes.

For the custom node type, at least , how about using a combination of hook_node_view() and EasyRdf_Graph::dump()?

mile23’s picture

Assigned: djevans » Unassigned

Generally unassigning issues. Please re-assign yourself as desired.

kristen pol’s picture

Status: Needs work » Closed (outdated)

Obviously this never happened... closing this almost 7 years later o_O