Feed aggregator

Anexus: How to load JS and CSS libraries in a Drupal 8 controller

Planet Drupal -

How to load JS and CSS libraries in a Drupal 8 controller

In the blog entry http://www.anexusit.com/blog/how-to-add-reactjs-drupal-8-composer, I show you how to add into Drupal 8 any library globally using composer.

But, that library is just there, because the library isn't used for any module or theme. For that reason, I am going to show you how to use a library in a controller.

In my example, I will include ReactJS inside a controller to be able to create react elements in that controller, to show how to use I will create a simple ReactJS form.

0. Setting your environment

I strongly recommend to set your environment in developer mode; that means to enable all debugs possible and disable all caches, the easy way to do that is using the Drupal Console project with the following command:

$ drupal site:mode dev 1. Create a module

Using the Drupal Console we could create a module using the following instruction:

$ drupal generate:module  --module="MySearch" --machine-name="mysearch" --module-path="/modules/custom" --description="My custom search using react" --core="8.x" --package="Anexus" --module-file --composer -n 2. Create a controller

With our module generated, now we need to create a controller to, later on, add the ReactJS library, again using the Drupal Console commands we will make the controller.

$ drupal generate:controller  --module="mysearch" --class="ReactJSFormController" --routes="title:MySearch name:mysearch.react_j_s_form_controller_form method:form path:/mysearch" 3. Including library in our module


To enable libraries in our module, we need to create a file named mysearch.libraries.yml, below could you find an example

react.min:   version: VERSION   js:     /libraries/reactjs/build/react.min.js: {} react:   version: VERSION   js:     /libraries/reactjs/build/react.js: {} react.dom.min:   version: VERSION   js:     /libraries/reactjs/build/react-dom.min.js: {}

The keys react.min, react and react.dom.min are arbitrary strings; you could change for any identifier do you prefer. 

Maybe you are wondering about the empty curly brackets {}, the idea is like each module could load the same library with different properties, like CSS could have media info, or js could be declared to be minified or report that library is an external file.

I included the minify version of React to being used when you push this module in prod and min version could be utilized in development to facilitate the debugging.

The property version is supposed to be the library version, but if you are not sure about the proper value you could use the "constant" VERSION, this constant contains the Drupal version and is used to generate the URL to include the library resource as you can see below.

In my case, I was using Drupal 8.1.9-dev.

4. Install your module


Using the Drupal Console we could install our module

$ drupal module:install mysearch 5. Updating our controller

The controller that was generated its pretty simple as you could see in the following snippet of code:

<?php namespace Drupal\mysearch\Controller; use Drupal\Core\Controller\ControllerBase; /**  * Class ReactJSFormController.  *  * @package Drupal\mysearch\Controller  */ class ReactJSFormController extends ControllerBase {   /**    * Form.    *    * @return string    *   Return Hello string.    */   public function form() {     return [       '#type' => 'markup',       '#markup' => $this->t('Implement method: form')     ];   } }

 

If you use the module Webprofiler you can validate how many JS were loaded in your controller, in my case 69 JS files as you could appreciate in the following image.

Let me change a little bit, to include our ReactJS library.

/**    * Form.    *    * @return string    *   Return Hello string.    */   public function form() {     return [         '#markup' => $this->t('Implement method: index'),         '#attached' => array(             'library' =>  array(                 'mysearch/react.min',                'mysearch/react.dom.min',              ),         ),     ];   }

If you remember, the library was registered as react.min, but we need to include the module name first, to avoid conflict with other modules that use the same key.

Sometimes you need to clear your cache to see the changes; you can do that with Drupal Console

$ drupal cache:rebuild all

After that, you could verify that you have one extra JS file, only for this particular controller.

6. Including ReactJS form

The objective of this example was to demonstrate how to render a ReactJS form in Drupal 8

The first thing I need to do is register a local library to load JS and CSS for our form, as you can check in the following example:

react.form:   version: VERSION   js:     js/mysearch.form.js: {}   css:     theme:       css/mysearch.form.css: {}

As you could notice the path is a little different, because doesn't start with "/" that means is a relative module path instead of Drupal Root relative.

When this new library has loaded both JS and CSS components are loaded.

