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

  1. PR creation
  2. PR code/concept review
  3. PR testing
  4. PR merge
  5. Make sure to note API changes in next release after this is merged
  6. Link follow-up issue to support all Entity types (not just node)

User interface changes

None.

API changes

  • hook_fb_instant_articles_article_alter() replaces hook_fb_instant_articles_display_instant_article_alter() (documented in fb_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 an InstantArticle object. The Display module sets entity_type and entity context before attaching the InstantArticle object to the Entity
  • DrupalInstantArticleDisplay getArticle() and render() methods have been replaced by ArticleWrapper->getArticle()->render() (or $entity->fb_instant_article->render()).
  • DrupalInstantArticleDisplay class has been renamed EntityWrapper.
  • EntityWrapper::create now requires new params: $entity_type and $entity rather than $node (to support for all Entity types), and also now requires injecting an InstantArticle 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 SDK InstantArticle object retrieved from ArticleWrapper).
  • 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

scottrigby created an issue. See original summary.

scottrigby’s picture

Title: Refactor Transformer/InstantArticle classes to be reusable and extensible » Refactor base classes for extensibility
scottrigby’s picture

Status: Active » Needs work

GithHub PR 35 open for discussion.

scottrigby’s picture

Issue tags: -7.x-1.0-rc1 blocker

This is not going to get complete before Tomorrow. We can follow up after F8.

scottrigby’s picture

Assigned: scottrigby » Unassigned
Issue summary: View changes
Status: Needs work » Needs review
scottrigby’s picture

Issue summary: View changes
scottrigby’s picture

m4olivei’s picture

Status: Needs review » Needs work

Reviewed. Let comments in the PR.

scottrigby’s picture

Status: Needs work » Needs review

@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).

m4olivei’s picture

Re-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.

m4olivei’s picture

Status: Needs review » Needs work
scottrigby’s picture

Status: Needs work » Needs review

@m4olivei OK I found a way to fix it. This review was really helpful. Check out the last commits and comments on the PR.

scottrigby’s picture

Issue summary: View changes

Updated issue summary to reflect strategy updates in the PR.

scottrigby’s picture

Assigned: Unassigned » m4olivei
Issue tags: +7.x-1.0 blocker

@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.

scottrigby’s picture

Assigned: m4olivei » Unassigned

I suppose anyone can help review this.

  • scottrigby committed 089e621 on 7.x-2.x
    Issue #2703063: Store InstantArticle object directly on Entity instead...
  • scottrigby committed 24a1188 on 7.x-2.x
    Issue #2703063: Add  param to hook_fb_instant_articles_article_alter()
    
  • scottrigby committed 24f5ca1 on 7.x-2.x
    Issue #2703063: Fix file name for Base module api.php doc
    
  • scottrigby committed 26b5550 on 7.x-2.x
    Issue #2703063: Update comments to reflect Entity not only node support
    
  • scottrigby committed 33a75a0 on 7.x-2.x
    Issue #2703063: Update API Rules import article call to use...
  • scottrigby committed 3571f65 on 7.x-2.x
    Issue #2703063: API change: Rename DrupalInstantArticleDisplay to...
  • scottrigby committed 428e6b1 on 7.x-2.x
    Issue #2703063: Update Display module file to work with class...
  • scottrigby committed 6998ce5 on 7.x-2.x
    Issue #2703063: Fix isset check in...
  • m4olivei committed 79ea149 on 7.x-2.x
    Merge pull request #60 from scottrigby/...
  • scottrigby committed 7eaf694 on 7.x-2.x
    Issue #2703063: Fix documentation
    
  • scottrigby committed 98ee457 on 7.x-2.x
    Issue #2703063: Move hook_fb_instant_articles_instant_article_alter from...
  • scottrigby committed a897974 on 7.x-2.x
    Issue #2703063: Use entity_extract_ids to get bundle name in...
  • scottrigby committed b2b1ac2 on 7.x-2.x
    Issue #2703063: API change: hook_fb_instant_articles_article_alter...
  • scottrigby committed b30a458 on 7.x-2.x
    Issue #2703063: Move Field module hooks to an include file for...
  • scottrigby committed b4d4771 on 7.x-2.x
    Issue #2703063: Separate EntityWrapper into EntityPropertyMapper (runs...
  • scottrigby committed b945938 on 7.x-2.x
    Issue #2703063: Update DrupalInstantArticleDisplay to require injecting...
  • scottrigby committed b949802 on 7.x-2.x
    Issue #2703063: New base module class (singleton wrapper pattern) so...
  • scottrigby committed e627e4e on 7.x-2.x
    Issue #2703063: Fix documentation
    
  • scottrigby committed e6b5146 on 7.x-2.x
    Issue #2703063: Remove unused fb_instant_articles_display_time_element...
  • scottrigby committed e6cb795 on 7.x-2.x
    Issue #2703063: Add rules alter hook (to remove or reorder existing...
  • scottrigby committed f1526bf on 7.x-2.x
    Issue #2703063: Change static transformer_config.json to new...
  • scottrigby committed f9f3ea9 on 7.x-2.x
    Issue #2703063: use new setContext() method to set Entity context on the...
scottrigby’s picture

Deleting comment.

scottrigby’s picture

Issue summary: View changes
scottrigby’s picture

Merged 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.

scottrigby’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Needs review » Fixed
Issue tags: -7.x-1.0 blocker +7.x-2.0 blocker

Fixed against 7.x-2.x. Way to go everyone!

Status: Fixed » Closed (fixed)

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