Drupal

Old Cyrillic Transliteration

New Drupal Modules - 16 March 2018 - 4:11pm

Drupal 7 transliteration rules for Drupal 8 (cyrillic, currently supports only Russian and Ukrainian)

Categories: Drupal

Entity Extra

New Drupal Modules - 16 March 2018 - 2:19pm

A module to ease developer's life when creating custom entities.

A lot has been done in Drupal 8, but there is always something to improve.

This module offers:

  • Base classes for content entities that already define common fields like ID, UUID, label, created and changed dates, and so on.
  • A Views based entity list builder.
  • An entity form base class that takes care of redirecting the user and showing a message.
Categories: Drupal

Mediacurrent: The New Mediacurrent.com: Adventures in Decoupled Drupal

Planet Drupal - 16 March 2018 - 1:20pm

In our first post that announced the new Mediacurrent redesign, we looked at the evolution of Mediacurrent.com over the years and talked through the over goals of the relaunch. Now let’s take a look under the hood to see some of the cool stuff we did and discuss what our development team learned along the way.Let's talk architecture

Now for the fun part, the technical architecture of the new website. First, the backend was upgraded from Drupal 7 to Drupal 8 - that will probably not be a huge shock to anyone. The more interesting aspect of this build is that we have now implemented a fully decoupled frontend. We accomplished this using a static generator called Jekyll which has been integrated with the Drupal backend. More on that in a bit. First let’s answer the question, “Why decoupled?”

Why decoupled?

A decoupled architecture provides flexibility for constant evolution, opening the door to a variety of potential programming languages and design philosophies to accomplish your website goals. There are any number of articles that discuss the benefits of moving to a decoupled approach. For this post, I want to focus specifically on the points that were deciding factors for our team.

Security

While we do have full confidence in the security features that Drupal offers, we have to acknowledge that a static public site does offer some advantages that make securing the application easier. First of all, we have the option to make the backend CMS completely walled off from the public site. It’s not a hard requirement that the Drupal admin is made publicly accessible. Second, there are simply fewer vulnerabilities that a static frontend will be susceptible to in comparison to a full PHP application. For example, it’s harder to DDOS a site serving only HTML/CSS/JS and there is no server side code running that could be hijacked by an SQL injection attack.

Performance

Decoupled sites often have a performance boost over a fully Drupal-rendered site because the frontend is more custom and lightweight. This is certainly true in our case. The static frontend requires no processing at the time of request so the page is served up immediately with no server-side execution required.

Hosting

One of the things we liked about this particular solution was that it made the hosting architecture pretty simple and inexpensive. With only editors logging into the CMS and the static site being served by Gitlab, we were able to have a fast, reliable stack up and running relatively easily. Up-time is great in that you aren’t as vulnerable to a production error or traffic spike bringing the site down. That being said, all platforms are subject to downtime each year.

Eating our own dog food

As many other agencies will attest to, when you work on your own website it’s a good chance to try something different! We looked at what some competitors had done and we wanted to try an approach that would be a good fit for our needs without overcomplicating the end solution. This endeavor was a way to take some risks and learn along the way.

Dividing the work

The great thing about decoupling is that you break apart the work that needs to get done. The frontend team can focus on the frontend stuff without being tied too much to the backend work (although there will always be some overlap). Our agency spends a lot of our day delivering solutions to our clients so being able to break apart some of the work streams was an advantage. We like that in the future we don’t necessarily need to do a big redesign and Drupal upgrade at the same time. With a decoupled approach, we have the flexibility to tackle each separately.

Technical Overview

Now that you have seen the “Why” behind this approach, let’s look at the “How.” We have kept our Drupal CMS in Bitbucket, which gets deployed to a Pantheon server. That piece is still the same as its been for many years. The new wrinkle is that the public frontend is served on GitLab Pages. If you haven’t heard of Github Pages (which run on Jekyll), Github, GitLab and many other services allow you host Jekyll source files which they can auto-compile into HTML pages and host for you for free or cheap. Pretty neat huh? We ended up going with GitLab Pages because GitLab allows you to add more build customizations than Github. We have also looked at potentially using Netlify in the future as the host for our Jekyll files.

The question you might be asking is how does Drupal content make its way to GitLab? Put simply, we translate node content to markdown and push to the GitLab API on every node save. For user files, we actually still use Drupal uploads and reference the path within Markdown files. If you are familiar with Markdown files, these are the “content” files that Jekyll compiles into pages. The diagram below illustrates the basic flow.

The concept is pretty simple: have Drupal manage your content, write to Jekyll markdown files and deploy those files to a static host.

Why not [Insert favorite Node framework here]?

You might be saying, that's all well and good but why go with a static generator over a server-rendered JavaScript framework like Next.js or Nuxt.js?

The short answer is that we reviewed several options and concluded there wasn’t a framework we felt was a fit at the time we were planning development (around mid-late 2016). Going with a JavaScript-only framework was ruled out for SEO reasons and the options for Isomorphic (server + client side js) frameworks weren’t as stable as we would have liked. Jekyll was the most popular static framework (and still is) with a variety of plugins we could utilize. After doing some POC’s we opted for Jekyll in order to keep the page rendering lean, simple and speedy. The overall complexity of the integration was also a deciding factor in choosing Jekyll over other options.

Trade-offs

One of the fun challenges with a static only site is that you need to learn how to get around the lack of server side rendering. The files are of course static, thus if you want anything dynamic looking you are limited to mostly JavaScript-based solutions. A couple quick examples are forms and the site search. For forms, we were already using Pardot hosted forms for marketing automation, so that wasn’t a big tradeoff. For site search, we went with a pretty cool solution that leverages https://lunrjs.com/ to handle searching the site. Essentially we have Drupal push an index file that Lunr.js can search against using only Javascript in the browser. For RSS, we still generate the RSS feed from Drupal and push to GitLab.

Lessons learned and looking forward

Now that we have the shiny new website up and running, it’s time to look ahead. Would we recommend taking this exact approach in 2018? I would say not exactly. While we are still intrigued by the power of static generators serving as a front end we think something like Gatsby.js (Node/React-based) might have more upside than Jekyll. Further, we aren’t sold on this type of static-only being able to scale in comparison to Node-hosted solutions. The options for server-rendered JavaScript frameworks increase by the day and many have matured over the last few years. Mediacurrent.com will continue to be our place to try new approaches and share with you everything we’ve learned along the way. Thanks for joining us in this journey and enjoy the new site!

Additional Resources
The 3 C’s and 1 D of Drupal: Why Decoupled Matters | Mediacurrent Blog
Relearning Accessibility for a Decoupled Front End | Mediacurrent Blog
4 Benefits of Decoupled Architecture for Enterprise Marketers | Mediacurrent Blog

Categories: Drupal

Matt Glaman: Creating better Drupal module release notes

Planet Drupal - 16 March 2018 - 8:00am
Creating better Drupal module release notes mglaman Fri, 03/16/2018 - 10:00 Every software release needs to have release notes. End users need to be able to understand what it is that they are upgrading to and any associated risks, or risks mitigated by upgrading and receiving bug fixes. Across the board proprietary and open source software projects either hit or miss on delivering decent release notes. During MidCamp I decided to help fix that problem for Drupal.org projects.
Categories: Drupal

Commerce Inventory: Square

New Drupal Modules - 16 March 2018 - 6:42am
Categories: Drupal

Acquia Developer Center Blog: Experience Express in Chicago: Inclusion and Drupal 8 in the Spotlight at MidCamp

Planet Drupal - 16 March 2018 - 5:59am

Every time I leave the Windy City, I feel something pulling me back. This time, it wasn't the gusts that whip around the skyscrapers towering over Lake Shore Drive. Instead, it was the renewed excitement I could feel in the air on the heels of Wednesday's release of Drupal 8.5, and the mood at MidCamp, held at the Lincoln Park campus of DePaul University, was celebratory and animated.

Tags: acquia drupal planet
Categories: Drupal

Polyfill

New Drupal Modules - 16 March 2018 - 5:39am

Provides Babel Polyfill as a drupal library.

Example usage

modulename.libraries.yml

mylibrary: version: 1.x js: js/mylibrary.js: {} dependencies: - polyfill/babel
Categories: Drupal

Agiledrop.com Blog: AGILEDROP: Delivering value not just the solution

Planet Drupal - 16 March 2018 - 3:16am
When you are in the business of selling services or expertise, you will face competition. Nowadays a global competition where (y)our competitors take on various shapes and sizes. So when an organisation goes on the market looking for certain services, this organisation probably has a predefined set of requirements for the provider. These can change over time, but some basics are set at the beginning.    What is the client actually buying? There are at least three factors that influence the buying process at the organisation which needs a new website. The first one is the organisation… READ MORE
Categories: Drupal

CKEditor Hint

New Drupal Modules - 16 March 2018 - 12:45am

This module will create a CKEditor button to easily add hint message using CKEditor.

Adds a new button to Drupal's CKEditor which allows the user to create & display any type of content in an hint format.

The styling is minimal and easily over write-able by developers.

Categories: Drupal

sms_smsbao

New Drupal Modules - 15 March 2018 - 11:37pm

SMSBAO gateway for SMS Framework
SMS Framework短信宝网关
提供基于SMS Framework短信宝平台整合.

Categories: Drupal

QuaDrupal

New Drupal Modules - 15 March 2018 - 7:41pm

Coming soon....

