Transcription
www.drupaleurope.org
How to COPEwith external entitiesPublishing & Media
Goal
COPE: Create Once Publish EverywhereStrategy to create content in one place and publish it in many placesSimple example: a block that appears on multiple webpagesAlso applies to the same content on multiple websites.Drupal solutions such as Migrate, Replication and Feeds all createduplicates of the contentSingle Point Of Truth
External Entities“This module allow you to connect to datasets from externaldatabases and use it in your Drupal 8 website.”Data is handled by Drupal as content entities with remote storage.External entities can be used in most ways that standard entities can.First released in 2015 (jelle S). Branch 1.x still in Alpha.Branch 2.x started August 2018 (rp7). Improvements include separateentity types instead of bundles.
Simple example (today’s session)Display a teaser for an article on another website
Complex example (for another day)Shared media library
Display teaser card for a remote articleRemote websiteCreate a REST service to GET multiple and single articlesLocal websiteCreate an External Entity typeCreate a View with an entity browser displayAdd entity reference field to a content type with an entity browser widgetTheme the external entity
REST service onremote websiteKeeping it simple with a View with RESTexport displaysAlternatives e.g. JsonAPI, GraphQL, coreRESTful moduleAuthentication and permissions - ignored!2 REST exports for single and multiple resultsShows 2 options - separate fields andrendered entity
JSON responsehttp://remote.test/rest/remote-pages? format jsonhttp://remote.test/rest/remote-pages/19? format jsonResponse for single item is inside an array could use custom serializer to remove arrayResponse shows 2 options - separate fields orrendered entity. Fields rewritten in Views UI.Relative links in the body or the renderedentity have to be changed to external links,e.g. with a custom PathProcessor
External entity typeStorage client part 1Create ‘external card’ external entity typeModule includes storage clients for REST and aexample using WikipediaSet REST endpoint and JSON formatRead-only as we are only using GETPager settings are not needed
External entity typeStorage client part 2Patch allows REST client to remove the array thatViews wraps arounf the response for a single item.Set parameter to add ‘ format json’ to therequest
External entity typeField mappingMap nid and title in response to entity typepropertiesCreate Drupal fields and map response fieldsto themSet text formatsComplex mapping is possible in 2.x e.g.‘contact information/email address’
External entity typeCaching and themeEnable theming to render the entities with aTwig template in the active theme
External card fields
External cardsList is at http://client.test/external-cardSingle item is at http://client.test/external-card/19Create Twig template in the theme:external-card.html.twig
Views and Search APINo automatic Views supportWaiting for core issue to be resolved “Make Views use /project/drupal/issues/2079019No recent work on EntityFieldQuery ViewsBackend moduleWorkaround with Search APICreate index in Search API with databaseserver
Search API indexRun the index.Entities are indexed in tablesearch api db external cards
Create a viewBase table for the view is the Search API index
Configure the viewCreate Entity Browser displayAdd the field “Entity browser bulk select form forSearch API views”
Create entity browserCreate Entity Browser displayAdd the field “Entity browser bulk select form forSearch API views”
Create entity browserAdd View display widget using the External cardsview
Entity Cards fieldCreate the External Cards field on a nodecontent typeChoose the Entity browser widget with theExternal Cards entity browser
Field displayChoose rendered entity for displaying the ExternalCards field
Edit the pageSelect an external card with the entity browserThe remote website could be hit with lots ofrequests if the entities’ caches have expired.Use Varnish!
Local Website composer.json
Adrian BatemanPrincipal developerpolynya@we are nomensa
Become a Drupal contributorFriday from 9am First timers workshop Mentored contribution General contribution
databases and use it in your Drupal 8 website." Data is handled by Drupal as content entities with remote storage. External entities can be used in most ways that standard entities can. Simple example (today's session) . Add the field "Entity browser bulk select form for Search API views" .