Drupal

Picture Media

New Drupal Modules - 23 October 2018 - 1:03am

This modules implements missing integrations between Picture and Media modules. It implements following features:

  • Track entities (including nodes) that has embedded images using wysiwyg editors and those images use file displays using picture formatter with lazy loading enabled. It then loads lazysizes library to ensure lazy loading works even on cached pages.
Categories: Drupal

Bay Area Drupal Camp: Holy moly, BADCamp kicks off on Wednesday!!

Planet Drupal - 23 October 2018 - 12:09am
Holy moly, BADCamp kicks off on Wednesday!! Drupal Planet rob.thorne Tue, 10/23/2018 - 07:09

We are looking forward to seeing you and are excited to share some last minute logistical details and tips for making the most of your time at BADCamp.

But wait: I’m still looking for a hotel room. Anything left??

Hotels are pretty booked in Berkeley but we checked with The Graduate and they still have some rooms left.

Give their reservation number a call at (510) 845-8981 and you’ll stay with at least 50 fellow BADCampers!

Where is everything? Where do I go?
  • Check out the Event Timeline to find out what is happening when.

  • Check out the Venues page to see what is happening where.

Where do I go to pick up my badge & register?

Central BADCamp registration opens at 8:30 am each morning on the 3rd Floor of the MLK Student Union Building.

If you are attending the Nonprofit or Backdrop Summit, badges will be available at the Marsh so no need to stop by central registration in the morning. Be sure to come by the main BADCamp space at lunch break or after your summit to say hi!

Map to Marsh Art Center

2120 Allston Way
Berkeley, CA 94704

What’s the 411 on food and beverage?

As always, BADCamp will provide an endless supply of coffee, tea and water.

Wednesday & Thursday
  • All Trainings & Summits will have light snacks in the morning.

  • For lunch, head outside to discover some of Berkeley’s best food!

  • Stop by the Sponsor Expo on Thursday for speciality coffees.

Parking

Parking at Berkeley can be extremely challenging. Consider taking public transportation whenever possible.  

Anything else to know?
  • Wear good shoes! You will do a lot of walking.

  • Bring layers, or donate at the $100 level and you’ll get an awesome 2018 t-shirt, cool BADCamp socks, and a cozy BADCamp hoodie!

  • The BADCamp Contribution Lounge is open all 4 days of camp from 9:30am! We welcome and encourage you to participate!  See the link for the location.

  • Did we mention the outside activities? At night?
    Bring something warm and maybe even a hat and gloves for the night time activities!

We need your help!

BADCamp is 100% volunteer driven and we need your hands! We need stout hearts to volunteer and help set up, tear down, give directions and so much more!  If you are local and can help us, please sign up on our Volunteer Form.  

Our biggest needs:
  1. Registration Volunteers

  2. Session Monitors (sign up for ones you are already in!)

  3. Trainings (sign up for ones you are already in!)

  4. Higher Ed Summit

 

Sponsors

A BIG thanks Platform.sh, Pantheon & DDEV and all our sponsors who have committed early. Without them this magical event wouldn’t be possible. We are also looking for MORE sponsors to help keep BADCamp free and awesome. Interested in sponsoring BADCamp? Contact matt@badcamp.net or anne@badcamp.net.

Would you have been willing to pay for your ticket?  If so, then you can give back to the camp by purchasing an individual sponsorship at the level most comfortable for you. As our thanks, we will be handing out some awesome BADCamp swag as our thanks.

    See You At BADCamp!!
Categories: Drupal

OSTraining: How to Import Data from CSV Files to Drupal with Content Import

Planet Drupal - 22 October 2018 - 10:29pm

Sometimes you may need to import data from a CSV file into Drupal.

We've spoken with OSTraining users who need to import from another CMS, and uses who need to import from a business spreadsheet.

There is no easy way do this import using the Drupal 8 core. To import your data from a CSV file, you need to install and enable the Content Import module.

In this tutorial, I'll walk you through the process of importing data with Content Import.

Categories: Drupal

Acquia's new European headquarters

Dries Buytaert - 22 October 2018 - 7:08pm