The content of mysearch.form.css is listed below:

.SearchForm {     padding: 8px 24px; } .SearchForm > input, .SearchForm > textarea, .SearchForm > select {     display: block;     width: 240px;     padding: 4px 8px;     margin-bottom: 8px;     border-radius: 3px;     border: 1px solid #888;     font-size: 14px; } .ContactForm > input.ContactForm-error {     border-color: #b30e2f; }

And the JS for our ReactJS form 

var Search = React.createClass({     render: function(){         return (             React.createElement('form', {onSubmit: this.onSubmit, className: 'SearchForm', noValidate: true},                 React.createElement('input', {                     type: 'text',                     placeholder: 'Search'                 }),                 React.createElement("select", { placeholder: 'Category', value: '', onChange: this.changeHandler },                     React.createElement("option", { value: 1 }, "Software"),                     React.createElement("option", { value: 2 }, "Movie")                 ),                 React.createElement('button', {type: 'submit'}, "Go")             )         );     }, }); ReactDOM.render(React.createElement(Search),  document.getElementById("content"));

The result will be a simple form, but with a lot of possibilities to implemented.

This form doesn't process anything, handle submits and request results via an API will be explaining in a further blog entry.

You can download a full and functional copy of this example from http://github.com/enzolutions/drupal-8-reactjs-form

enzo Thu, 08/11/2016 - 08:03

Issue 252

The Weekly Drop -

Issue 252 - August, 11th 2016 From Our Sponsor Why is Your Site Slow?

Speed is a feature many clients assume they will get but do not always ask for. In fact, you are more likely to hear your clients ask for features or functionality that will make the site slower. Then, right before launch, clients will ask “why is this site so slow?” Join Steve Persch of Pantheon and Marc Drummond of Lullabot on August 25th as they dive into the many answers to this question and look for the root causes of slow sites. Register for the webinar now.

Articles 7 New Improvements You'll See in Drupal 8.2

Steve Burge highlights some of the changes in Drupal 8.2.

There Will Never Be a Drupal 9

Steve Burge makes a bold statement. "So, Drupal is adjusting successfully to the new reality. Big releases are probably history. Drupal's future is in regular, small, backwards-compatible releases."

There Will Be a Drupal 9, and Here Is Why

Gábor Hojtsy responds to Steve Burge's bold declaration that there will never be a Drupal 9. Worth reading.

Drupal 8 Module Development: Mad with Power Sponsored

Module development in Drupal 8 is drastically different from Drupal 7 and previous versions. After you learn a few tricks, you’ll be surprised by how much you can do with so little code. This webinar will cover what it means for module development that Drupal 8 is object oriented, how to leverage the power of an IDE like never before, how to speed up development, and more.

Getting to Grips with Automated Deployment in Drupal 8 Tutorials Avoiding Drupal 7 #AJAX Pitfalls Creating Landing Pages with Drupal 8 and Paragraphs

If you've heard all the buzz about Paragraphs module but haven't had time to check it out give this post a look for a simple example of how you can use this versatile project.

How to Attach a CSS or JS Library to a View in Drupal 8 How to Install Drupal 8 (And Composer) on Windows 10 Bash How to Validate Field Submissions in Drupal

Daniel Pickering shows us how you can set up text validation in Drupal 8 without writing any custom code.

IT's August 2017: You're Still on Drupal 6, and That's OK! Sponsored

A letter from the future about your Drupal 6 site.

JQuery.cookie in Drupal 7 Stop Telling Users That Another User Has Modified the Content in Drupal 8

"Every Drupal developer knows the following error message (maybe some by heart): The content has been modified by another user, changes cannot be saved."

Twig Extensions and Views FTW in Drupal 8

Working with Views can be a challenge. But Israel Morales says, "Many developers use the preprocess functions, or alter the query of the view, however there is another option: twig filters."

Projects Overview of the Commerce 2.x Module for Online Stores The DrupalConsole RC-1 Release Is Close with a Lot of Changes.

The Drupal Console project is being broken up into separate projects.

Use the Official Docker Drupal Library and Its Developer Version Releases admin_views 7.x-1.6 Bean 7.x-1.11 Drupal 8.1.8 Drupal 8.2.0-Beta1 Features 8.x-3.0-Beta7 focal_point 8.x-1.0-Beta2 Lightning 8.x-1.03 migrate_plus 8.x-2.0-Beta2 Openatrium 7.x-2.66 Panopoly 7.x-1.38 Quiz 7.x-5.0-Rc3 Thunder 8.x-1.0-Beta9 Video Mediacurrent: Friday 5: 5 Free QA Webtools Podcasts The Open Mic: DrupalCamp Ottawa 2016 Round Table Events DrupalCamp LA 2016

August 27-28, 2016 in Irvine, California.

DrupalGamp Sydney 2016

September 3rd, 2016 in Sydney, Australia.

BADCamp 2016

October 20-23, 2016 in Berkeley, California.

News Statistics Module Now Has an Overridable Backend Jobs List Your Job on Drupal Jobs

Wanna get the word out about your great Drupal job? Get your job in front of hundreds of Drupal job seekers every day at Jobs.Drupal.Org.

Featured JobsDrupal Front End Web Developer

Eastern Standard 19107/PA/US

Drupal Full Stack Developer

Eastern Standard 19107/PA/US

Remote Drupal Developer

Toptal LLC Anywhere


Jeff Geerling's Blog: Register and Submit Sessions for DrupalCamp St. Louis - Sep 10-11 2016

Planet Drupal -

The time is here! The rest of the DrupalCamp St. Louis 2016 organizers and I were working feverishly this week to get all our ducks in a row, and we now have online registration opened up for DrupalCamp St. Louis 2016! Here are the relevant details:

You'll get a snazzy T-Shirt, a catered lunch, and the fuzzy warm feeling of being part of the great Drupal open source community! Plus I'll be there!

Acquia Developer Center Blog: Debugging Drupal 8 in PhpStorm

Planet Drupal -

Introduction

Welcome to my series of blogs about debugging in Drupal 8.

The reason why I decided to create this series is that a lot of Drupalists use ”legacy” ways of non-interactive debugging based on php-native commands like print_r(), var_dump(), debug_print_backtrace() or commands provided by contributed modules or themes like dpm() or dump() inside of twig templates.

Tags: acquia drupal planet

Miloš Bovan: Where can I use Mailhandler?

Planet Drupal -

Where can I use Mailhandler?

This year’s Google Summer of Code is slowly coming to an end. I am working on latest steps to complete the project as planned. In the previous blog post, I was writing about the final code polishing of Mailhandler, while the focus of last week (#11) was to improve the overall project documentation. Before the project wrap-up blog post, I am going to write about the real use-cases for Mailhandler.

5 steps to create secured user-content-driven Drupal website

One of the best use-cases for Mailhandler would be for media publishing Drupal-based websites. Those websites usually have different user roles for content creators, publishers, editors, administrators… That means a very different set of permissions for each role. For instance, one website could allow its users to create site content. Users could submit it either through a website or by sending a signed email using Mailhandler.

In order to enable users to create content by sending an email, an administrator would need to follow these simple 5 steps:

  1. Enable authenticated users to post nodes for a specific content type (e.g. Users posts).

  2. Set-up an email address that users will send content to.

  3. Enable Mailhandler module and make sure gnu_pg PHP extension is enabled on the web server.

  4. Create a new deliverer in Inmail to fetch new emails. This can be done by using an IMAP deliverer.

  5. Set a content type in the (MailhandlerNode) handler configuration that will be used to create content in.

By completing all the steps, a Drupal website is ready to accept users submissions. Since we are going to use PGP-signed emails which add an additional layer of security, the following steps are needed on the user side:

  1. Log in to the account and update your GPG public key. PGP-signed messages are signed with a private key of a user and verified on the Drupal website with the corresponding public key. PGP method of authentication is briefly explained in this blog post.

  2. The email address in the user account needs to match to the address user wants to send emails from.

  3. The subject needs to begin with [node] part. This is a technical term and tells our plugins about the referenced entity type.

  4. The final step is to write your article and send the email!

Voila! The user created content is available on the website. Since it was digitally signed, it is guaranteed the message was not changed in transmission and the user can not deny sending and signing the message.

Some web hosting services don’t support gnu_pg PHP extension by default. However, you can still benefit from Mailhandler by using a less secure From email address method of user identification. In order to use it, you will need to enable Message Sender Analyzer.

The above use-case represents one part of the Mailhandler features. The module can be used in a similar way to post comments via email, create ads or to make any other email integration with “node” entities out-of-the-box.

To allow end-users and developers an easy start with the module, we have been improving project documentation a lot. A Github pull request has been submitted and passed for the review to my mentors. All Inmail analyzers and handler plugins provided by Mailhandler will be documented and described in details. Also, the project will get a ReadMe.MD file that will consist of the module description, installation, configuration and how-to sections.

Also, I would like to inform you that lead maintainer of the Mailhandler, Dane Powell recognized the efforts we made this summer and gave us write access to the original repository. Thanks to him, we will be able to merge our Github repository and a sandbox project to the main module. This is one step forward to releasing a stable version of Mailhandler and a duty to keep contributing to Mailhandler in the future too.

The plan for the following week is to merge the documentation pull request and work on remaining Inmail issues that we started earlier. Additionally, the final project evaluation starts in less than a week and I will spend some time to prepare for it as well.

 

 

 

Milos Wed, 08/10/2016 - 19:01 Tags Open source Google Summer of Code Drupal Drupal Planet Add new comment

August Happy Hour at Lake Monster Brewing

Twin Cities Drupal Group -

Start:  2016-08-11 17:30 America/Chicago Organizers:  Les Lim wylbur Event type:  User group meeting

Please join us for our reguar Summer Happy Hour location - Lake Monster Brewing! And it's almost in Minneapolis!

Lake Monster has EVERYTHING we need! Just 1505 yards from the Minneapolis Border. TONS of indoor and outdoor seating. Great beer and food truck. Easy location off the Cretin and I94 exit.

Lake Monster Brewing Company
550 Vandalia St #160, St Paul, MN 55114
http://www.lakemonsterbrewing.com/

Come on out and meet all those interesting people that came to Drupal Camp! This is just social and fun and maybe a little Drupal talk.

No need to sign up, just show up!

myDropWizard.com: Drupal 6 security updates for Google Analytics and Piwik!

Planet Drupal -

As you may know, Drupal 6 has reached End-of-Life (EOL) which means the Drupal Security Team is no longer doing Security Advisories or working on security patches for Drupal 6 core or contrib modules - but the Drupal 6 LTS vendors are and we're one of them!

Today, there are two Moderately Critical security releases for the Google Analytics and Piwik modules to fix a Cross-Site Scripting (XSS) vulnerability.

Users who have permission to configure these modules have the ability to add unrestricted, custom JavaScript to the page, however, it's not commonly known that this permission presents a security risk (and there was previously no way to seperate the ability to configure the modules from the ability to add JavaScript).

The new versions create a new permission for adding JavaScript code, which users will need to have in addition to just the permission necessary to configure the modules.

You can download one the of three patches for Google Analytics for 6.x-2.x, 6.x-3.x and 6.x-4.x.

And you can download this one patch for Piwik.

If you have a Drupal 6 site using the Google Analytics or Piwik modules, we recommend you update immediately! We have already deployed the patch for all of our Drupal 6 Long-Term Support clients. :-)

If you'd like all your Drupal 6 modules to receive security updates and have the fixes deployed the same day they're released, please check out our D6LTS plans.

Note: if you use the myDropWizard module (totally free!), you'll be alerted to these and any future security updates, and will be able to use drush to install them (even though they won't necessarily have a release on Drupal.org).