Categories: Drupal

Commerce cashpresso

New Drupal Modules - 15 March 2018 - 12:08pm

This module integrates the cashpresso payment provider into Drupal Commerce, to allow payment by instalments.

Installation

See the modules README.md for information on installing and configuring this module.

Credits

Commerce Product Review module was originally developed and is currently
maintained by Mag. Andreas Mayr.

Categories: Drupal

Commerce checkout order fields

New Drupal Modules - 15 March 2018 - 8:12am

Commerce checkout order fields provides a new checkout form view mode on orders.

All fields exposed on this form view mode, are available from the Commerce order fields checkout pane.

This can be used to collect additional data during the checkout, for example:
- Order comments
- Shipping notes
- ..

Categories: Drupal

Animate On Scroll

New Drupal Modules - 15 March 2018 - 5:06am

Animate On Scroll (AOS) library allows you to animate elements as you scroll down, and up.If you scroll back to top, elements will animate to it's previous state and are ready to animate again if you scroll down.This module provides integration with AOS library.

Requirements
Animate On Scroll Library. (Check demo at: http://michalsnik.github.io/aos/)

Categories: Drupal

CKEditor Alert Notification

New Drupal Modules - 15 March 2018 - 3:49am

This module will create a CKEditor button to easily add alert message using CKEditor.

Adds a new button to Drupal's CKEditor which allows the user to create & display any type of content in an alert box format.

The styling is minimal and easily over write-able by developers.

Categories: Drupal

CKEditor Large Numbers List

New Drupal Modules - 15 March 2018 - 2:55am

This module will create a CKEditor button to easily add large numbered ordered list.

Adds a new button to Drupal's CKEditor which allows the user to create & display any type of content in an ordered list with large numbers in circle format.

The styling is minimal and easily over write-able by developers.

Categories: Drupal

Salesforce Auth

New Drupal Modules - 15 March 2018 - 2:27am

Salesforce Auth allow users to sign in to Drupal using API's credentials.

Salesforce auth is a module that uses for acting on Drupal system without having an account on it with the help of it's defined API's credentials.

This is not a single sing-on kind, it actually generate the "Login with Salesforce" button link from where user can easily login to their Salesforce as well as Drupal system without having sign-up process.

Thank you!

Categories: Drupal

PubMed submit

New Drupal Modules - 15 March 2018 - 2:22am

PubMed comprises over 28 million citations for biomedical literature from MEDLINE, life science journals, and online books. PubMed citations and abstracts include the fields of biomedicine and health, covering portions of the life sciences, behavioral sciences, chemical sciences, and bioengineering. PubMed also provides access to additional relevant web sites and links to the other NCBI molecular biology resources.

Categories: Drupal

jQuery Migrate 3.x

New Drupal Modules - 15 March 2018 - 1:58am

jQuery Migrate 3.x restores the API that was removed in the jQuery 3.x, previously marked as deprecated. Without it the breaking changes introduced by jQuery 3.x may break your site.

Categories: Drupal

PreviousNext: Bare Templates: Removing Unnecessary Markup in Twig files

Planet Drupal - 15 March 2018 - 1:48am

In most of the projects we build, the HTML markup provided by core just gets in the way. There is way too many wrapper divs. This can cause issues when trying to create lean markup that matches what is produced in a generated styleguide.

In this post, I'll introduce you to the concept of bare templates, and how you can remove unnecessary markup from your Twig templates.

by Pasan Gamage / 15 March 2018

In Drupal 8, a couple of themes are shipped by default to serve a common set of end user needs.

Among them are:

  • Bartik: A flexible, recolourable theme with many regions and a responsive, mobile-first layout.
  • Seven: The default administration theme for Drupal 8 was designed with clean lines, simple blocks, and sans-serif font to emphasise the tools and tasks at hand.
  • Stark: An intentionally plain theme with almost no styling to demonstrate default Drupal’s HTML and CSS.
  • Stable: A base theme. Stable theme aggregates all of the CSS from Drupal core into a single theme. Theme markup and CSS will not change so any sub-theme of Stable will know that updates will not cause it to break.
  • Classy: A sub-theme of Stable. Theme designed with lot of markups for beginner themers.

But in an actual business scenario the requirements and expectations of a client towards the look and feel of the website is far more distinct than the themes that are provided in Drupal core.

When building your site based upon one of these themes it is common to face issues with templating during the frontend implementation phase. Quite often the default suggested templates for blocks, nodes, fields etc. contain HTML wrapper divs that your style guide doesn’t require.

Usually the most effective way is to build themes using the Stable theme. In Stable, the theme markup and CSS are fixed between any new Drupal core releases making any sub-theme to less likely to break on a Drupal core update. It also uses the verbose field template support for debugging.

Which leads us to use bare templates.

What is a bare template?

A bare template is a twig file that has the minimum number of HTML wrappers around actual content. It could be simple as a file with a single content output like {{content.name}}

Compared to th traditional approach, bare templates provide benefits such as:

  • Ease of maintenance: With minimum markup the complexity of the template is much lesser making it easy to maintain.
  • Cleaner Markup: The markup will only have the essential or relevant elements where as in traditional approach there are a lot of wrappers leading to a complex output.
  • Smaller page size: Less markup means less page size.
  • Avoids the need for markup removal modules: With bare markup method we do not need to use modules like fences or display suite. Which means less modules to maintain and less configuration to worry about.
Our Example

We need to create a bare template for type field and suggest it to render only field name and field_image of my_vocabulary taxonomy entity. This will avoid Drupal from suggesting this bare template for other fields belonging to different entities.

Field template

Let's have a look at field template which resides at app/core/themes/stable/templates/field/field.html.twig

{% if label_hidden %} {% if multiple %} {% for item in items %} {{ item.content }} {% endfor %} {% else %} {% for item in items %} {{ item.content }} {% endfor %} {% endif %} {% else %} {{ label }} {% if multiple %} {% endif %} {% for item in items %} {{ item.content }} {% endfor %} {% if multiple %} {% endif %} {% endif %}

As you see there is quite a lot of div wrappers used in the default template which makes it difficult to style components. If you are looking for simple output, this code is overkill. There is however, a lot of valuable information is provided in the comments of field.html.twig which we can use.

{# /** * @file * Theme override for a field. * * To override output, copy the "field.html.twig" from the templates directory * to your theme's directory and customize it, just like customizing other * Drupal templates such as page.html.twig or node.html.twig. * * Instead of overriding the theming for all fields, you can also just override * theming for a subset of fields using * @link themeable Theme hook suggestions. @endlink For example, * here are some theme hook suggestions that can be used for a field_foo field * on an article node type: * - field--node--field-foo--article.html.twig * - field--node--field-foo.html.twig * - field--node--article.html.twig * - field--field-foo.html.twig * - field--text-with-summary.html.twig * - field.html.twig * * Available variables: * - attributes: HTML attributes for the containing element. * - label_hidden: Whether to show the field label or not. * - title_attributes: HTML attributes for the title. * - label: The label for the field. * - multiple: TRUE if a field can contain multiple items. * - items: List of all the field items. Each item contains: * - attributes: List of HTML attributes for each item. * - content: The field item's content. * - entity_type: The entity type to which the field belongs. * - field_name: The name of the field. * - field_type: The type of the field. * - label_display: The display settings for the label. * * @see template_preprocess_field() */ #} The code Building the hook.

We will be using hook_theme_suggestions_HOOK_alter() to suggest the two fields to use our bare template when rendering.

It is important to note that only these two fields will be using the bare template and the other fields (if any) in that entity will use the default field.html.twig template to render.

my_custom_theme_theme_suggestions_field_alter (&$hooks, $vars){     // Get the element names passed on when a page is rendered.     $name = $vars['element']['#field_name'];     // Build the string layout for the fields.     // :::     $bare_hooks = [         'taxonomy_term:my_vocabulary:teaser:name',         'taxonomy_term:my_vocabulary:teaser:field_logo',     ];     // Build the actual var structure from second parameter     $hook = implode(':', [         $vars['element']['#entity_type'],         $vars['element']['#bundle'],         $vars['element']['#view_mode'],         $vars['element']['#field_name'],     ]);     // Check if the strings match and assign the bare template.     if (in_array($hook, $bare_hooks, TRUE)) {         $hooks[] = 'field__no_markup';     } }

The hook key field__no_markup mentioned in the code corresponds to a twig file which must reside under app/themes/custom/my_theme/templates/field/field--no-markup.html.twig

Debugging Output

In order to see how this is working, we can fire up PHPStorm and walk the code in the debugger.

As you can see in the output below, the implode() creates the actual var structure from the second parameter. We will use this to compare with the $bare_hooks array we created  fields specific to content entity types that we need to assign the bare template.

Note: As best practise make sure you pass a third argument TRUE to in_array(). Which will validate the data type as well.

 

Bare Template Markup

The following is the contents of our bare template file. Notice the lack of any HTML?

{# /** * @file * Theme override to remove all field markup. */ #} {% spaceless %} {% for item in items %} {{ item.content }} {% endfor %} {% endspaceless %}

Bare templating can be used for other commonly used templates as well. To make it render a minimal amount of elements.

Conclusion

We can always use custom templating to avoid getting into complicated markups. And have the flexibility to maintain the templates to render for specific entities.

Resources Tagged Style Guides, Twig
Categories: Drupal

Pages

Subscribe to As If Productions aggregator - Drupal