While Acquia's global headquarters are in Boston, we have fourteen offices all over the world. Last week, we moved our European headquarters to a larger space in Reading, UK. We've been steadily growing in Europe, and the new Reading office now offers room for 120 employees. It's an exciting move. Here are a few photos:

Categories: Drupal

Local Translation

New Drupal Modules - 22 October 2018 - 6:22pm
Categories: Drupal

PeerTube

New Drupal Modules - 22 October 2018 - 2:40pm

This module allows you to add PeerTube videos as Remote videos from the media module in drupal core.

Categories: Drupal

Drupal Commerce: What's new in the Commerce 2.10 release?

Planet Drupal - 22 October 2018 - 9:49am

We made many important improvements to Drupal Commerce over the summer, including an improved promotions UI, BOGO offers, and product category conditions in the 2.8 release and full list price support with the 2.9 release. After a long sprint to the finish, we’ve now finally released 2.10, one of our largest releases to date that resolves 39 issues and feature requests.

Product administration improvements

Six years ago we released the first stable version of Commerce Kickstart 2.x and the new (at the time) Inline Entity Form module, which allowed us to manage multiple product variations from a single product page form for the first time. Since then, Inline Entity Form has become a popular Drupal module and a recommended way to manage products in Drupal 7. When we started developing Commerce 2.x for Drupal 8, we ported over Inline Entity Form and the previous approach to managing products, but now we’re ready to take another step forward to advance the usability and performance of product management.

As of the 2.10 release, product variations are managed on their own tab of the product page form. This follows the same UI pattern we established for coupons within the promotions UI.

Moving variations to their own tab allows us to extend the UI in future releases, specifically to add bulk operations for tasks such as price updates, image replacement, and even the creation of a full set of variations. We foresee other modules adding their own elements to the tab, like the Commerce Pricelist module adding a “Prices” dropbutton item to provide quick access to every price for a variation on multiple price lists.

Having variations on a separate tab would be a bit much for products that always only have a single variation, so we’ve made sure to accommodate that use case in the new version. Each product type’s settings form includes an “Allow each product to have multiple variations.” option that when disabled reverts to the inline editing experience for products of that type.

Query access filtering

If you create a new role for your merchant and only give it the “Book: View products” permission, you’d expect users with that role to be able to book products but no others. In Drupal 7, our solution for this was a generic query access API in Drupal Commerce itself that filtered entity loading queries based on user permissions.

To achieve this same result in Drupal 8, we've rebuilt this API and added it to the recent 8.x-1.0-rc1 release of the Entity API module. Commerce is now using it for administrative listings of products, orders, and stores. The API adds a QueryAccessEvent to allow modules to alter the access conditions, making it possible to apply further filtering (e.g. only show the user’s own store). Next we will extend the filtering to Search API to filter customer facing listings.

User-driven API improvements

Over 4,000 websites have launched on Commerce 2.x in the past year, pushing us up over 6,000 in total. As developers launch their projects, we keep our lines of communication open to hear about all the things that annoyed or hindered them, and we work to improve our APIs as a result. Several examples that made it into this release include:

(Note that as a result of the last two, if you have overridden the PaymentInformation or PaymentProcess panes on your site, you will need to update them for the new release.)

We love to hear stories of the great things you’re doing with Drupal Commerce, and we’d also love to improve the core APIs and data model to better support you, too. Feel free to join us and hundreds of other developers in the #commerce channel on Drupal Slack for real-time discussion or post your proposals directly to the issue queue for discussion.

Categories: Drupal

Nextide Blog: Maestro Use Case: Nextide Assists NASA’s Jet Propulsion Laboratory

Planet Drupal - 22 October 2018 - 9:34am
NASA’s Jet Propulsion Laboratory (JPL) needed to automate an internal document approval process where any given launch of the workflow could: Have unique and a varying number of approvers. Abort the approval process immediately upon a single approver rejecting, even if other approvers have approved or have yet to view the document. Re-route rejected documents to the initiator of the approval process. Upon all assigned approvers approving the document, route the document to completion, notifying stakeholders in the process. Using Drupal and Nextide’s Maestro workflow module, JPL was able to prototype a base workflow template to automate their process. However, the missing element was the ability to implement a workflow that allows for on-the-fly selection of approvers, the number of approvers and managing the acceptance and rejection of the document.
Categories: Drupal

