Drupal

Lullabot: Interpreting the Drupal Core Commit History

Planet Drupal - 5 June 2019 - 10:40am

According to Drupal’s community documentation, “The Benevolent Dictator for Life (BDFL),” Dries Buytaert, is the “chief decision-maker for the [Drupal] project.” In practice, as Dries has pointed out, he wears “a lot of different hats: manager of people and projects, evangelist, fundraiser, sponsor, public speaker, and BDFL.” And he is chairman and chief technology officer of a company that has received

Categories: Drupal

Hook 42: All Aboard To Chattanooga

Planet Drupal - 5 June 2019 - 8:00am
All Aboard To Chattanooga Lindsey Gemmill Wed, 06/05/2019 - 15:00
Categories: Drupal

Exclusiv Access

New Drupal Modules - 5 June 2019 - 7:28am
About

This module provide a light access control solution.

There is not a "global access control" or a "access security solution" but a "content-by-content" solution

Categories: Drupal

Drudesk: Simple ways to rewrite the output of Drupal 8 Views fields

Planet Drupal - 5 June 2019 - 6:34am

The unique Drupal Views module allows you to pull the data from the database and display it in any way you wish. As an example, we discussed creating photo galleries with Drupal 8 Views. Drupal’s flexibility is unlimited, so it offers additional ways to customize the content display and meet the customer’s precise requirements. One of them is to rewrite the output of Drupal Views fields. Let’s explore it a little bit in the simplest of cases.

Categories: Drupal

Language switcher enhanced

New Drupal Modules - 5 June 2019 - 3:54am
Categories: Drupal

Morpht: Debugging Guzzle HTTP request errors in Drupal

Planet Drupal - 5 June 2019 - 3:24am

Guzzle makes HTTP requests easy. When they work, it's like magic. However, as with all coding, getting something to work requires debugging, and this is where the Drupal implementation of Guzzle has a major usability problem - any returned messages are truncated, meaning that with the default settings, error messages that can help debug an issue are not accessible to the developer. This article will show developers how they can re-structure their Guzzle queries to log the full error to the Drupal log, instead of a truncated error that does not help fix the issue.

Standard Methodology

Generally, when making a Guzzle request, it is made using a try/catch paradigm, so that the site does not crash in the case of an error. When not using try/catch, a Guzzle error will result in a WSOD, which is as bad as it gets for usability. So let's take a look at an example of how Guzzle would request a page using a standard try/catch:

try {
  $client = \Drupal::httpClient();
  $result = $client->request('GET', 'https://www.google.com');
}
catch (\Exception $error) {
  $logger = \Drupal::logger('HTTP Client error');
  $logger->error($error->getMessage());
}

This code will request the results of www.google.com, and place them in the $result variable. In the case that the request failed for some reason, the system logs the result of $error->getMessage() to the Drupal log.

The problem, as mentioned in the intro, is that the value returned from $error->getMessage() contains a truncated version of the response returned from the remote website. If the developer is lucky, the text shown will contain enough information to debug the problem, but rarely is that the case. Often the error message will look something along the lines of:

