Development News

Roy Scholten: Core strengths

Main Drupal Feed - Mon, 02/05/2018 - 23:28
06 Feb 2018 Core strengths

The Designing Connected Content book has arrived. “Plan and model digital products for today and tomorrow.” I have yet to dive in but I see Drupal screenshots and lists of field types like entity reference, long text (formatted), boolean, number (float), etc.

Today a content strategist collegue asked me about that list builder thing in Drupal. Show items of type x, filtered by y, sorted by x and only show fields 1, 3 and 6 of each item. And is it available for Drupal 8 as well?

Yes, that’s 1. Field UI and 2. Views module, which are both part of the Drupal core package.

We take Drupal core features for granted that other systems are still struggling with. They are also features people struggle with in Drupal because of hard to use user interfaces. I would love to see research and design work happen around how we can improve Field UI and Views UI.

Tags book designing connected content drupalplanet content modeling

WordPress 4.9.3 Maintenance Release

Wordpress News - Mon, 02/05/2018 - 19:47

WordPress 4.9.3 is now available.

This maintenance release fixes 34 bugs in 4.9, including fixes for Customizer changesets, widgets, visual editor, and PHP 7.2 compatibility. For a full list of changes, consult the list of tickets and the changelog.

Download WordPress 4.9.3 or visit Dashboard → Updates and click “Update Now.” Sites that support automatic background updates are already beginning to update automatically.

Thank you to everyone who contributed to WordPress 4.9.3:

Aaron Jorbin, abdullahramzan, Adam Silverstein, Andrea Fercia, andreiglingeanu, Andrew Ozz, Brandon Payton, Chetan Prajapati, coleh, Darko A7, David Cramer, David Herrera, Dion Hulse, Felix Arntz, Frank Klein, Gary Pendergast, Jb Audras, Jeffrey Paul, lizkarkoski, Marius L. J., mattyrob, Monika Rao, munyagu, ndavison, Nick Momrik, Peter Wilson, Rachel Baker, rishishah, Ryan Paul, Sami Ahmed Siddiqui, Sayed Taqui, Sean Hayes, Sergey Biryukov, Shawn Hooper, Stephen Edgar, Sultan Nasir Uddin, tigertech, and Weston Ruter.

Dev Blog: WordPress 4.9.3 Maintenance Release

Wordpress Planet - Mon, 02/05/2018 - 19:47

WordPress 4.9.3 is now available.

This maintenance release fixes 34 bugs in 4.9, including fixes for Customizer changesets, widgets, visual editor, and PHP 7.2 compatibility. For a full list of changes, consult the list of tickets and the changelog.

Download WordPress 4.9.3 or visit Dashboard → Updates and click “Update Now.” Sites that support automatic background updates are already beginning to update automatically.

Thank you to everyone who contributed to WordPress 4.9.3:

Aaron Jorbin, abdullahramzan, Adam Silverstein, Andrea Fercia, andreiglingeanu, Andrew Ozz, Brandon Payton, Chetan Prajapati, coleh, Darko A7, David Cramer, David Herrera, Dion Hulse, Felix Arntz, Frank Klein, Gary Pendergast, Jb Audras, Jeffrey Paul, lizkarkoski, Marius L. J., mattyrob, Monika Rao, munyagu, ndavison, Nick Momrik, Peter Wilson, Rachel Baker, rishishah, Ryan Paul, Sami Ahmed Siddiqui, Sayed Taqui, Sean Hayes, Sergey Biryukov, Shawn Hooper, Stephen Edgar, Sultan Nasir Uddin, tigertech, and Weston Ruter.

Mark Jaquith: Tips for configuring WordPress environments

Wordpress Planet - Mon, 02/05/2018 - 14:59

Many WordPress hosts will give your site a “staging” environment. You can also use tools like Local by Flywheel, or MAMP Pro to run a local “dev” version of your site. These are great ways of testing code changes, playing with new plugins, or making theme tweaks, without risking breaking your live “production” site.

Here is my advice for working with different WordPress environments.

Handling Credentials

The live (“production”) version of your site should be opt-in. That is, your site’s Git repo should not store production credentials in wp-config.php. You don’t want something to happen like when this developer accidentally connected to the production database and destroyed all the company data on his first day.

Instead of keeping database credentials in wp-config.php, have wp-config.php look for a local-config.php file. Replace the section that defines the database credentials with something like this:

if ( file_exists( __DIR__ . '/local-config.php' ) ) {     include( __DIR__ . '/local-config.php' ); } else {     die( 'local-config.php not found' ); }

Make sure you add local-config.php to your .gitignore so that no one commits their local version to the repo.

On production, you’ll create a local-config.php with production credentials. On staging or development environments, you’ll create a local-config.php with the credentials for those environments.

Production is a Choice

Right after the section that calls out local-config.php, put something like this:

if ( ! defined( 'WP_ENVIRONMENT' ) ) { define( 'WP_ENVIRONMENT', 'development' ); }

The idea here is that there will always be a WP_ENVIRONMENT constant available to you that tells you what kind of environment your site is being run in. In production, you will put this in local-config.php along with the database credentials:

define( 'WP_ENVIRONMENT', 'production' );

Now, in your theme, or your custom plugins, or other code, you can do things like this:

if ( 'production' === WP_ENVIRONMENT ) { add_filter( 'option_gravityformsaddon_gravityformsstripe_settings', function( $stripe_settings ) { $stripe_settings['api_mode'] = 'live'; return $stripe_settings; }); } else { add_filter( 'option_gravityformsaddon_gravityformsstripe_settings', function( $stripe_settings ) { $stripe_settings['api_mode'] = 'test'; return $stripe_settings; }); }

This bit of code is for the Easy Digital Downloads Stripe gateway plugin. It makes sure that on the production environment, the payment gateway is always in live mode, and the anywhere else, it is always in test mode. This protects against two very bad situations: connecting to live services from a test environment (which could result in customers being charged for test transactions) and connecting to test services from a live environment (which could prevent customers from purchasing products on your site).

You can also use this pattern to do things like hide Google Analytics on your test sites, or make sure debug plugins are only active on development sites (more on that, in a future post!)

Don’t rely on complicated procedures (“step 34: make sure you go into the Stripe settings and switch the site to test mode on your local test site”) — make these things explicit in code. Make it impossible to screw it up, and working on your sites will become faster and less stressful.

Do you need WordPress services?

Mark runs Covered Web Services which specializes in custom WordPress solutions with focuses on security, speed optimization, plugin development and customization, and complex migrations.

Please reach out to start a conversation!

[contact-form]

Matt: National Magazine Award Nomination

Wordpress Planet - Fri, 02/02/2018 - 21:37

Longreads was nominated today for its first-ever National Magazine Award, in the category of columns and commentary, alongside ESPN The Magazine, BuzzFeed News, Pitchfork, and New York magazine. Laurie Penny's Longreads columns explore important questions of consent and female desire that have strongly resonated in our current moment. In addition to this nomination, Penny's columns have been translated and republished in Italian and German newspapers, and will be collected in a forthcoming book.

Acquia Lightning Blog: Using the Configuration Installer with Lightning

Main Drupal Feed - Fri, 02/02/2018 - 17:07
Using the Configuration Installer with Lightning Adam Balsam Fri, 02/02/2018 - 12:07

Installing a site with existing config has been a bit of a moving target in Drupal 8. At different times, I've recommended at least three different approaches. I won't go into too much detail, but basically we've used the following at times:

  • Manually change site UUIDs (Sloppy)
  • Use --config-dir option with drush site-install (Only supports minimal profile)
  • Use patch from Issue #2788777 (Config needs to be stored in profile directory)

You can read more about previous approaches here. The one thing that hasn't changed is the user story:

As a user I want to be able to install Drupal from a package of configuration that is maintained in git.

The issue that most closely addresses this user story is #1613424 "Allow a site to be installed from existing configuration". That issue is currently postponed on another thorny issue which involves the special way that Drupal treats dependencies of profiles. In the meantime, alexpott has provided a standalone install profile that handles installing a site from existing config. This is the Configuration installer profile.

It takes a minute to wrap your head around the concept because when you use the Configuration installer profile, you don't end up with a site running the Configuration installer profile. At the end of the install, your site will be running the profile that is defined in the config you provided the Config installer.

So for a new project, you would initially install using the profile of your choice. Then, once you have exported your config, you would use the Config installer for subsequent installs.

Considerations
  • For ease of use, your settings file should not be writable by the installer and should not contain the install_profile key. If your settings file contains your profile, you'll get an exception when trying to run the install. And if it is writable, Drupal will write that value every time you do install.
  • The Config installer profile requires two patches in order to work properly with Drush 9.
  • Config must not have direct dependencies on a profile. Lightning 3.0.1 requires the patch in issue #2933445 to be compliant.
Instructions
  1. For new sites, install using the profile or sub-profile of choice.
$ drush site-install lightning
  1. Ensure that the install_profile key is not present in your settings.php file. Drupal will write this value by default, but it is not required in Drupal >= 8.3.0. You can prevent Drupal from writing it by disallowing write access to the settings file. If the installer wrote the profile during initial installation, you can manually delete it. Then revoke write access:
$ chmod 444 docroot/sites/default/settings.php
  1. Define the following patches in your composer.json file if you are using config_installer < 1.6.0 and/or lightning < 3.0.2.
"patches": { "drupal/config_installer": { "2916090 - Support Drush 9": "https://www.drupal.org/files/issues/drush9-support-2916090-6.patch", "2935426 - Drush 9: Call to undefined function drush_generate_password": "https://www.drupal.org/files/issues/config_installer-drush_9_call_undefined_function_drush_generate_password-2935426-2.patch" }, "drupal/lightning_layout": { "2933445 - user.role.layout_manager has dependency on Lightning": "https://www.drupal.org/files/issues/2933445.patch" } },
  1. Add the Configuration installer profile to your codebase.
$ composer require drupal/config_installer
  1. Export your site's configuration.
$ drush config-export
  1. Use the Configuration installer profile in all subsequent site installs. The resulting install will run on the profile used in step 1.