Moderation state columns

New Drupal Modules - 22 October 2018 - 8:46am

Provides a views style plugin that groups entities by content moderation state and displays in columns.

WORK IN PROGRESS. Usage at this point is discouraged unless you want to take part in the development.

Categories: Drupal

Aten Design Group: Decoupled Drupal + Gatsby: Getting Started

Planet Drupal - 22 October 2018 - 6:53am

Lately, we've been using Gatsby with Drupal for projects where we need it decoupled.

Gatsby is a unique project. It's most often evaluated as a static site generator compared to the likes of Jekyll and Hugo. While Gatsby can generate a static website, it's more accurately described as a content mesh.

Gatsby uses GraphQL to pull in one or more sources to generate site content. There is a large list of Gatsby source plugins including: Drupal, WordPress, YouTube, Twitter, Hubspot, Shopify and Google Sheets just to name a few. It's optimized for blazing fast performance. Since it's built using React, it can be used to build hybrid sites. Along with generating static pages it can also render client-side content. It can pull in dynamic data, add password protected content and take advantage of features typically not found in static generated sites.

Similar to Drupal, Gatsby is open source. It has a devoted and ever-growing community, with an expanding plug-in library which makes building your site even easier.

With this combination we can leverage Drupal as a content authoring platform and utilize Gatsby to render the frontend.

The screencasts below show how quickly you can configure a Drupal 8 website to pair with Gatsby.

With our Drupal 8 website set up, the next step is to configure Gatsby to pull the Drupal site's content.

In my next blog, I'll be covering how automate your Drupal to Gatsby content deployment to Netlify.

Download a Transcription of this Screencast

Download Transcription

Categories: Drupal

Agiledrop.com Blog: Janne Kalliola: Organising CEO dinners, Drupal Business surveys and local and regional DrupalCamps

Planet Drupal - 22 October 2018 - 6:53am

This week we talked with Janne Kalliola. Janne does not code, but he is a very active Drupal community contributor. Learn about CEO dinners he helps organize and what would he be working on, if he had an extra day between Thursday and Friday.

READ MORE
Categories: Drupal

WebPush

New Drupal Modules - 22 October 2018 - 5:08am

Drupal integration of PHP WebPush library https://github.com/web-push-libs/web-push-php

Categories: Drupal

Sooper Drupal Themes: 9 Drupal Websites that Change the World

Planet Drupal - 22 October 2018 - 2:33am

In today's article we are going to take a look at 9 of the best Drupal websites that have a big impact on changing the world, working to make it better place for everyone.

Drupal is the number one open source platform for web content management among global enterprises, governments, higher education institutes, and NGOs. It is an open source content management system (CMS) that enables complex websites to offer a large amount of information without having to compromise speed or utility. Drupal's standard features like easy content authoring, reliable performance and excellent security represent some of its biggest assets that together make it the CMS of choice for big enterprises and NGOs. Nowadays, more than 1 million websites worldwide use Drupal to combine great design with power, speed and security that the CMS provides.
 

1. NASA

Our knowledge of Space and what lies beyond our planet’s limits would be very limited without NASA. In between landing people on the Moon and studying every planet in our Solar System NASA also spends their time towards improving our daily lives, for example in health, medicine, transportation, public safety, consumer products, computer technology, environmental and agricultural resources, and industrial activity. Moreover, the technologies developed for their space missions eventually end up having huge benefits for humanity, for example the CMOS sensor built in the ‘90s to take pictures of our planet from space, enables today’s smartphone camera, high definition videos and shaped social media as we know it. NASA also has a dedicated research program called NASA Earth Science, whose main objective is to develop a scientific understanding of the Earth system and its response to natural and human-induced changes to enable improved prediction of climate, weather, and natural hazards for present and future generations.

2. Tesla