Anexus: How to apply patches in Drupal 8 with Composer

Planet Drupal -

How to apply patches in Drupal 8 with Composer

How I mentioned in my previous post How to add ReactJS in Drupal 8 with Composer, Composer is a fundamental part of Drupal 8 development workflow.

Like any open source projects, contributions are the core of Drupal, and those contributions are included in Drupal modules and themes and event Drupal core via Patches.

1. Drupal Installation.

In this example I will assume that did you install Drupal using *Drupal Composer* project, using an instruction similar to the following:

$ composer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interact 2. Installing module to patch.

I will use the module Address to demonstrate how to patch a module.

Using the following module we could install the Address module in our Drupal 8 project.

$ composer require "drupal/address ~8.1" 3. Patching the module.


The Address module works pretty well, but there is an issue related to full configuration import in a site, this issue was reported and fixed in https://www.drupal.org/node/2663412. But at the moment of this article that solution wasn't included in the stable release of Address module.

Including composer lingua, we could say module and themes are packages and their difference remains in package type. To patch a package is need to edit put composer.json file to provide the patch instructions as you can see in the following snippet of code.

"extra": { "installer-paths": { "web/core": ["type:drupal-core"], "web/libraries/{$name}": ["type:drupal-library"], "web/modules/contrib/{$name}": ["type:drupal-module"], "web/profiles/contrib/{$name}": ["type:drupal-profile"], "web/themes/contrib/{$name}": ["type:drupal-theme"], "drush/contrib/{$name}": ["type:drupal-drush"] }, "patches": { "drupal/address": { "Drupal Addess fix default syncing": "https://www.drupal.org/files/issues/address_syncing.patch" } } }

