Planet Drupal

Subscribe to Planet Drupal feed
Drupal.org - aggregated feeds in category Planet Drupal
Updated: 8 hours 41 min ago

Web Wash: How to Build Custom Pages Using Page Manager and Panels in Drupal 8

9 January 2017 - 10:00am
Panels has always been my go-to module when it comes to building custom pages in Drupal 7. Now in Drupal 8 things have changed. A lot of what Panels did in Drupal 7 has been moved over to Page Manager. Panels itself doesn't offer a user interface and it is just a variant type in Drupal 8. Also, Page Manager is now its own project, whereas, in Drupal 7 it was part of the Ctools module. Panels in Drupal 8 integrates with Page Manager and offers a custom variant type which allows you to select different layouts and manage blocks in the layouts. On its own, Panels doesn't really do anything, you need something like Page Manager to utilize it. So with that being said, what can Page Manager do?
Categories: Drupal

Annertech: Mapping in Drupal 8 with GeoLocation Field

9 January 2017 - 9:06am
Mapping in Drupal 8 with GeoLocation Field

Adding a map to a website in Drupal 7 is fairly easy - the only difficulty being which of the many mapping modules to use. In Drupal 8 many of the modules are not available yet, or only have dev or beta versions available. One of the ones that seems fairly stable and has a good set of features without being overly complex is the Geolocation Field module. We've used it on a site recently with great success, and in this blog post we will cover the fundamentals of how to use this module.

Categories: Drupal

Acquia Developer Center Blog: "Media Essentials" Begins Its Journey to Drupal Core

9 January 2017 - 7:26am

Last month, eight companies collaborated in Berlin to bring media to Drupal core during a week-long code sprint. The work done was part of the Media Initiative, which is an effort to support advanced media use cases in Drupal core. This encompasses many features including external embeds from YouTube and Twitter, native video support, and an interface to re-use and manage media assets.

Tags: acquia drupal planet
Categories: Drupal

CiviCRM Blog: The quest for performance improvements - 4th sprint

9 January 2017 - 6:13am

Last week we had a fourth sprint to improve CiviCRM performance at the socialist party. 

During this sprint we started with looking at why the screen for adding and editing memberships loaded slow. The issue reported was that it took some time before the end date field jumped from the right side of the screen to the middle of the screen. It turned out that as long as the field was displayed at the right side the screen was still loading.  Timing this gave a time of about 18 seconds before the screen was fully loaded.

