Zivtech: Getting Started with React, Drupal 8, and JsonAPI

Planet Drupal - Tue, 2017/07/11 - 11:00am

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
Categories:

lakshminp.com: User authentication in Drupal 8 - passwords

Planet Drupal - Tue, 2017/07/11 - 10:09am

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.

Categories:

Agiledrop.com Blog: AGILEDROP: Top Drupal Blogs from June

Planet Drupal - Tue, 2017/07/11 - 9:37am
Because of the summer, many people were or are going to the holidays. But that doesn't mean that they rested. In fact, there were many high-quality blog post about Drupal in the past month, so let's take a lot at the top Drupal Blogs from June. We'll start with Sasa Nikolic and his Nested Paragraphs Translation. In this blog post the author warns that translating content in Drupal isn't a straightforward task and has many obstacles. So, he recapped the basics first and then dug deeper in nested paragraph translation. Our second choice is a fascinating story of how Jack switched his career… READ MORE
Categories:

Hook 42: Inclusivity Through Accessibility

Planet Drupal - Mon, 2017/07/10 - 11:40pm

Last month Hook 42 had the pleasure of hosting Mike Gifford from Open Concept for conversation, collaboration, and thought leadership surrounding Accessibility and Drupal.

Why the push for accessibility on the web? Roughly 20% of the population has some form of disability. 

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.
 

Categories:

Drupal CMS Guides at Daymuse Studios: Drupal 8 Getting Started: Install, Composer, & Facebook Login

Planet Drupal - Mon, 2017/07/10 - 9:30pm

We'll walkthrough setting up your local development LAMP environment, installing Drupal 8, configuring Composer, and your first module: Simple FB Connect.

Categories:

Palantir: Why We're Standing Up for Net Neutrality

Planet Drupal - Mon, 2017/07/10 - 6:52pm
Why We're Standing Up for Net Neutrality brandt Mon, 07/10/2017 - 11:52 George DeMet Jul 12, 2017

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.
Categories:

Acquia Developer Center Blog: Making a Custom, Acquia-Hosted Site Affordable for Higher Ed

Planet Drupal - Mon, 2017/07/10 - 5:24pm

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
Categories:

Mediacurrent: Drupal vs Sitecore, Part 1 of 2

Planet Drupal - Mon, 2017/07/10 - 5:17pm

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.

Categories:

Roman Agabekov: Setting up server for Drupal with Nginx and Php-fpm under Debian

Planet Drupal - Mon, 2017/07/10 - 3:24pm
Setting up server for Drupal with Nginx and Php-fpm under Debian Submitted by admin on Mon, 07/10/2017 - 13:24

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
Categories:

Xeno Media: Entity Reference Roundup

Planet Drupal - Mon, 2017/07/10 - 11:00am

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.

Use case:

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.

Use case:

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.

Use case:

  • 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.
Entity Reference Display

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.

Use case:

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.

Use case:

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.

Use case:

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.

Use case:

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.

Use case:

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.

Use case:

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.

Use case:

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.

Use case:

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.

Use case:

When referencing custom entities that don't have view-modes of their own, you would not need to write your own custom formatters

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

Use case:

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.

Use case:

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!

Use case:

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.

Use case:

Providing a better admin experience.

Phew! Thanks for making it to the end! Do you have a favorite Entity Reference module that we missed? Let us know on Twitter at @xenophiles and @thejimbirch

Happy Drupaling!

Acknowledgements

Thanks to Mike Acklin for his help with this article, and to all the awesome module maintainers and contributors!

Photo by Bethany Legg on Unsplash

Categories:

Wim Leers: On simplicity & maintainability: CDN module for Drupal 8

Planet Drupal - Sun, 2017/07/09 - 8:02pm

The first release of the CDN module for Drupal was 9.5 years ago yesterday: cdn 5.x-1.0-beta1 was released on January 8, 2008!

Excitement

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.


Learning

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
CDN module in Drupal 8: radically simpler

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!
changed/improved
  1. 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
  2. the UI is now a separate module
  3. the UI is optional: for power users there is a sensible configuration structure with strict config schema validation
  4. complete unit test coverage of the heart of the CDN module, thanks to D8’s improved architecture
  5. preconnecting (and DNS prefetching) using headers rather than tags in , which allows a much simpler/cleaner Symfony response subscriber
  6. tours instead of advanced help, which very often was ignored
  7. there is nothing to configure for the SEO (duplicate content prevention) feature anymore
  8. 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
removed
  1. File Conveyor support
  2. separate HTTPS mapping (also mentioned above)
  3. all the exceptions (blacklist, whitelist, based on Drupal path, file path…) — all of them are a maintenance/debugging/cacheability nightmare
  4. configurability of SEO feature
  5. configurability of unique file identifiers for the Forever cacheable files feature
  6. 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:

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:

  1. About edge cases & complexity:
Edge cases are no longer my concern. I mean, I’m making sure that edge cases can be done and the API will cater to it, but I won’t go too far and implement them. […] we’ve somewhat reduced the flexibility in order to reduce the complexity; but while doing so, made sure edge cases can still hook into the process.


2. About tests:

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.


3. About feature set & UI:

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.


  1. I also did my bachelor thesis about Drupal + CDN integration, which led to the Drupal 6 version of the module. ↩︎

  2. Unit tests in Drupal 8 are wonderful, they’re nigh impossible in Drupal 7. They finish running in seconds. ↩︎

Categories:

Nacho Digital: Drupal Picnic BsAs Argentina

Planet Drupal - Sun, 2017/07/09 - 5:12pm
With Buenos Aires Argentina user group we are organizing a meeting on Sat 22nd and Mon 24th of July

It's been a long time since our last camp was done on BsAs (2009) and thanks to the inspiration of Drupal Camp Chile we've been planning doing another for a while.

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

You can find more details on our event page.

Categories:

Tech Rendezvous: Encounter with VPN

Planet Drupal - Sun, 2017/07/09 - 2:00am
Categories:

TimOnWeb.com: JQuery.cookie in Drupal 7

Planet Drupal - Sat, 2017/07/08 - 2:54am

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: 

  1. drupal_add_library('system', 'jquery.cookie');

Wondering to ...

Read now

Categories:

clemens-tolboom pushed to master at clemens-tolboom/p5js-examples

On github - Fri, 2017/07/07 - 5:14pm
Jul 7, 2017 clemens-tolboom pushed to master at clemens-tolboom/p5js-examples
  • 8011edc Added modified version of Pieter.

Third & Grove: Overriding Admin Views in Drupal 7

Planet Drupal - Fri, 2017/07/07 - 4:00pm
Overriding Admin Views in Drupal 7 josh Fri, 07/07/2017 - 10:00
Categories:

Mediacurrent: Friday 5: 5 Reasons to Attend a Drupal Camp

Planet Drupal - Fri, 2017/07/07 - 2:47pm

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. 

 

Categories: