Comments On All Fieldable Entities: An Update To The Livefyre Module
Senior Developer Engineer, Drupal Architect
Dec 19, 2013
Livefyre wanted to better integrate its services with the Drupal platform and asked us to make sure that the Livefyre integration module was architected to conform with Drupal best practices. They also wanted to give the module better feature parity with Livefyre’s WordPress integration. Following an earlier code review, Pronovix was asked to refactor the module to turn comments into fields, to add search indexing, a synchronization mechanism and a comment count. AaronELBorg did a great job with the original Livefyre module. As a module originally developed for Drupal 6 and then ported to Drupal 7, it did not yet fully leverage all the new possibilities with Drupal 7’s API. When Livefyre asked us what we could do to make the module use best practices in Drupal, the obvious question was what we should do with the comments, originally a custom attachment to the node body. It was around this time that the developers of Drupal 8 worked on the feature to add comments to entities as fields, so we thought it would be a simple and flexible solution to not only extend the commenting functionality to users, but implement it with fields. What are the advantages of this approach? If comments are fields, you can
add them to all fieldable entities
set the order of fields on the admin interface
set field labels (title of the field) on the admin interface
filter them with Views
set up permissions for field management
change appearance for different display modes
All this shows that with a small extra effort we got a significantly more abstract solution, that extends beyond the original idea of commenting on nodes to enable comments on users, taxonomy terms or even custom entities.
Livefyre also wanted us to implement a comment count, as they had on their Wordpress plugin. To achieve this we implemented the comment counts API that returns the number of comments for a specific ID from the Livefyre system. This came in especially handy when handling view modes, as this is what we need for the teaser view most of the time. For the full view, we can use the widget itself. An interesting issue with 3rd party commenting systems is search indexing, because comments are loaded through javascript, and there is no direct connection between the widget and Drupal. We solved this with the Bootstrap API, that loads the comments as HTML content, and then replaces them with the javascript widget. This method displays all comments in the generated source code, but visitors only see the widget – so the user and the web crawler both see the same content. In the open source world vendor lock-in is a big concern: what happens if a site-owner wants to take their data out of a service? In some cases site owners also want to be able to combine and analyze all user interactions across a site. For this reason Livefyre requested us to build a synchronization mechanism that makes it easy to export comments back to Drupal. First we planned to use the core comment module, but because it only lets you add comments to nodes - this would have meant that we lost any comments not attached to nodes. Instead we developed a custom entity with Views integration, that saves changes at each cron run using the Sync API. As a result we extended the Livefyre module and created a 2.x branch, where the new features are available. About Livefyre:Livefyre helps bloggers, publishers, and brands create online communities through conversation and social media curation.
Observations from the Pronovix team on developer portals, technical documentation, architecture, UX, APIs, and the surrounding questions: AI-native workflows, business capabilities, buyable solutions, and operational reality.