$ drush site-install config_installer

drunken monkey: Some more (updated) tips for PhpStorm live templates

Main Drupal Feed - Fri, 02/02/2018 - 11:19

A few years ago I started using the PhpStorm IDE for PHP development, was immediately smitten and, after a bit of use, wrote a blog post with some tips I found for makig better use of the tools PhpStorm gives you.

In the four years since then there have been some new developments. Firstly, of course, Drupal 8 was finally released – and, consequently, the one complaint I had back in 2013 about the $MODULE$ variable only working in the module file itself became more of a problem. (Also, I added one more live template that's very useful for Drupal 8.)
But secondly, a few weeks ago PhpStorm finally added scripting support for live templates, so it's now possible to write more powerful templates that way – and fix the $MODULE$ variable.

The new di live template

In general, when writing OOP code for Drupal 8 (that is, for almost all Drupal 8 code) you should use dependency injection as much as possible. There's several different styles for doing that, I'm using one which uses setter methods and calls them in create() (instead of adding all injected objects to the constructor). This makes inheritance easier and keeps the constructor “cleaner” – and becomes much easier with a good live template:

  /**
   * The $NAME$.
   *
   * @var $INTERFACE$|null
   */
  protected $$$PROP_NAME$;

  /**
   * Retrieves the $NAME$.
   *
   * @return $INTERFACE$
   *   The $NAME$.
   */
  public function get$UC_PROP_NAME$() {
    $plugin->set$UC_PROP_NAME$($container->get('$SERVICE$'));

    return $this->$PROP_NAME$ ?: \Drupal::service('$SERVICE$');
  }

  /**
   * Sets the $NAME$.
   *
   * @param $INTERFACE$ $$$VAR_NAME$
   *   The new $NAME$.
   *
   * @return $this
   */
  public function set$UC_PROP_NAME$($INTERFACE$ $$$VAR_NAME$) {
    $this->$PROP_NAME$ = $$$VAR_NAME$;
    return $this;
  }

Variable definitions:

Name Expression Skip if defined VAR_NAME N SERVICE N INTERFACE clipboard() Y NAME underscoresToSpaces(VAR_NAME) Y UC_NAME underscoresToCamelCase(VAR_NAME) Y UC_PROP_NAME capitalize(PROP_NAME) Y

Usage:

  1. Copy the service interface's FQN to your clipboard.
  2. Put the service ID either into a secondary clipboard (e.g., middle mouse button on Linux) or remember it.
  3. Execute live template (at the position where you want the getter and setter).
  4. Input variable name (in snake_case), then input service name.
  5. Move the property definition and the create() line (temporarily stored as the first line of the getter in the template) to their appropriate places.
  6. In the code, alway use the getter method for accessing the service.
Fixing the $MODULE$ variable

Since the code for this is quite complex, we better just put it into a separate file. So, first download the script file and save it to some known location, then simply use the (absolute) path to the script file as the argument for groovyScript(), like this:

This can be used for all the live templates that contain a $MODULE$ variable (though it will, of course, be less useful for the procedural ones, than for the simple m template).

Dev Blog: The Month in WordPress: January 2018

Wordpress Planet - Fri, 02/02/2018 - 08:10

Things got off to a gradual start in 2018 with momentum starting to pick up over the course of the month. There were some notable developments in January, including a new point release and work being done on other important areas of the WordPress project.

WordPress 4.9.2 Security and Maintenance Release

On January 16, WordPress 4.9.2 was released to fix an important security issue with the media player, as well as a number of other smaller bugs. This release goes a long way to smoothing out the 4.9 release cycle with the next point release, v4.9.3, due in early February.

To get involved in building WordPress Core, jump into the #core channel in the Making WordPress Slack group, and follow the Core team blog.

Updated Plugin Directory Guidelines

At the end of 2017, the guidelines for the Plugin Directory received a significant update to make them clearer and expanded to address certain situations. This does not necessarily make these guidelines complete, but rather more user-friendly and practical; they govern how developers build plugins for the Plugin Directory, so they need to evolve with the global community that the Directory serves.

If you would like to contribute to these guidelines, you can make a pull request to the GitHub repository or email plugins@wordpress.org. You can also jump into the #pluginreview channel in the Making WordPress Slack group.

Further Reading:

If you have a story we should consider including in the next “Month in WordPress” post, please submit it here.

WPTavern: WordPress 4.9.3 Rescheduled for February 5th

Wordpress Planet - Fri, 02/02/2018 - 08:09

WordPress 4.9.3 is a maintenance release and was originally scheduled to be available on January 30th. However, due to ongoing tickets and a short time frame to test the release candidate, it has been pushed back to February 5th.

WordPress 4.9.3 RC 1 is available for testing. This release removes JSHint from the code editors due to conflicts with the GPL License. If your code relies on JSHint from Core, developers encourage you to update it to use a copy of JSHint.

Other changes in 4.9.3 include, avoiding page scrolling when navigating the media modal, a handful of improvements to the customizer, and more. Please test WordPress 4.9.3 on a staging site and if you encounter any bugs, you can report them on the Alpha/Beta section of the support forums.

Pages