Problem/Motivation

We need to add metadata to the document before exporting it to JSON.
Currently, we haven't found a way of doing it, or at least not an "easy" way.

Proposed resolution

Create an alter hook on ApplenewsManager::getDocumentDataFromEntity to allow modules to alter the document.

API changes

Creation of hook_applenews_document_alter

Issue fork applenews-3191110

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

BetoAveiga created an issue. See original summary.

betoaveiga’s picture

betoaveiga’s picture

StatusFileSize
new3.24 KB

Excuse me. I uploaded the wrong patch on my previous comment. Re-uploading.

m4olivei made their first commit to this issue’s fork.

m4olivei’s picture

Assigned: Unassigned » m4olivei

I spoke with @BetoAveiga offline about this the other day.

There is clearly a need to extend the functionality the module provides such that you can customize the Apple News format document before it's sent to Apple News. There are currently other means of doing the same thing that this new hook is intended to do via overriding the \Drupal\applenews\Normalizer\ApplenewsContentEntityNormalizer service. The nice thing about that is you get access to the \ChapterThree\AppleNewsAPI\Document object to use it's API so your not in the business of ensuring the right JSON format

That approach has it's downsides as well. Namely it's quite verbose.

I think we can arrive at a middle ground by using an event subscriber embedded in the normalizer stack, which will allow subscribers to affect the \ChapterThree\AppleNewsAPI\Document object.

We agreed to go that route. I'm currently working on a patch.

m4olivei’s picture

Opened a merge request with some foundation. Refactors a bit for better testability and includes a simple test for the normalizer to make sure I didn't break things. This will be good to build the event subscriber onto.

m4olivei’s picture

Needed to rebase against 8.x-1.x. Fingers crossed for green tests.

  • m4olivei committed 5a18e77 on 8.x-1.x
    Issue #3191110 by m4olivei, BetoAveiga: Allow modules to alter document...
m4olivei’s picture

Assigned: m4olivei » Unassigned
Status: Active » Fixed

Yay, green! Also I discussed with @BetoAveiga offline, and he's good with the changes.

Merged to 8.x-1.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.