We discovered a few causes:

  • The javascript files which the browser had to download are over 2MB in size
  • Every request in CiviCRM was also logged in Google Analytics and in Piwik.
  • The PHP function getGroupsHierarchy in CRM/Contact/BAO/Group.php took around 900ms to execute (see the issue: https://issues.civicrm.org/jira/browse/CRM-19831)
  • On that same screen the custom fields are retrieved with an AJAX request and in each request all contributions linked to the membership are also retrieved.

The getGroupsHierarchy function is performing slow because it needed to loop three times through all groups in the database in this case there are around 2.687 groups. In addition one of the loops uses the php function array_merge to merge the result of the loop. The array_merge function is known for performing slow when an array contains more than 40 elements.

After rewriting the function we reduced the execution time from 900ms to 20ms.  At https://github.com/civicrm/civicrm-core/pull/9633/files you can find the patch of the rewritten code.  In that patch we use for loops and not foreach as we discovered that a for loop is performing a lot faster than a foreach. If we replace the for to a foreach the total time of execution of that function will drop to 2.360 ms a factor of 100 slower.

We have also turned off Google Analytics and Piwik for CiviCRM pages as there is no need for this. Nobody really knew why it was turned on in the first place.

After fixing the getGroupsHierarchy function we reduced the total loading time in the browser from 18  seconds to 10 seconds. Which is still slow!

Read the previous blog posts:

Drupal
Categories: Drupal

MD Systems blog: Current status of Media in Drupal 8 core and next steps

9 January 2017 - 12:44am
The Media team finished the exciting and successful year 2016 with a Drupal 8 core media sprint in Berlin and we were part of it. Now, what are the next steps?
Categories: Drupal

Web Omelette: Choose your theme dynamically in Drupal 8 with theme negotiation

9 January 2017 - 12:00am

Have you ever needed to render certain pages (or groups of pages) with a different theme than the default one configured for the site? I did. And in this article I'm going to show you how it's done in Drupal 8. And like usual, I will illustrate the technique using a simple use case.

The requirement

Let's say we have a second theme on our site called gianduja since we just love the chocolate from Torino so much. And we want to apply this theme to a few custom routes (the content rendered by the respective controllers is not so important for this article). How would we go about implementing this in a custom module called Gianduja?

The solution

First, we need a route option to distinguish these routes as needing a different theme. We can call this option _custom_theme and its value can be the machine name of the theme we want to render with it. This is how a route using this option would look like:

gianduja.info: path: '/gianduja/info' defaults: _controller: '\Drupal\gianduja\Controller\GiandujaController::info' _title: 'About Gianduja' requirements: _permission: 'access content' options: _custom_theme: 'gianduja'

Just a simple route for our first info page. You can see our custom option at the bottom which indicates the theme this route should use to render its content in. The Controller implementation is outside the scope of this article.

However, just adding an option there won't actually do anything. We need to implement a ThemeNegoatiator that looks at the routes as they are requested and switches the theme if needed. We do this by creating a tagged service.

So let's create a simple class for this service inside the src/Theme folder (directory/namespace not so important):

namespace Drupal\gianduja\Theme; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Theme\ThemeNegotiatorInterface; /** * Our Gianduja Theme Negotiator */ class ThemeNegotiator implements ThemeNegotiatorInterface { /** * {@inheritdoc} */ public function applies(RouteMatchInterface $route_match) { $route = $route_match->getRouteObject(); if (!$route instanceof Route) { return FALSE; } $option = $route->getOption('_custom_theme'); if (!$option) { return FALSE; } return $option == 'gianduja'; } /** * {@inheritdoc} */ public function determineActiveTheme(RouteMatchInterface $route_match) { return 'gianduja'; } }

As you can see, all we need to do is implement the ThemeNegotiatorInterface which comes with two methods. The first, applies(), is the most important. It is run on each route to determine if this negotiator provides the theme for it. So in our example we examine the Route object and see if it has the option we set in our route. The second, determineActiveTheme() is responsible for providing the theme name to be used in case applies() has returned TRUE for this route. So here we just return our theme name. All pretty straightforward.

Lastly though, we need to register this class as a service in our gianduja.services.yml file:

services: theme.negotiator.gianduja: class: Drupal\gianduja\Theme\ThemeNegotiator tags: - { name: theme_negotiator, priority: -50 }

This is a normal definition of a service, except for the fact that we are applying the theme_negotiator tag to it to inform the relevant container compiler pass that we are talking about a theme negotiator instance. Additionally, we are also setting a priority for it so that it runs early on in the theme negotiation process.

And that is pretty much it. Clearing the cache and hitting our new route should use the gianduja theme if one exists and is enabled.

Using this example, we can create more complex scenarios as well. For one, the theme negotiator class can receive services from the container if we just name them in the service definition. Using these we can then run complex logics to determine whether and which theme should be used on a certain route. For example, we can look at a canonical route of an entity and render it with a different theme if it has a certain taxonomy tag applied to it. There is quite a lot of flexibility here.

Categories: Drupal

Platform.sh: 2016, The Year We Won PHP

8 January 2017 - 5:00pm

First, a joyous and productive 2017 to you all. 2016 was really great for us as a growing company and the new year is a great time to look back and share with you, our dear clients and community, our journey.

The title of the post is audacious, very possibly a hyperbole. There are bigger players than us out there. We don’t claim the highest market share. We claim we have become an obvious choice for ambitious projects. Let me make the case.

Over the course of last year, the leading vendors in the PHP enterprise space Magento, eZ Platform, Typo3, and most recently Symfony - the PHP framework of frameworks - announced their cloud platform to be on Platform.sh. Since its inception two and a half years ago, Platform.sh has already become a leader in the whole PHP space. How did this come about?

Categories: Drupal

jordanpagewhite: Drupal 8 Front-End Architecture

8 January 2017 - 4:00pm

I recently read Front-End Architecture for Design Systems by Micah Godbolt (BK1). It is a fantastic evaluation of front-end architecture and strategy. The book isn’t specifically for Drupal developers, but the concepts laid out in the book are relevant to all front-end developers and they are easily applicable to Drupal 8 projects. In this post, I want to build a couple of components and discuss different front-end architecture approaches for Drupal 8 projects, specifically using the concepts in Godbolt’s book.

Categories: Drupal

jordanpagewhite: Add region modifier class to menu

8 January 2017 - 4:00pm

I asked this in the DrupalTwig slack channel a couple days ago:

Categories: Drupal

Pages