Client error: `POST https://exaxmple.com/3.0/users` resulted in a `400 Bad Request` response: {"type":"http://developer.example.com/documentation/guides/error-glossary/","title":"Invalid Resource","stat (truncated...)

As can be seen, the full response is not shown. The actual details of the problem, and any suggestions as to a solution are not able to be seen. What we want to happen is that the full response details are logged, so we can get some accurate information as to what happened with the request.

Debugging Guzzle Errors

In the code shown above, we used the catch statement to catch \Exception. Generally developers will create a class that extends \Exception, allowing users to catch specific errors, finally catching \Exception as a generic default fallback.

When Guzzle hits an error, it throws the exception GuzzleHttp\Exception\GuzzleException. This allows us to catch this exception first to create our own log that contains the full response from the remote server.

We can do this, because GuzzleException provides the response object from the original request, which we can use to get the actual response body the remote server sent with the error. We then log that response body to the Drupal log.

use Drupal\Component\Render\FormattableMarkup;
use GuzzleHttp\Exception\GuzzleException;

try {
  $response = $client->request($method, $endpoint, $options);
}

// First try to catch the GuzzleException. This indicates a failed response from the remote API.
catch (GuzzleException $error) {

  // Get the original response
  $response = $error->getResponse();

  // Get the info returned from the remote server.
  $response_info = $response->getBody()->getContents();

  // Using FormattableMarkup allows for the use of tags, giving a more readable log item.
  $message = new FormattableMarkup('API connection error. Error details are as follows:@response', ['@response' => print_r(json_decode($response_info), TRUE)]);

  // Log the error
  watchdog_exception('Remote API Connection', $error, $message);
}

// A non-Guzzle error occurred. The type of exception is unknown, so a generic log item is created.
catch (\Exception $error) {
  // Log the error.
  watchdog_exception('Remote API Connection', $error, t('An unknown error occurred while trying to connect to the remote API. This is not a Guzzle error, nor an error in the remote API, rather a generic local error ocurred. The reported error was @error', ['@error' => $error->getMessage()));
}

With this code, we have caught the Guzzle exception, and logged the actual content of the response from the remote server to the Drupal log. If the exception thrown was any other kind of exception than GuzzleException, we are catching the generic \Exception class, and logging the given error message.

By logging the response details, our log entry will now look something like this:

Remote API connection error. Error details are as follows:

stdClass Object (
  [title] => Invalid Resource
  [status] => 400
  [detail] => The resource submitted could not be validated. For field-specific details, see the 'errors' array.
  [errors] => Array (
    [0] => stdClass Object (
      [field] => some_field
      [message] => Data presented is not one of the accepted values: 'Something', 'something else', or another thing'
    )
  )
)

* Note that this is just an example, and that each API will give its own response structure.

This is a much more valuable debug message than the original truncated message, which left us understanding that there had been an error, but without the information required to fix it.

Summary

Drupal 8 ships with Guzzle, an excellent HTTP client for making requests to other servers. However, the standard debugging method doesn't provide a helpful log message from Guzzle. This article shows how to catch Guzzle errors, so that the full response can be logged, making debugging of connection to remote servers and APIs much easier.

Happy Drupaling!

Image credit: Marco Verch https://www.flickr.com/photos/30478819@N08/35337269544
Categories: Drupal

Active Directory Integration / LDAP Integration - NTLM & Kerberos Login

New Drupal Modules - 5 June 2019 - 2:24am

Active Directory Integration / LDAP Integration for Intranet sites plugin provides login to Drupal using credentials stored in your LDAP Server . It allows users to authenticate against various LDAP implementations like Microsoft Active Directory , OpenLDAP and other directory systems as well as perform authentication using NTLM and Kerberos. We support user management features such as creating users not present in Drupal from LDAP Server, adding users, editing users and so on. User information is in sync with the information in LDAP.

Categories: Drupal

Traffic Light Rating

New Drupal Modules - 5 June 2019 - 2:20am

Provides a field type for the traffic light rating system which displays information on the fat, saturated fat, sugar and salt content of food and drink products. For more information on the Traffic Light Rating system visit: https://en.wikipedia.org/wiki/Traffic_light_rating_system

Categories: Drupal

Agiledrop.com Blog: Our blog posts from May 2019

Planet Drupal - 5 June 2019 - 1:47am

We’ve prepared a short overview of the blog posts we wrote in May. Give it a read and check out what we had to say.

READ MORE
Categories: Drupal

Commerce Atos SIPS

New Drupal Modules - 5 June 2019 - 1:05am

This module provides support for Atos SIPS payment gateway.

Categories: Drupal

Neibers

New Drupal Modules - 4 June 2019 - 8:04pm

Reconstruct from Neibrs
重新构造Neibrs
# Get the code
1. composer
> composer require drupal/neibers
2. download the code to modules directory
> wget 'https://ftp.drupal.org/files/projects/neibers-8.x-1.0.tar.gz'

Categories: Drupal

BADCamp 2019: Amalgamate with us in the fall!!

Planet Drupal - 4 June 2019 - 2:53pm
Amalgamate with us in the fall!! volkswagenchick Tue, 06/04/2019 - 21:53
Categories: Drupal

Programmatically - Examples and code snippets

New Drupal Modules - 4 June 2019 - 2:10pm

Tired of always typing the same things in your search engine?

Looking for example of how to programmatically do things in Drupal?

This module is made for you :)

Purpose

It's a collection of helpful example for developers meant to improve productivity while coding. You'll no longer need to get out of your code editor to find a code snippet.

It includes this kind of answer/example:

Categories: Drupal

Webform Edit Element

New Drupal Modules - 4 June 2019 - 12:02pm

Simple module for embedding a webform submission edit form as a render element. Webform has this functionality built in for Webform creation forms, but I did not see a way to do it for editing a submission.

Usage:
($sid is the webform submission id)

$form['webform_editor']=[ '#type' => 'webform_edit', '#sid'=>$sid, ];
Categories: Drupal

BNL e-POSitivity Payment Gateways

New Drupal Modules - 4 June 2019 - 11:36am
About this Module

Epositivity is a module that allows payments to be made through the BNL e-POSitivity gateway.

From any webform it is possible to redirect the user to the payment gateway.

Categories: Drupal

CSS Container

New Drupal Modules - 4 June 2019 - 9:25am

This project was built simply to make it easier to apply css container to each page

I didn't see a way to do this yet so I built it really quick

for example

if the path is the front page it would add the css class "URL_node" to the body classes

if the path was "/contactUs/at/this/place" it would add the path "URL_contactUs_at_this_place"

There is no configuration
Just enable and it exists

Categories: Drupal

Phase2: The Last Great Migration: Why Drupal 8 is in a Class of Its Own

Planet Drupal - 4 June 2019 - 8:45am

Historically, migrating your content management system (CMS) or content platform from one major version of Drupal to the next was nothing short of a Herculean task.

Every new version of Drupal meant rebuilding existing functionality, converting (or migrating) your content, and accepting significant changes along the way. Because of this, it’s become commonplace to see stakeholders want to leapfrog Drupal versions (e.g., 5 to 7, or 6 to 8), to extend the life of both their old and new platforms for as long as possible for the least amount of transitional pain.

Categories: Drupal

Hook 42: Switching Themes For Progressive Enhancements

Planet Drupal - 4 June 2019 - 8:40am
Switching Themes For Progressive Enhancements Adam Bergstein Tue, 06/04/2019 - 15:40
Categories: Drupal

Palantir: Learning Design Thinking by Doing: How to Craft a Design Workshop

Planet Drupal - 4 June 2019 - 8:39am
Learning Design Thinking by Doing: How to Craft a Design Workshop Monday, June 17, 2019 brandt Tue, 06/04/2019 - 10:39 WeWork, 111 W Illinois Street, Chicago, IL Chicago IA/UX Meetup (official site)

Facilitating design workshops with key stakeholders allows them to have insight into the process of "how the sausage is made" and provides the product team buy-in from the get-go.

Join Palantir's Director of UX Operations, Lesley Guthrie, for a session on design workshops. She'll go over:

  • How to choose the right exercises 
  • How to play to the team skill sets
  • Ways to adjust the workshop to fit the needs of the project 

You'll learn how to sell it the idea of the design workshop to stakeholders and collaborate with them on a solution that can be tested and validated with real users.

Tue, 06/04/2019 - 12:00
Categories: Drupal

Admin Toolbar Language Switcher

New Drupal Modules - 4 June 2019 - 7:08am

Add the Toolbar Language Switcher to administration toolbar of the project.
This is helpful to easily visualize the current page language context and the handy navigation to change it.

Categories: Drupal

Pages

Subscribe to As If Productions aggregator - Drupal