You don't need to go fully 'headless' to use React for parts of your Drupal site. In this tutorial, we'll use the Drupal 8 JsonAPI module to communicate between a React component and the Drupal framework.
As a simple example, we'll build a 'Favorite' feature, which allows users to favorite (or bookmark) nodes. This type of feature is typically handled on Drupal sites with Flag module, but let's say (hypothetically...) that you have come down with Drupal-module-itis. You're sick of messing around with modules and trying to customize them to do exactly what you want while also dealing with their bugs and updates. You're going custom today.
Follow along with my Github repo.Configure a custom Drupal module
First thing's first: data storage. How will we store which nodes a user has favorited? A nice and easy method is to add an entity reference field to the user entity. We can just hide this field on the 'Manage Form Display' and/or 'Manage Display' settings since we'll be creating a custom user interface for favoriting.
When you install the Favorite module in the repo, it will add the field 'field_favorites' for you to the user entity: see the config/install directory.
Next up: define the part of the page that React will replace. Typically, you will replace an HTML element defined by an id with a React component. If this is your first time hearing this, you should do some basic React tutorials. I started with one on Code Academy.Read more
We saw how general authentication works with Drupal 8 in the previous post. We shall see how the actual authentication happens when user logs in. It all begins with a humble login route in user.services.yml of the user module.
There is quite a diversity of abilities. Sight and hearing are the ones people tend to give the most thought to, but there are cognitive, learning, neurological, physical, and speech abilities that can all change how a user engages with the web. As able-bodied people age, they may experience some of the same challenges as those born with disabilities: failing eyesight, diminished hearing, carpal tunnel, and loss of mobility or dexterity.It's the law.
Under Section 508, government funded agencies must give disabled employees and members of the public access to information that is comparable to access available to others. American with Disabilities Act (ADA) “prohibits discrimination and ensures equal opportunity for persons with disabilities in employment, State and local government services, public accommodations, commercial facilities, and transportation.”
"Currently, web developers are less expensive than lawyers." ~ Mike Gifford
But, more than anything, it's the right thing to do. Accessibility promotes inclusivity and diversity on the web.
We'll walkthrough setting up your local development LAMP environment, installing Drupal 8, configuring Composer, and your first module: Simple FB Connect.
Join us for a day of action urging the FCC and Congress to preserve Title II net neutrality protections.
Stay connected with the latest news on web strategy, design, and development.Sign up for our newsletter.
Most people who use the internet take for granted the ability to easily access content and services from a variety of different sources. We watch movies and TV shows on Netflix, Hulu, Amazon, and countless other streaming video services. We listen to music on Spotify, Apple Music, Pandora, and Tidal. We communicate with others using social media and messaging apps like Facebook, Twitter, Instagram, WhatsApp, and Snapchat. We get our news and analysis from hundreds of sites representing the full spectrum of political thought in the United States and beyond.
Being able to quickly and easily publish or consume content from nearly anywhere in the world is not just one of the key reasons for the rapid growth of the internet, but also one of its founding principles.
Today, however, that principle is under threat. The United States Federal Communications Commission (FCC) is considering rolling back net neutrality protections that ensure equal access to online content for broadband internet users. Without net neutrality, internet service providers would be able to offer preferred access to some content providers, and withhold it from others.
Some of these providers also own their media companies and have a business interest in making it easier for people to view and purchase their content than someone else’s. Because most people in the United States don’t have many options when it comes to broadband internet access, losing net neutrality protections means that many consumers may no longer be able to freely choose the online services that best meet their needs.
Think about it this way: imagine a world in which Cuisinart not only made great kitchen appliances, but they also owned your local electric company. And imagine that electric company decided that they were going to charge you more for the electricity used to power any appliances that you had that were made by KitchenAid or any other other non-Cuisinart brand. You would probably argue that that’s absurd, because there’s nothing inherently different about the electricity that’s used to power a KitchenAid toaster versus one made by Cuisinart.
But that’s precisely what the broadband internet service providers opposed to net neutrality want to be able to do: prioritize traffic from their preferred content providers, making it more difficult or costly to access others. In reality, there’s no inherent difference in the traffic that comes from one site versus another; they’re all ones and zeros. Whether you choose to watch a movie on Netflix, Hulu, or FilmStruck shouldn’t be the business of your internet service provider any more than the brand of toaster you use to toast bread in the morning should be the business of your electric utility.
At Palantir, we believe that helping others discover, create, and share knowledge can help strengthen humanity. Many of the websites and online experiences that we architect, design, and build convey information that enable people to make more informed choices and in some cases, even help save lives. It’s important to us that our work is accessible to everyone regardless of what internet service provider they’re using.
That’s why we’re proud to join forces with hundreds of other sites around the web this July 12th for a day of action urging the FCC and Congress to preserve Title II net neutrality protections. You can find out more and make your voice heard at www.battleforthenet.com. We hope you’ll stand alongside us to help keep the web a free and open place.
Stay connected with the latest news on web strategy, design, and development.Sign up for our newsletter.
With budget cuts and rising expectations, higher education websites have become a challenging balancing act of function and affordability. Late in 2016, we set out to build a website solution that would leverage a CMS to create a repeatable, flexible website solution that meets current expectations in higher ed clients, and leaves room for them to make it their own -- without requiring custom development for each client. We also wanted to ensure that it could be deployed for under $50,000; put the work of managing and maintaining the site into the hands of the content team; and have a low-recurring cost to the client.Tags: acquia drupal planet
Annually, the information technology research firm Gartner publishes its magic quadrant report comparing web content management systems (CMS) at the enterprise level. At this writing, the most recent report places Acquia/Drupal, Adobe Experience Manager (AEM), and Sitecore as the three leaders in the field, based on both their completeness of vision and their ability to execute on organizational requirements.
In the previous article Setting up Nginx on a Debian server as front-end for Apache of the series of articles for Drupal sysadmins we explained Nginx configs that allow it working through static queries while Apache serves dynamic content. This article offers a look at an alternative setup, where Php-fpm takes the place of Apache. The operating principle for our web server will be as follows:Tags
Drupal's Entity reference fields are the magic sauce that allows site builders and developers to relate different types of content. Because the fields allows builders and administrators to reference different types of content (entities), it facilitates the building of complex data models and site architectures.
Like anything in Drupal, the community takes the core tools and builds additional functionality on top. Here is a slew of modules that extend or complement the Drupal 8 core reference field so you can do even more!Entity Reference Revisions
This module is from the team that brought you the Paragraphs module. Adds an Entity Reference field type that has revision support. It's based on the core Entity Reference module but allows you to reference a specific revision of an entity.
An entity is actually part of a parent entity (with an embedded entity form). When the parent entity is updated, the referenced entity is also updated, thus the previous revision of the parent entity should still be pointing to the previous version of the entity in order to fully support revision diff and rollback.Entity Reference Override
An entity reference field paired with a text field. You can use this module to
- Override the title if you are linking to the referenced entity.
- Add an extra CSS class to the referenced entity.
- Override the default display mode for the field on an entity-by-entity basis.
Aggregate lists of referenced entities like related articles, but you want to override the name or appearance of individual items.Entity references with text
Allows you to provide custom text along with one or more entity references.
- Add a referenced author, the word "and ”, and then another referenced author.
- On another node, Add a referenced author, the words "with support from ”, and then another referenced author.
- On another node, Add a referenced author, a comma ", ”, another referenced author, the word "and ”, and then another referenced author.
This module adds a field type that allows you to select the display mode for entity reference fields. This allows an editor to select from different display modes such as Teaser, Full, or any you add.
It also includes a Selected display mode field formatter which renders the referenced entities with the selected display mode.
Allowing the administrator to change the display of related articles from a grid display mode to a list display mode.Entity Reference Views Select
This module allows you to change your Entity reference fields to be displayed as a select list, or checkboxes/radio buttons in administrative forms. It does this by allowing you to use Views as the reference method, where you can format the results giving the administrator a much better experience.
Showing an icon or thumbnail in a selectable list when referencing a list, or a referenced image.Entity Reference Tab / Accordion Formatter
This cool little module works on both Entity Reference and Entity Reference Revisions fields and provides a field formatter for displaying the referenced entity in jQuery Tabs or jQuery Accordion.
Returning multivalue Paragraphs items in tabs or accordion format.Views Entity Reference Filter
Provides a new admin friendly Views filter for configuring entity reference fields. It allows users to select the labels of the entities they want to filter on rather than manually entering the IDs.
Providing a better admin experience.Better Entity Reference Formatter
This module extends Drupal's default field formatter for entity reference fields in order to make it more flexible by introducing a new field formatter plugin. Along side the view mode option, you can also define the number of entities to return, or a specific entity, like the first, last, or offset them.
Showing the first related product referenced from another product.Entity Reference Validators
The plural in its name suggests more is coming, but currently this module adds a single validator for Entity Reference fields, the Circular reference validator. This prevents you from using the entity reference field to reference itself.
Preventing an entity reference field on node 1 from linking to node 1.Entity Reference Integrity
This interesting sounding module lists other entities that reference your entity.
It also includes a sub-module Entity Reference Integrity Enforce which will attempt to protect entities that are referenced by other entities, and not allowing its deletion.
Protect the integrity of the site by protecting referenced content.Entity Reference Quantity
This module extends the default entity reference field that includes a "Quantity" value in the field definition so you don't have to build a separate entity just to store two distinct fields.
It also includes autocomplete and dropdown field widgets that allow you to select which entity and add the quantity value.
I'll use the example from this great blog on the module: A real world example might be a deck builder for a trading card game like Magic: The Gathering or the DragonBall Z TCG. We want to reference a card from a deck entity and put in the quantity at the same time.Entity Reference Formatter
This module creates a generic field formatter for referenced entities which allows you to select the formatter based on the referenced entity in the display settings form.
When referencing custom entities that don't have view-modes of their own, you would not need to write your own custom formattersPermissions by field
This module extends the Entity Reference field that adds permissions along with the referenced entity. By adding this field, you can manage access to the entities referenced by this field and select permission level (none, view, update, delete).
A lighter version of Organic Groups, or the Group modules.Views Reference Field
In Drupal 8, Views are now entities! Drupal core's Entity Reference field is able to reference Views, however you can't actually reference the Views displays. This module extends core's entity reference module to add the display ID so that a View can be rendered in a field formatter.
Adding a Views reference field to a Paragraphs bundle so you can have a view in and around other paragraph bundles. We implemented this technique in the Bootstrap Paragraphs module.Dynamic Entity Reference
So cool! This awesome module adds the functionality to let you reference more than one entity type. It create a single field in which you can reference Users, Blocks, Nodes, Contact Forms, Taxonomy Terms, etc!
Creating a "related” field, and allowing your administrators to select anything they want.Entity Reference Drag & Drop
This module creates a Drag & Drop widget for the standard Entity reference fields. It provides you with a list of available entities on the left, and you can select them by dragging and dropping them to the list on the right.
Providing a better admin experience.
Thanks to Mike Acklin for his help with this article, and to all the awesome module maintainers and contributors!
On January 27, 2008, the first RC followed, with boatloads of new features. Over the years, it was ported to Drupal 61, 7 and 8 and gained more features (I effectively added every single feature that was requested — I loved empowering the site builder). I did the same with my Hierarchical Select module.
I was a Computer Science student for the first half of those 9.5 years, and it was super exciting to see people actually use my code on hundreds, thousands and even tens of thousands of sites! In stark contrast with the assignments at university, where the results were graded, then discarded.Frustration
Unfortunately this approach resulted in feature-rich modules, with complex UIs to configure them, and many, many bug reports and support requests, because they were so brittle and confusing. Rather than making the 80% case simple, I supported 99% of needed features, and made things confusing and complex for 100% of the users.
Main CDN module configuration UI in Drupal 7.
In my job in Acquia’s Office of the CTO, my job is effectively “make Drupal better & faster”.
In 2012–2013, it was improving the authoring experience by adding in-place editing and tightly integrating CKEditor. Then it shifted in 2014 and 2015 to “make Drupal 8 shippable”, first by working on the cache system, then on the render pipeline and finally on the intersection of both: Dynamic Page Cache and BigPipe. After Drupal 8 shipped at the end of 2015, the next thing became “improve Drupal 8’s REST APIs”, which grew into the API-First Initiative.
All this time (5 years already!), I’ve been helping to build Drupal itself (the system, the APIs, the infrastructure, the overarching architecture), and have seen the long-term consequences from both up close and afar: the concepts required to understand how it all works, the APIs to extend, override and plug in to. In that half decade, I’ve often cursed past commits, including my own!
That’s what led to:
- my insistence that the dynamic_page_cache and big_pipe modules in Drupal 8 core do not have a UI, nor any configuration, and rely entirely on existing APIs and metadata to do their thing (with only a handful of bug reports in >18 months!)
- my “Backwards Compatibility: Burden & Benefit” talk a few months ago
- and of course this rewrite of the CDN module
I started porting the CDN module to Drupal 8 in March 2016 — a few months after the release of Drupal 8. It is much simpler to use (just look at the UI). It has less overhead (the UI is in a separate module, the altering of file URLs has far simpler logic). It has lower technical complexity (File Conveyor support was dropped, it no longer needs to detect HTTP vs HTTPS: it always uses protocol-relative URLs, less unnecessary configurability, the farfuture functionality no longer tries to generate file and no longer has extremely detailed configurability).
In other words: the CDN module in Drupal 8 is much simpler. And has much better test coverage too. (You can see this in the tarball size too: it’s about half of the Drupal 7 version of the module, despite significantly more test coverage!)
CDN UI module in Drupal 8.
- all the fundamentals
- the ability to use simple CDN mappings, including conditional ones depending on file extensions, auto-balancing, and complex combinations of all of the above
- preconnecting (and DNS prefetching for older browsers)
- a simple UI to set it up — in fact, much simpler than before!
- the CDN module now always uses protocol-relative URLs, which means there’s no more need to distinguish between HTTP and HTTPS, which simplifies a lot
- the UI is now a separate module
- the UI is optional: for power users there is a sensible configuration structure with strict config schema validation
- complete unit test coverage of the heart of the CDN module, thanks to D8’s improved architecture
- preconnecting (and DNS prefetching) using headers rather than tags in , which allows a much simpler/cleaner Symfony response subscriber
- tours instead of advanced help, which very often was ignored
- there is nothing to configure for the SEO (duplicate content prevention) feature anymore
- nor is there anything to configure for the Forever cacheable files feature anymore (named Far Future expiration in Drupal 7), and it’s a lot more robust
- File Conveyor support
- separate HTTPS mapping (also mentioned above)
- all the exceptions (blacklist, whitelist, based on Drupal path, file path…) — all of them are a maintenance/debugging/cacheability nightmare
- configurability of SEO feature
- configurability of unique file identifiers for the Forever cacheable files feature
- testing mode
For very complex mappings, you must manipulate cdn.settings.yml — there’s inline documentation with examples there. Those who need the complex setups don’t mind reading three commented examples in a YAML file. This used to be configurable through the UI, but it also was possible to configure it “incorrectly”, resulting in broken sites — that’s no longer possible.
There’s comprehensive test coverage for everything in the critical path, and basic integration test coverage. Together, they ensure peace of mind, and uncover bugs in the next minor Drupal 8 release: BC breaks are detected early and automatically.The results after 8 months: contributed module maintainer bliss
The first stable release of the CDN module for Drupal 8 was published on December 2, 2016. Today, I released the first patch release: cdn 8.x-3.1. The change log is tiny: a PHP notice fixed, two minor automated testing infrastructure problems fixed, and two new minor features added.
We can now compare the Drupal 7 and 8 versions of the CDN module:
- 149 support requests for the Drupal 7 version, with 14 in the last 12 months (the module is stable now after all these years of course) and 83 bug reports over 6.5 years (78 months), with ~6000 sites using it.
- 7 support requests for the Drupal 8 version in the last 8 months and 1 bug report (a bug in a test). With ~500 sites using it.
In other words: maintaining this contributed module now requires pretty much zero effort!Conclusion
For your own Drupal 8 modules, no matter if they’re contributed or custom, I recommend a few key rules:
- Selective feature set.
- Comprehensive unit test coverage for critical code paths (UnitTestCase)2 + basic integration test coverage (BrowserTestBase) maximizes confidence while minimizing time spent.
- Don’t provide/build APIs (that includes hooks) unless you see a strong use case for it. Prefer coarse over granular APIs unless you’re absolutely certain.
- Avoid configurability if possible. Otherwise, use config schemas to your advantage, provide a simple UI for the 80% use case. Leave the rest to contrib/custom modules.
This is more empowering for the Drupal site builder persona, because they can’t shoot themselves in the foot anymore. It’s no longer necessary to learn the complex edge cases in each contributed module’s domain, because they’re no longer exposed in the UI. In other words: domain complexities no longer leak into the UI.
At the same time, it hugely decreases the risk of burnout in module maintainers!
And of course: use the CDN module, it’s rock solid! :)Related reading
Finally, read Amitai Burstein’s “OG8 Development Mindset”! He makes very similar observations, albeit about a much bigger contributed module (Organic Groups). Some of my favorite quotes:
- About edge cases & complexity:
I think there is another hidden merit in tests. By taking the time to carefully go over your own code - and using it - you give yourself some pause to think about the necessity of your recently added code. Do you really need it? If you are not afraid of writing code and then throwing it out the window, and you are true to yourself, you can create a better, less complex, and polished module.
2. About tests:
One of the mistakes that I feel made in OG7 was exposing a lot of the advanced functionality in the UI. […] But these are all advanced use cases. When thinking about how to port them to OG8, I think found the perfect solution: we did’t port it.
3. About feature set & UI:
Unit tests in Drupal 8 are wonderful, they’re nigh impossible in Drupal 7. They finish running in seconds. ↩︎
- AttachmentSize CDN UI module version 3.0-rc2 on Drupal 830.62 KB
We finally put a day thanks to a visit from Enzo. We are calling it a "PicNic" and not a camp due to the extend it'll have, it will be two days:
- On Saturday 22nd we'll have an sprint with mentoring
- On Monday 24th there will be technical conferences
A quick tip for all Drupalistas outhere: if you want to use jQuery.cookie in your project, you actually don't have to download and install the library. jQuery.cookie is a part of Drupal 7 and can be included as easy as typing:
- drupal_add_library('system', 'jquery.cookie');
Wondering to ...
Happy Friday everyone, and a happy 4th of July weekend. This week we have April Sides on the program to talk about how much fun Drupal Camps are and what you will take away from them.