What does a car company have to do with changing the world? Tesla, founded in 2003, has continuously revolutionized the way people look at sustainable energy, focusing on infinitely scalable clean energy generation and storage products. In order to achieve its goal, Tesla manufactures a unique set of energy solutions, Powerwall, Powerpack and Solar Roof, enabling homeowners, businesses, and utilities to manage renewable energy generation, storage, and consumption. In addition, they have also developed the Gigafactory 1: a facility designed to significantly reduce battery cell costs. 
With Tesla building its most affordable car yet, Model 3, the company continues to make products accessible and affordable to more people, ultimately accelerating the arrival of clean transport and clean energy production. 
All their amazing product pages, company information, and add-on components like the forum and job board are put together in a minimalist but feature-rich Drupal website.

3. Rainforest Alliance 

The Rainforest Alliance is an international non-governmental organization whose mission is to conserve biodiversity and promote sustainable living by transforming land-use practices, business practices, and consumer behavior. Currently the NGO works with rural communities in 76 countries around the world to conserve forests, support sustainable livelihoods, and restore balance to the planet.  
In order to achieve its goals, The Rainforest Alliance has distinguished 5 issues they are focusing on:

  1. Forests - helped prevent deforestation of nearly 4.4 million hectares in high-risk landscapes and forest frontiers.
  2. Food & Farming - the organization trains farmers in some of the world's most vulnerable landscapes to farm in a way that boost crop yields, conserves forests, protects streams and rivers, and nurtures soil health.
  3. Wildlife - trained more than 1 million farmers in methods that boost the productivity of the land and prevents agricultural expansion and destruction of vital forest habitat.
  4. Climate - working towards advancing sustainable economic development through promoting climate-smart land management, greenhouse gas mitigation policies, and support national governments' participation in climate policies and frameworks.
  5. People - adopted concrete strategies to support the environmental, economic, and social health of rural communities around the world. 

The Rainforest Alliance currently runs Drupal 8 on their main site, and Drupal 7 on the business site. Its smart, simple and beautiful layout with a focus on structured data makes for an easy navigation and accessible information for the site visitors.

4. Doctors without Borders


Doctors without Borders, or Médecins Sans Frontières (MSF) was officially founded in December 1971. At the time the organization consisted of 300 volunteers: doctors, nurses, and other staff, including 13 founding doctors and journalists. Over the years, MSF has grown to be an independent, global movement providing medical aid where it's needed most, implementing the right to medical care regardless of gender, race, religion, creed, or political affiliation. 
To assure their global presence and respond as fast as possible to the emergencies, Doctors without Borders has 21 offices located all over the world, followed by offices in Geneva and two United Nations liaison offices. Up and ready for every situation, MSF makes sure to have the necessary resources in order at all time, such as:

  • Pre-packed disaster - kits ready for transportation within hours
  • Supply centers across the globe - four logistical centers based in Europe and East Africa plus stores of emergency materials in Central America and East Asia
  • Cost-reducing logistics - a dedicated staff who negotiates with appropriate officials to insure the import taxes on medication are correct and material delivered as quickly as possible

Currently MSF employs more than 30,000 people across the world and has treaded over a hundred million patients - with 8.25 million outpatient consultations being carried out in 2014 alone. In 1999, Doctors without Borders was awarded a Nobel Prize for World Peace in recognition of the organization's pioneering humanitarian work on several continents.
The MSF site is a prime example of a complex website that embraces the power of Drupal. Strong multisite capabilities, proven track record of handling high traffic and its flexibility were few of the reasons Drupal was chosen as their website CMS. 

5. International Committee of the Red Cross

The International Commitee of the Red Cross, or ICRC, is an independent, neutral organization providing humanitarian protection and assistance for victims of armed conflict and other situations of violence. The ICRC also fights to prevent suffering by promoting and strengthening humanitarian law and universal humanitarian principles. Established in 1863, the ICRC is at the origin of Geneva Conventions and the International Red Cross and Red Crescent Movement. Through its activity, the organization addresses a wide variety of global issues such as economic security, restoring family links, water and habitat, access to education, health, sexual violence, forensic science, mine action and building respect for the law. The legal basis of any action undertaken by ICRC stands as follows: 

  • The four Geneva Conventions and Additional Protocol confer on the ICRC a specific mandate to act in the event of international armed conflict. In particular, the ICRC has the right to visit prisoners of war and civilian internees. The Conventions also give the ICRC a broad right of initiative
  • In non-international armed conflicts, the ICRC enjoys a right of humanitarian initiative recognized by the international community and enshrined in Article 3 common to the four Geneva Conventions
  • In the event of internal disturbances and tensions, and in any other situation that warrants humanitarian action, the ICRC also enjoys a right of initiative, which is recognized in the Statutes of the International Red Cross and Red Crescent Movement. Thus, wherever international humanitarian law does not apply, the ICRC may offer its services to governments without that offer constituting interference in the internal affairs of the State concerned

