Drupal

Chromatic: Javascript Theme Functions in Drupal 7

Planet Drupal - 23 May 2016 - 9:26am

Like it or not, sometimes you have to output HTML in javascript.

Recently, I ran across a line of code something like this while reviewing a pull-request for a client:

var inputMarkup = '<span><label data-val="' + inputText + '" for="checkbox-' + index + '" data-tid="' + tid + '">' + inputText + '</label><input type="checkbox" id="checkbox-' + index + '" data-tid="' + tid + '" data-val="' + inputText + '" /></span>';

Aside from the fact that this code was hard to read (and therefore would be more difficult to maintain), the same code was used with no significant modification in three separate locations in the pull-request.

In PHP, most developers familiar with Drupal would immediately reach for one of the well-known parts of Drupal's theme system, render arrays, theme(), or a *.tpl.php file. In javascript, however, I seldom see much use of Drupal 7's extensive javascript API (also made available in a nicely browseable--though not quite up-to-date--form by nod_).

In this case, the relatively difficult-to-read code, combined with the fact that it was repeated several times across more than one file were clear signs that it should be placed into a theme function.

The Drupal.theme() function in the javascript API works much like theme() in PHP. When using theming functions in PHP, we never call them directly, instead using the theme() function.

In javascript, it's similar; when output is required from a given theme function, we call Drupal.theme() with the name of the theme function required, and any variable(s) it requires.

For example, drupal.org shows the following usage:

Drupal.theme('myThemeFunction', 50, 100, 500);

The example uses Drupal.theme() to call the theme function, myThemeFunction(), and pass it the arguments it requires (50, 100, and 500 in this instance). A theme function can accept whatever number of arguments is necessary, but if your theme function requires more than one parameter, it's good practice to define the function to take a single javascript object containing the parameters required by the function.

So in the case of my code-review, I suggested we use a theme function like this:

/** * Provides a checkbox and label wrapped in a span. * * @param {object} settings * Configuration object for function. * @param {int} settings.index * A numeric index, used for creating an `id` attribute and corresponding * `for` attribute. * @param {string} settings.inputText * The text to display as the label text and in various attributes. * @param {int} settings.tid * A Drupal term id. * * @return {string} * A string of HTML with a checkbox and label enclosed by a span. */ Drupal.theme.checkboxMarkup = function(settings) { "use strict"; var checkboxId = 'checkbox-' + settings.index; var inputText = Drupal.checkPlain(settings.inputText); var checkboxMarkup = ''; // Assemble the markup--string manipulation is fast, but if this needs // to become more complex, we can switch to creating dom elements. checkboxMarkup += '<span>'; checkboxMarkup += '<label data-val="' + inputText + '" for="' + checkboxId + '" data-tid="' + settings.tid + '">'; checkboxMarkup += inputText; checkboxMarkup += '</label>'; checkboxMarkup += '<input type="checkbox" value="' + inputText + '" id="' + checkboxId + '" data-tid="' + settings.tid + '" data-val="' + inputText + '">'; checkboxMarkup += '</span>'; return checkboxMarkup; };

This allowed the calling code to be much simpler:

// Creates themed checkbox. checkboxMarkup = Drupal.theme('checkboxMarkup', { index: i, inputText: $('.inputText').val(), tid: $('.tid') }); $container.append(checkboxMarkup);

The HTML generation is now also more loosely coupled, and more portable, meaning that we can easily use Drupal.theme.checkboxMarkup() elsewhere in this project--or in any other Drupal project.

Categories: Drupal

Conocimiento Plus: [GSoC 2016: Social API] Week 0: Community bonding. GSoC starts!

Planet Drupal - 23 May 2016 - 8:30am
Today, Google Summer of Code has officially started. It is time students get to code. Google Summer of Code (GSoC) is a global program that offers students stipends to write code for open source projects. I will be working with the Drupal community on a project called Social API. This project tries to harmonize social networking functionality in […]
Categories: Drupal

Sooper Drupal Themes: Beta: Revolutionary (Free) Drupal Installation Tool. SooperThemes Rebranding. Glazed & Carbide .10 Releases

Planet Drupal - 23 May 2016 - 7:25am

Introducing Zero-Touch Drupal Product Provisioning

2 years ago I started working on a Drupal CMS distribution that makes it less painful to launch a fully configured Drupal website. Today we're proudly launching what I think is the best CMS installation experience you've ever seen. Pantheon and Acquia cloud might be great tools for people like me who work with Drupal on a daily basis, but there is a huge community of people who need something more simple. Our goal was for users to install a fully configured and themed Drupal website, with fully configured CMS components and demo content without requiring any user interaction.

Our Deployment tool currently does the following completely on auto-pilot:

  1. Runs tests to see if the receiving server ready for installation
  2. Generates a custom build of our Glazed CMS installation profile with the CMS components you need
  3. Uploads the files straight from sooperthemes.com to your server
  4. Uses Drush to go through the entire installation on your server
  5. Installs demo content

Looking For Drupal Hosting Partners

From a wider perspective, I see this kind of service as an answer for the Open Web to the streamlined experiences provided by companies like Wix and SquareSpace. The walled garden alternatives for small businesses. In that light want to integrate with as many great Drupal hosting providers as possible. The first Hosting partner I integrated is A2hosting, because they provide SSH and Drush automatically to all users. I'm looking for other hosting providers who offer this, if you know of, or are such a company please let me know in the comments.

Our service launched in beta but theoritically this should work fine on an Drupal/Drush capable server. It doesn't matter if you run Apache with MySLQ or nginx with PostgreSQL, our software has only the following server requirements:

  • Drupal capable stack
  • Drush
  • Rsync
  • SSH with password authentication
Looking For Testers

This means you can try it out right now on your VPS development server, all you need to provide is an empty web directory and database. If you're trying this and can't get it to work on your Drupal/Drush capable server please let me know in the comments. We did a lot of testing but the variety of server configurations is so vast that I'm sure we can improve our software's compatibility. Just to be clear, you don't need to be a subscriber or even registered on sooperthemes.com to use this. As a guest user you cannot choose the premium themes in the form but you can install any configuration of our CMS distribution with the Glazed Free theme.

It has been an adventure developing this new deployment tool. If you are excited too please test it and let me know what you think!

In Other News: SooperThemes Rebranding. Glazed 2.4.10 and Carbide Builder 1.0.10 Released

This week I've also updated the SooperThemes logo. For the past year the sooperthemes.com website has reflected what our new product was: Completely new and finding out where it wants to go. Now the logo more reflects the values of simplicity, open source and friendliness. These are the values I want to embed in our products. The logo is much simpler than the old one. The openings in the O are for open source. And the last detail is the Happy e's. This little touch of Dutch Design is a tilted back lower case e, it was invented by Heineken and reminds of a laughing head.

Today you can also download the latest patch-level release of Glazed theme and Carbide Builder. These releases contain no new features, only bug fixes. See the Glazed CHANGELOG and Carbide CHANGELOG. We've also updated the YouTube background library and put a usage example in the bottom of the Sections and Backgrounds demo page. Enjoy!

Categories: Drupal

Background rotate

New Drupal Modules - 23 May 2016 - 4:59am

Add an interface to upload multiple background images to be changed with a set interval.

Categories: Drupal

Devel Snippet

New Drupal Modules - 23 May 2016 - 2:42am

The Devel Snippet module allows to save code snippets inputted on the Execute PHP Code (provided by the Devel module) to database for further execution.

Categories: Drupal

Author Pane Popup

New Drupal Modules - 23 May 2016 - 2:35am

Shows author information in a tooltip manner. Integrates with Stylish jQuery Tooltips. You can use various qTip style instances for author pane popup.

Installation
  1. Copy author_pane_popup directory to your modules directory.
  2. Enable the module at module configuration page.
  3. Configure Author Pane Popup in admin/config/author_pane_popup/settings page.
Features
  1. Show content author information as a tooltip.
  2. Integrates with Stylish jQuery Tooltips.
Dependencies
  1. Author Pane

    Author Pane is a block of information about a given user, like those typically found on a forum post, but can be used in other places as well. From core, it collects the user picture, name, join date, online status, contact link, and profile information.

Categories: Drupal

Progressive Web App (PWA)

New Drupal Modules - 23 May 2016 - 1:51am
Categories: Drupal

Virtuoso Performance: Global migration sprint day - Monday May 23

Planet Drupal - 22 May 2016 - 9:47am
Global migration sprint day - Monday May 23

As I wrote in my last blog post, I'd like to try doing regular sprint days for Drupal 8 migration. These will be a bit more informal than than a conference sprint - basically, a day when anyone interested in helping move the migration system from its experimental status to a fully supported subsystem of Drupal core can show up in #drupal-migrate, or just pick a relevant issue and start working on it. Our theme for at least the first of these sprints is migrate-critical issues - these are issues for the migration system which would be marked critical if the system were full supported, and thus our highest priority to address. Some issues need code written, some need tests written, some could use code review and/or manual testing, and some need discussion around the best approaches - there are multiple ways to help out.

If you're interested in contributing to the sprint, on Monday May 23:

  1. Check the triaged list of issues - if you find one you'd like to work on, add your drupal.org username under "Who's working on it". The fact that someone is doing work on a given issue doesn't mean you can't help too - virtually any issue without a stable patch could use input and suggestions, and any issue with a patch could use review and manual testing.
  2. Join #drupal-migrate on IRC. Get help selecting an issue to work on, coordinate with others on a given issue, ask general migration questions (or answer them!), ...
  3. If writing or testing code for a given issue, pay attention to which Drupal core version the issue is filed against (generally it'll be 8.1.x for bug fixes, and 8.2.x for new work) and be sure you pull the correct core branch to work against.

I expect to be available in #drupal-migrate for most of the time from around 9am to (at least) 6pm U.S. Central time (minus a lunch break). You can expect to find other people with migration expertise there at most times, of course.

mikeryan Sun, 05/22/2016 - 11:47 Tags
Categories: Drupal

Transactional PHP

New Drupal Modules - 22 May 2016 - 5:46am
Installation
  1. Apply the core patch bundled with this module.
  2. Update autoload with dependencies:
    %> composer drupal-update
Configuration

None

Using the default database connection

Categories: Drupal

PDF To Webform

New Drupal Modules - 21 May 2016 - 11:28pm
Categories: Drupal

Timedropper

New Drupal Modules - 21 May 2016 - 10:48am

This module provides integration for the jQuery Timedropper plugin, providing a better timepicker.

Categories: Drupal

Field Stripe

New Drupal Modules - 21 May 2016 - 9:54am

Provides a field for Stripe Checkout, also provides a formatter for a price field if commerce_price is used.

Categories: Drupal

Tour link block

New Drupal Modules - 21 May 2016 - 9:11am

This module add's a block with a tour link.
This block is shown on page's which have a tour.
This allows users which don't have toolbar permissions to start a tour.

Categories: Drupal

Display Field Copy

New Drupal Modules - 21 May 2016 - 8:32am

Display Field Copy provides the ability to make a display copy of a field with Display Suite. The copy of the field can use a different formatter (with different config) than the single field that is currently available in core.

For instance, if a site has a single entity reference field and the display needs the list rendered on the page twice (once as a rendered entity and once as a list of links). This module could be used to create a copy of the field and apply a different formatter to it.

Categories: Drupal

Non Clickable Menu Items

New Drupal Modules - 20 May 2016 - 1:45pm

Module 'Non-Clickable Menu Items' allows to have menu items which will not react on user's clicks. This could be a parent menu items which should behave as a containers.

Each menu item will have a setting 'Disable clicks' at edit page and also admin's settings page '/admin/config/user-interface/non-clickable-menu-items' where collected all selected menu items.

Support: GreyBox Technologies

Categories: Drupal

FFW Agency: Great Examples Of Distributed Content Management In Product Companies

Planet Drupal - 20 May 2016 - 10:24am
Great Examples Of Distributed Content Management In Product Companies erik.wagner Fri, 05/20/2016 - 17:24

Welcome to the fifth post in my series on Distributed Content Management.  In previous posts I’ve defined the concept and provided some great examples of Distributed Content Management use cases in higher education, the pharmaceutical industry and media and entertainment companies.  In today’s post I’ll wrap up my industry-specific use cases by investigating ways in which product companies can use Distributed Content Management to improve their approach to everything from internationalization of their websites to managing community contributions. 

Setting The Scene

Product websites, whether for physical or virtual products, must ultimately influence their visitors.  For direct-to-consumer products, the goal may be a direct conversion - to get the visitor to buy/download the product.  Business-to-business products often have a more complex buyer’s journey, starting with something as seemingly minimal as driving the visitor to contact the company for more information.  Within the digital sphere, companies whose products are extensible platforms or systems may be seeking not only end-users, but developers or contributors to expand on the value of their initial offerings.  In all of these scenarios, the content presented to the user must be keenly adapted to the task at hand and, with products especially, must co-exist with information available from external sources.  Carefully planning their approach to Distributed Content Management - to the point of expanding what they may consider content - is a key tool for a product company’s success.

Use Case 1: A Multi-System Approach to Product Experience Management

Many web platforms strive to be all-in-one solutions for a product’s online presence; however, savvy product companies recognize that they can build a superior web experience by integrating multiple systems and relying on their core strengths.  A common example of this for product companies is around enterprise e-commerce systems (such as Demandware, Magento, or BigCommerce).  All of these solutions provide some level of content management and layout control; however, larger organizations that make heavy use of Distributed Content Management staples such as content re-use and custom publishing workflows may find the out-of-the-box tools duplicative or not sophisticated enough for their processes. Luckily, these systems allow organizations to interact with them programmatically through APIs and many provide pre-built connectors to popular content management systems such as Drupal and WordPress.  By integrating e-commerce tools with powerful content management systems, product companies can have the best of both worlds for both their internal processes and customers’ experience.

Use Case 2: Internationalization of Product Websites

Entry-level internationalization may be achieved with a single website and automated text translation; however, as a product company’s reach expands so may the sophistication of their internationalization strategy - and that can impact their needs for Distributed Content Management.  A simple example of this may be the transition between automatic translation technology (such as Google Translate, Lingotek Inside or Translate.com’s Website Translator) and content management provided by native-speaking editors.  Native-language content production, with its cultural nuances and idiomatic expressions, can provide a far superior experience to a website’s visitors but introduces a number of elements to a company’s Distributed Content Management strategy. For example, how will translated content fit within the company’s existing publishing workflow?  How will different language teams coordinate around new pages and content?  Taking this further, companies that produce physical products often have unique product lines in different geographical regions, a reality that necessitates a decentralized management strategy with close coordination around company-wide content.

Use Case 3: Curating Other People’s Content

More so than ever before, potential customers have easy access to a flood of content about a product before they decide whether or not to use it.  For a company’s digitally-inclined customers, Amazon’s Q&A and reviews, YouTube videos and even social media interactions with a company have become key elements guiding their decision making.  Attentive product companies actively manage these external sources: answering questions on Amazon, providing high-profile bloggers and YouTube producers with review copies of products, etc., but companies interested in further differentiating themselves are beginning to recognize that the content produced on these channels should be part of their Distributed Content Management strategy.  For example, Twitter actively promotes itself as a customer service platform, citing not only its “unparalleled reach,” but the fact that its conversations can be “embedded across other media.” However, many content strategists promote this same approach for curating testimonials.  Curating and embedding tweets in which a user speaks positively about a company’s product is a great example of managing distributed content to increase potential buyers’ social trust in a product.

Use Case 4: Content For Contributors and Existing Customers

Prospective users are not the only audience for product companies.  Physical product companies, especially those making electronics, often provide access to support resources, such as frequently asked questions and downloadable product manuals. Companies that produce digital products may offer software downloads and updates or, in the case of open products, API and developer documentation.  With each of these areas comes important decision around a company’s approach to Distributed Content Management.  Will product support require registration?  If so, what external system integrations are required to share the appropriate content with the user?  Will developers be able to contribute documentation?  If so, what kind of publishing workflows will be in place in for community-contributed content?  While each new audience brings additional considerations around Distributed Content Management, it also increases the opportunities to improve a product’s digital experience and extend its reach.

What’s Next?

Now that we have sufficiently explored industry-specific use cases for Distributed Content Management, I’ll move on to discussing prerequisites for proper planning.  Thoughts or questions?  Reach out in the comments below or tweet them to me at @HankVanZile.

Tagged with Comments
Categories: Drupal

Field Report

New Drupal Modules - 20 May 2016 - 9:51am

The Field Report module creates a report page that lists all of the fields on the site, along with their label, description, field type, and what they are shared with, organized by entity type and bundle.

This should make it really easy to see how the fields are organized onto your site, and identify any that are missing descriptions or relevant labels, and find fields that could be shared but aren't, etc.

Categories: Drupal

Four Kitchens: Trip Report: DrupalCon 2016 — Five Days in New Orleans

Planet Drupal - 20 May 2016 - 9:14am

A mostly full report on what went down last week in the Big Easy, gonzo journalism -style. …

Categories: Drupal

Group Queue

New Drupal Modules - 20 May 2016 - 9:10am

This module allows you to create a new queue made of several, already existing, child queues in a specific order.
When the group queue is processed, items are returned from the child queues following the queue group configured order. You can still process component child queues as usual as standalone queues.

Example

Supose you create a group queue, named group1 consisting in queue1 and queue2.

Categories: Drupal

Pages

Subscribe to As If Productions aggregator - Drupal