As you could see, the format is a straightforward entry in patches group, providing the package to patch and the URL of the patch to be download with a human comment.

4. Applying your patches.

The next time do you run *composer install* or *composer update*; your patches will be applied, and you will get an output similar to the next image.

I recommend checking the slides Improving your Drupal 8 development workflow http://weknowinc.com/talks/2016/drupalgov-workflow for more references about how to use Composer in Drupal 8 projects

enzo Wed, 08/10/2016 - 06:57

GVSO Blog: [GSoC 2016: Social API] Week 11: Documentation

Planet Drupal -

[GSoC 2016: Social API] Week 11: Documentation

We are getting closer to Google Summer of Code final evaluation. Students must start submitting their project in 5 days. During these months, I have been working on a project to harmonize social networking functionality in Drupal. So, it was time to start creating documentation about it. This week, I focus on documentation for site builders.

gvso Wed, 08/10/2016 - 08:43 Tags Drupal Drupal Planet GSoC 2016

LevelTen Interactive: Adventures from the Road: The Journey Begins

Planet Drupal -

On Sunday, I trucked out of Dallas in a 38’ RV with a mess of AV equipment, a Jeep named Daisy and a pair of mountain bikes in tow. So without further ado, I'm excited to announce that LevelTen has officially kicked off its four thousand mile journey through twenty-plus cities across the United States. I know what you're thinking: What would possess me to leave my home and business for three months?