ICRC picked Drupal as their CMS because it provides their team with tools for easy management, large number of features and reliable performance, which makes a site managing easy and provides a great digital experience for the visitors.

6. Rotary

Rotary is a global network of 1.2 million neighbors, friends, leaders, and problem-solvers united by one goal: unite people and take action to create a lasting, meaningful change. It is a non-political and non-sectarian organization open to anyone, regardless of their race, color, creed, religion, gender, or political reference. Rotary consists of 34,000+ member clubs worldwide, as well as 1.2 million individuals, known as Rotarians, who all work towards solving important global problems, such as: fighting disease, growing local economies, promoting peace, providing clean water, saving mothers & children and support education. 
The object of Rotary is to encourage and foster the ideal of service as a basis of worthy enterprise and, in particular, to encourage and foster:

  • The development of acquaintance as an opportunity for service.
  • High ethical standards in business and professions, the recognition of the worthiness of all useful occupations, and the dignifying of each Rotarian's occupation as an opportunity to serve society.
  • The application of the ideal of service in each Rotarian's personal, business, and community life.
  • The advancement of international understanding, goodwill, and peace through a world fellowship of business and professional persons united in the ideal of service.

    Rotary chose Drupal as the primary CMS for their website due to its flexibility and extensibility. The wide variety of modules and distributions assist Rotary with the best web technology solutions for providing, managing and distributing content.

    7. Global Impact | Charity.org

    Global Impact is a non-profit organization based in the United States who works with hundreds of public and private sectors workplace, assisting in campaigns to generate funding for an alliance of more than 100 of the most respected international charities. Some of the affiliated charities include CARE, Doctors without Borders, Heifer International, Save the Children, the U.S. fund for UNICEF and and World Vision. The organization builds partnerships and raises resources that help the world's most vulnerable people. Global Impact focuses on supporting programs related to global issues such as: clean water, disaster relief and resiliency, economic development, education, environmental sustainability, global health and child survival, human trafficking, hunger, malaria, women and girls. Since its founding in 1956, Global Impact generated more than $1.8 billion for people in need. In 2016 alone, the organization raised more than $42 million in total contributions, helping more than 45 corporate and nonprofit partners accomplish their philanthropic goals by providing advisory and and backbone services.

    Currently running Drupal 7, Global Impact's website handles the large amount of information shared on the website with ease, the web pages feel light and the loading times are minimal.

    8. CARE International

    Founded in 1945 in the U.S, CARE is a nonsectarian, impartial, and non-governmental organization who currently works in 79 poor and developing countries, helping people in need to find a better, poverty-free life. Thanks to the years of experience in the industry CARE International recognized that poverty is a direct result of absence of rights, opportunities and assets, due to social exclusion, marginalization and discrimination. Also one of their primary focus is empowering women after realizing that women play a big role in fighting poverty: by empowering women, entire families and communities can be lifted out of poverty. Until 2020, CARE is committed to being a key part in making sure that:

    • 100 million women and girls exercise their rights to sexual, reproductive and maternal health and a life free from violence
    • 30 million women to have greater access to and control over economic resources
    • 20 million people affected by humanitarian crises receive quality, life-saving humanitarian assistance.
    • 50 million poor and vulnerable people increase their food and nutrition security and their resilience to climate change

    The organization is planning to achieve the following by focusing on 3 key roles: providing and transferring expertise (particularly in the areas of women's economic empowerment, humanitarian action, inclusive governance, gender equality and resilience); multiplying impact; and raising funds to achieve CARE's goals. 

      All the information related to the company, its achievements and goals are packed into a flawless website structure, making the best out of the tools that Drupal provides to create a pleasurable experience for the visitors. 

      9. The Chinese University of Hong Kong

      The Chinese University of Hong Kong (CUHK) is a comprehensive research university with a global vision and mission to combine tradition with modernity. To maximize the impact and the benefits it brings to society, CUHK has adopted a 2016-2020 strategic plan to become a world-class university recognized as a centre of excellence for developing cutting-edge research and emerging interdisciplinary strengths that have global impact and significant contributions to society. CUHK focuses on researching four major areas that will address some of the most pressing issues humankind faces:

      1. China Studies - as China takes centre stage in the world's economic, cultural and political arenas, CUHK works towards unovering the opportunities and challenges of China's global development and its impact on the world from the synergistic perspectives of humanities, social science, business and law.
      2. Translational Biomedicine - translate advances in biomedical research for the betterment of physiological, behavioral or psychological health
      3. Information and Automation Technology - develop data science and artificial intelligence into innovative technologies for the benefit of human life
      4. Environment and Sustainability - achieve low carbon and active healthy living with Information and Communication Technologies and integrated environmental and socio-economic sustainability

      Besides using Drupal for running their website, CUHK is also using our product Glazed Builder. While Glazed Builder is not yet used for the main website it is used to quickly design and build faculty sites and special event websites. For example Glazed Builder and Glazed Theme were recently used for rapid deployment of the memorial website of Nobel Prize winner Sir Charles K. Kao. We're honored to have been a part in the honoring of the founding father of broadband internet.

      The mission and dedication towards making the world a better place, as well as the extent these organizations go in order to achieve their goals is both astonishing and inspiring. By using Drupal to communicate and display a colossal amount of information in a way that's accessible and easy to navigate through for the audience, they are also supporting one of the largest open source CMS community - who works together towards improving the digital world.

      Categories: Drupal

      LetsEncrypt

      New Drupal Modules - 22 October 2018 - 12:38am

      LetsEncrypt library wrapper.

      Usage / Использование:

      Settings/demo: /admin/config/system/letsencrypt

      CODE:

      $domain = "example.org"; \Drupal::service('letsencrypt')->sign($domain); \Drupal::service('letsencrypt')->read($domain);
      Categories: Drupal

      Web Omelette: Lazy loaded services in Drupal 8

      Planet Drupal - 22 October 2018 - 12:32am

      Inheriting from Symfony (in principle but not implementation), Drupal 8 allows us to define certain services as lazy. Why? Well why the hell not?!

      Sometimes, our services get big. Not necessarily in the number of things they do (hopefully not) but in the time it takes for them to get instantiated. As you know, when we define a service and make it a dependency of something else, the service container will instantiate that service and inject it where it is needed. And this happens whether on that particular request that service is used or not.

      For example, let’s imagine you have a Controller with 2 public methods used for 2 distinct routes. Most likely, when one method gets hit for the route, the logic of the second one doesn’t run. And even if only the second one depends on an injected service, the latter gets instantiated in both cases regardless.

      Of course, for “popular” services like the EntityTypeManager or form builders this is not a big deal. For one, they are probably going to be instantiated anyway for other parts of the request. And second, they are not expensive to construct. Well, they probably are but anyway, see point 1. However, if we have our custom service as a dependency which is used only for that one route, it doesn’t make sense to have it instantiated for both routes. Especially if it is expensive to do so — heavy on resources. Enter lazy services.

      Lazy services basically “tell” the container:

      Ok, I need to be injected, sure, but unless I’m not used, please don’t construct me… mkay?

      So how does this work in practice? Let’s see an example.

      Assume this service:

      namespace Drupal\module_name; class MyHeavyService implements HeavyServiceInterface { /** * This be slow. */ public function __construct() { sleep(4); } /** * Does something, doesn't matter what. */ public function doSomething() {} }

      A few things to note here:

      • It’s important to have an interface. Without one, this won’t work. You’ll see in a moment why.
      • The constructor does, for some reason, take an expensive nap.
      • It’s not important what the API of the service does.

      For such a service, the normal service definition would look like this:

      module_name.heavy_service: class: Drupal\module_name\MyHeavyService

      If we injecting this into our Controller, any request which uses the latter will instantiate this service as well — which costs us 4 seconds a pop. So to make it lazy we just have this instead:

      module_name.heavy_service: class: Drupal\module_name\MyHeavyService lazy: true

      Lazy services work by way of proxy classes. Meaning that for each service that is declared lazy, the container expects a proxy class which is responsible for decorating the original one and only instantiate it if any of the public APIs are requested. But don’t worry, we don’t have to write another class. We have a PHP script provided by Drupal core that does this for us:

      php core/scripts/generate-proxy-class.php 'Drupal\module_name\MyHeavyService' 'modules/custom/module_name/src'

      The script takes two parameters:

      • The namespace of the service we want to create a proxy for
      • The location where it should be written

      Do note that proxy classes are dumped automatically into a ProxyClass folder located at that specified path. So this is what gets generated for our service at modules/custom/module_name/src/ProxyClass/MyHeavyService.php:

      // @codingStandardsIgnoreFile /** * This file was generated via php core/scripts/generate-proxy-class.php 'Drupal\module_name\MyHeavyService' "modules/custom/module_name/src". */ namespace Drupal\module_name\ProxyClass { /** * Provides a proxy class for \Drupal\module_name\MyHeavyService. * * @see \Drupal\Component\ProxyBuilder */ class MyHeavyService implements \Drupal\module_name\HeavyServiceInterface { use \Drupal\Core\DependencyInjection\DependencySerializationTrait; /** * The id of the original proxied service. * * @var string */ protected $drupalProxyOriginalServiceId; /** * The real proxied service, after it was lazy loaded. * * @var \Drupal\module_name\MyHeavyService */ protected $service; /** * The service container. * * @var \Symfony\Component\DependencyInjection\ContainerInterface */ protected $container; /** * Constructs a ProxyClass Drupal proxy object. * * @param \Symfony\Component\DependencyInjection\ContainerInterface $container * The container. * @param string $drupal_proxy_original_service_id * The service ID of the original service. */ public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $drupal_proxy_original_service_id) { $this->container = $container; $this->drupalProxyOriginalServiceId = $drupal_proxy_original_service_id; } /** * Lazy loads the real service from the container. * * @return object * Returns the constructed real service. */ protected function lazyLoadItself() { if (!isset($this->service)) { $this->service = $this->container->get($this->drupalProxyOriginalServiceId); } return $this->service; } /** * {@inheritdoc} */ public function doSomething() { return $this->lazyLoadItself()->doSomething(); } } }

      As you can see, we have a simple decorator. It implements the same interface and has the same public methods. The latter, however, are derived automatically from the service class and not the interface. And basically, the container is injected and used to instantiate the underlying service the first time any of the public methods are called. If none are called in that request, it won’t get instantiated.

      I mentioned above that having an interface on the service is necessary. The reason is that when we inject it somewhere, we need to type hint the interface. Otherwise, the container would pass an instance of Drupal\module_name\ProxyClass\MyHeavyService which is not the same as the original Drupal\module_name\MyHeavyService.

      So now, we can inject it, type hint it with the interface and it would only get instantiated if any of the public methods are called. Neat no?

      The responsible for making all this happen is the Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass compiler pass. Looking for service definitions that have been marked as lazy, it creates a new identical service definition (non-lazy) which uses the proxy class and adds that to the container instead. It’s actually not rocket science if you look at the code.

      And like many things, just because we have this available, it doesn’t mean we should use it for every service we write. Remember, if you create services used all over the place, this is useless. The criteria for whether to make your service lazy should be:

      • Is it heavy to instantiate (depends on a bunch of other services which in turn are not super popular either)?
      • Is it ever instantiated for no reason?

      Hope this helps.

      Categories: Drupal

      OSTraining: How to Create a Request Contact Form in Drupal 7

      Planet Drupal - 21 October 2018 - 10:02pm

      An OSTraining member has asked us how to create a request form in Drupal 7. They needed to process requests using this workflow:

      1. A customer fills out a form to send their request for repair or service on a specific piece of equipment.
      2. A customer service agent comments on the request to either approve or deny it.
      3. The customer gets an automatic email after his request has been processed.

      In this tutorial, I'll show you how to create a form like this.

      Categories: Drupal

      Paywall

      New Drupal Modules - 21 October 2018 - 5:38pm
      Paywall module has been moved to Github.

      Paywall module allow node author set price to each node, and guide visitors to pay for full access.

      By default, paywall module will hide the second half of content (see screenshot below). But if you want better control of it, you can use [$][/$] tags to define paid/hide areas manually.

      Categories: Drupal

      Views Math

      New Drupal Modules - 20 October 2018 - 9:31pm

      Different mathematical features for views.
      The work is in progress.

      Categories: Drupal

      Drupal Atlanta Medium Publication: How to Add Blocks in Paragraphs for Drupal 8

      Planet Drupal - 20 October 2018 - 8:15pm
      Wouldn’t it be nice if you could add any block you want to your paragraphs?

      In years past, layout for Drupal has been in the hands of front-end developers, but over time various modules were developed that provided site-builders the ability to adjust the layout. An improvement yes, but there still wasn’t a clear cut option that empowered content editors to alter the layout during the editorial process.

      Look out! Here comes the Paragraphs Module. This module has been taking the Drupal community over by storm because it allows content editors to add pre-designed components which gives each page the option to have different layouts. One of the limitations of the Paragraphs module, is that each paragraph can only be used once, and only for the current node you are editing. This means that you can’t re-use a common paragraph such as a call to action block, email signup or contact us form, so you end up finding yourself duplicating a lot of work if you want the same block on numerous pages. While the Drupal community has been working to help solve this problem by allowing the re-use of paragraphs, there are still going to be plenty of situations where you want to insert custom blocks, views, or system blocks such as the site logo or login block.

      How do you allow your site editors to add re-used blocks into their content during the editorial process?

      Let me introduce you to the Block Field Module. Maintained by the one and only Jacob Rockowitz (you know the webform guy ), you can be assured that the code follows best practices and that there will be support. The block field module allows you to reference any block regardless of where it is coming from and the best part, you don’t have to create some hidden region in your theme in order for the blocks to be rendered.

      There are plenty of awesome articles out there that explains how to use paragraphs so I won’t get into that. To follow along with my steps be sure to have downloaded and enabled both the Paragraphs and the Block Field modules.

      Steps to Add Blocks to Paragraphs
      1. Download and Enable the Paragraphs and Block Field modules.
      2. Create a paragraph type called Block Reference (or whatever name you want)
      3. Add a new field, by selecting the Block (plugin) field type from the dropdown and save it.
      4. Go to manage display and make the label hidden.
        I always forget this step and then I scratch my head when I see the Block Ref field label above my views title.
      5. Now go to back to your content type that has the paragraph reference field and ensure the Block Reference paragraph type is correctly enabled.
        The content type with the paragraph reference field was not covered in this tutorial.
      6. When adding or editing your content with a paragraph reference field. Add the Block Reference paragraph type. Select the name of the block that you would like to reference from the dropdown hit save on the content and watch the magic happen.

      In conclusion, it does feel a little scary giving content editors this much freedom so it will be imperative that all views and custom blocks have descriptive names so that editors can clearly identify what blocks to reference. Overall I feel like this is a good solution for referencing existing blocks that can save a lot of time and really unleashes the power of the paragraphs module. The Drupal community continues to amaze me!

      If you are interested in contributing blog post or want to get more involved with the Atlanta Drupal Users Group (ADUG) please feel free to reach out info@drupalatlanta.org

      How to Add Blocks in Paragraphs for Drupal 8 was originally published in Drupal Atlanta on Medium, where people are continuing the conversation by highlighting and responding to this story.

      Categories: Drupal

      Video embed PeerTube

      New Drupal Modules - 20 October 2018 - 5:59pm

      This module provides PeerTube handler for Video Embed Field.
      Users can add PeerTube videos to their site by pasting the video URL into a video embed field.

      Requires:
      Video Embed Field

      Categories: Drupal

      Pages

      Subscribe to As If Productions aggregator - Drupal