Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The single reason for doing this is to allow other modules the ability to alter the SDK InstantArticle object without requiring the Display module.
Proposed resolution
Create a base wrapper class to wrap a FB Instant SDK article object with Drupal Base module configs and hooks for extensibility (without class inheritance, which the FB Instant SDK prevents by design).
Remaining tasks
PR creationPR code/concept reviewPR testingPR merge- Make sure to note API changes in next release after this is merged
- Link follow-up issue to support all Entity types (not just node)
User interface changes
None.
API changes
hook_fb_instant_articles_article_alter()
replaceshook_fb_instant_articles_display_instant_article_alter()
(documented infb_instant_article.api.php
).- New base module class (singleton wrapper + Drupal hook pattern):
\Drupal\fb_instant_articles\ArticleWrapper
. ArticleWrapper::create()
allows setting a$context
param when creating anInstantArticle
object. The Display module setsentity_type
andentity
context before attaching the InstantArticle object to the EntityDrupalInstantArticleDisplay
getArticle()
andrender()
methods have been replaced byArticleWrapper->getArticle()->render()
(or$entity->fb_instant_article->render()
).DrupalInstantArticleDisplay
class has been renamedEntityWrapper
.EntityWrapper::create
now requires new params:$entity_type
and$entity
rather than$node
(to support for all Entity types), and also now requires injecting anInstantArticle
object$instantArticle
.
Data model changes
$node->fb_instant_articles_display_wrapper
(previously contained the Display wrapper class), has now changed to$entity->fb_instant_article
(now containing the Drupal-hook-altered SDKInstantArticle
object retrieved fromArticleWrapper
).- Note that the refactoring also added generic Entity support (not only for node). Link follow-up issue here.
Original report by scotttrigby
Note we are changing our class pattern strategy from this initial idea due to SDK-imposed class inheritance limitations. See above.
This should:
- Be reusable inheritance for both RSS and API use.
- Invoking Drupal hook for building defining Transformer rules (using addRule rather than a JSON file and loadRules).
- Invoking Drupal hook for adding custom transformations (to be used by both the Display module, to call it’s extension class), as well as API use (without a dependency on the Display module, so that additional transformations – such as custom advertising services – can be placed within content HTML).
Comments
Comment #2
scottrigbyComment #3
scottrigbyGithHub PR 35 open for discussion.
Comment #4
scottrigbyThis is not going to get complete before Tomorrow. We can follow up after F8.
Comment #5
scottrigbyComment #6
scottrigbyComment #7
scottrigbyA link might help: https://github.com/BurdaMagazinOrg/module-fb_instant_articles/pull/55
Comment #8
m4oliveiReviewed. Let comments in the PR.
Comment #9
scottrigby@m4olivei I updated the PR with comments. If my question about the last commit in the PR makes sense to you, then I'll update the d.o issue summary (to reflect the class changes).
Comment #10
m4oliveiRe-reviewed and tested. Unfortunately I found some issues. See PR comments for details. Thinking about how to overcome. Overall I like the revised code organization.
Comment #11
m4oliveiComment #12
scottrigby@m4olivei OK I found a way to fix it. This review was really helpful. Check out the last commits and comments on the PR.
Comment #13
scottrigbyUpdated issue summary to reflect strategy updates in the PR.
Comment #14
scottrigby@m4olivei OK, I think I've resolved all the concerns and then some. I'm marking this with the tag `7.x-1.0 blocker` because I would like to see this resolved before we move ahead with a 1.0 release (we've all fixed a bunch of issues, and for both Feeds and API approaches, this module is working - but getting the refactoring resolved, especially the hook change, is pretty important before we do this IMO). I would like to help get the 8.x branch up to speed with 7.x once we get this in as well. Specific comments in GH.
Comment #15
scottrigbyI suppose anyone can help review this.
Comment #17
scottrigbyDeleting comment.
Comment #18
scottrigbyComment #19
scottrigbyMerged into a new 7.x-2.x branch. We will wait until d.o git infrastructure recognizes that new branch, so we can mark fixed against the correct branch.
Comment #20
scottrigbyFixed against 7.x-2.x. Way to go everyone!