The Reason for R.O.W. Season 

I believe we are at a pivotal time for the Web. We are...Read more

Talha Paracha: GSoC'16 – Pubkey Encrypt – Week 11 Report

Planet Drupal -

As you might’ve already guessed, Pubkey Encrypt is a Google Summer of Code’2016 sponsored project. As a part of the GSoC program, I’ve spent the last 2.5 months building this module for Drupal 8. The journey so far has been amazing for me and now we’re approaching the end of the program. So I spent this week in finalizing the module. For those who don’t know, Pubkey Encrypt is a security-related module which provides a way for encrypting data with users’ login credentials. But the way the module is designed, it delegates the task of actual data encryption/decryption to some other module. Previously, we were using Encrypt Test for this purpose, which was just a test sub-module within the Encrypt module, and were waiting for Real AES module to get in a stable state. A few weeks ago, I posted a patch to fix the module but its maintainers haven’t responded yet, and its HEAD is still broken. Thus we decided to use the PHPSecLib Encryption module which in turn uses the external PHP Secure Communications Library and is hence expected to be pretty secure. The task seemed quite simple but the relevant changes simply broke all the tests for Pubkey Encrypt.

Cocomore: Starting small: Why websites should get designed for small screens first

Planet Drupal -

Search engines like Google prefer mobile optimized websites for their ranking. No surprise, after all websites are mainly accessed from devices like smartphones nowadays. If you can’t offer a responsive design you will lose traffic and therefore customers. For this reason, mobile optimized websites are crucial and “mobile first” the best way to get there.

FFW Agency: Mastering the Basics: The Content Plan

Planet Drupal -

Mastering the Basics: The Content Plan Ray Saltini Tue, 08/09/2016 - 19:26

It is amazing how often the content equation is underestimated or misunderstood whether building new properties or renewing existing sites.

The essence of any web project is the content or message to be conveyed. Understandably organizations will engage terrific creative agencies that will put tremendous effort into strategy and design. Unfortunately this often has the unintended effect of de-emphasizing existing content that may, or may not, need to be migrated to your new project. A thorough content audit early on in your planning process will help streamline your project and your budget.

Rarely is content brought over to a project wholesale without some important changes. This can be obvious like making PDF content more search engine friendly or less obvious like adding or changing metadata and reforming its underlying data structure. An audit will help determine if content migration should be included in your web development scope or handled as a separate component.

But unlike planning for strategy and design, resources are often scarce when it comes to content planning and conducting a content audit. It is likely the content planning process will be reduced to task level milestones and allocated to support staff or subject matter experts with little accommodation for the importance, difficulty or breadth of the requirements. This can lead to unforeseen and unwanted surprises during the development and user acceptance cycles of your project. 

Here are a few quick resources to get you started understanding the content planning process is Drupal.

A topic central strategy from a blog post that has only gotten more important: Understanding Content Planning: Why Taxonomy is Your New Best Friend

A great book from an accomplished Drupalist that will answer a lot of basic questions around content planning: The Drupal User's Guide by Emma Jane Hogbin Westby.

And a new series of articles about distributed content management by our very own Hank VanZile Director of Pre Sales Consulting starting with 'What is Distributed Content Management'

Tagged with Comments

FFW Agency: Breaking New Ground - Tapping Free Open Source Drupal to Achieve Big Gains in the Energy Sector

Planet Drupal -

Breaking New Ground - Tapping Free Open Source Drupal to Achieve Big Gains in the Energy Sector Ray Saltini Tue, 08/09/2016 - 19:10

Upheavals in the energy sector in recent years are driving a new Texas-sized need for efficiencies in all facets of business operations and are leading companies to begin mining new areas for streamlining and savings.

Houston, we have a solution.

The good news is open source technologies are opening up areas for exploration previously overlooked by many in the energy sector. In this multi-part series we’ll begin to look at how energy companies use the web and how open source internet technologies can drastically reduce acquisition costs, enable rapid prototyping, and create a potential for windfall profits.

Here’s a preview of our upcoming series on Drupal for the Energy Sector. Use the form below to sign up for our newsletter to get notified when we post new articles or sign up for our free training session on September 16 in Houston.

Acquisition Cost

Ever test drive a Lamborghini? Me neither. How about a proprietary web experience platform by one of the venders in Gartner’s Quadrants? Not happening. You wouldn’t buy a car you couldn’t test drive. Why consider purchasing a software platform you couldn’t pilot? Unless it’s open source you’re going to have to pay dearly for the privilege of any kind of test drive. Among the platforms listed in Gartner’s magic platform, Drupal is the only system you can freely pilot around your business needs.

Rapid Prototyping

Just because its free doesn’t mean you know what to do with it. Many open source systems have a huge transparent install base. You can install a simple plugin in your web browser that will tell you what Content Management System, technology or platform is being used. Drupal takes it even further with free custom developed distributions for different functional needs like ERP, localization and translation, publishing, ecommerce, event organizing, and networking. Agencies can build in various front end technologies and connect them to a Drupal backend with minimal customization.

Windfall Profits

How large is your IT department? Chances are the answer is something like, ‘Not big enough to do the job we have ahead of us.’ The nature of an open source project means you can tap more personnel than you could ever achieve a return on with a proprietary system. Drupal alone has over 3,000 developers that contributed to their latest version, Drupal 8. All of them are writing code that is highly secure and available for you to try and use for free.

Stay tuned for more on each of these and other topics in the coming days.
 

Tagged with Comments

jmolivas.com: The DrupalConsole RC-1 release is close with a lot of changes.

Planet Drupal -

The DrupalConsole RC-1 release is close with a lot of changes.

To make the DrupalConsole project more modular and easy to maintain, we are decoupling into separated projects.

jmolivas Tue, 08/09/2016 - 18:27

Pages

Subscribe to Cruiskeen Consulting LLC aggregator