browse the blogs

[ 3 Sep 2016 ]

This one’s more interesting than it is useful (or its main use is as a debugging exercise), but while I was working on a UI Component tutorial I wanted to turn off the XSD validation for ui_component files.

It turns out there’s a dedicated object that can control whether the XSD validations are applied ($this->validationState->isValidationRequired() below.

#File: vendor/magento/framework/View/Element/UiComponent/Config/DomMerger.php
public function createDomDocument($xml)
$domDocument = new \DOMDocument();
if ($this->validationState->isValidationRequired() && $this->schema) {
$errors = $this->validateDomDocument($domDocument);
if (count($errors)) {
throw new \Magento\Framework\Exception\LocalizedException(

[ 1 Sep 2016 ]

For folks using pestle, my PHP command line frameworking + Magento code generation tool, I’ve just added a selfupdate command. This will make a backup of your current version, grab the latest version, and update your local copy (permissions allowing, of course)

$ pestle.phar selfupdate
Downloaded to /private/tmp/pestle_DZOXou
Backing up /Users/alanstorm/Documents/github_private/GeneralCode/bin/pestle.phar to /Users/alanstorm/Documents/github_private/GeneralCode/bin/pestle.phar.1472763047
Backed up current pestle to /Users/alanstorm/Documents/github_private/GeneralCode/bin/pestle.phar.1472763047
Reaplced /Users/alanstorm/Documents/github_private/GeneralCode/bin/pestle.phar

Next up along these lines is formalizing the concept of pestle versions and adding some sort of “you haven’t updated in 30 days and there’s a new version” feature.

I don’t have any regrets about setting out to create my own CLI framework, but it really makes me appreciate everything you get “for free” from somethings like Symfony console.

[ 9 Aug 2016 ]

I’m knee deep in a rewrite of No Frills Magento Layout for Magento 2 – I know the systems well enough to use them, but I’m still coming up to speed on the underlying object implementations. This is important, since my approach in No Frills is

Here’s how you’d do this in PHP, here’s how to do the same thing in XML, hey look, all that XML means you don’t need to write PHP

When I was looking at the layout arguments, I was pleased to an xsi:type attribute

<argument name="block" xsi:type="string">integration_edit_tab_info</argument>

In Magento’s di.xml files and the UI Component XML files, these typed nodes usually meant you can sneak an actual object manager object in as an argument using …

[ 8 Aug 2016 ]

Although the technique still works, various members of Magento’s engineering team have discouraged using Magento 1’s <action method="..."/> syntax to call methods on blocks from layout update XML files.

<block ...>
    <action method="addTab">
        <argument name="name" xsi:type="string">info_section</argument>
        <argument name="block" xsi:type="string">integration_edit_tab_info</argument>

Other members of the engineering team have suggested an <arguments/> node as a replacement.

<referenceBlock name="block_name">
        <argument name="field1" xsi:type="string">foo</argument>
        <argument name="field_two" xsi:type="string">bar</argument>

Whenever you see an <argument/> or <arguments/> node in a bit of Magento 2 XML, …

[ 3 Aug 2016 ]

Magento 2 module creator and code generator | Mage2Gen:

Haven’t had a chance to check this out yet, but it looks like another Magento 2 module generation tool. This one seems to be an “everything and the kitchen sink” approach (vs. pestle which lets you build only the parts you need) but that approach does mean you get a fully featured module (whereas pestle requires you to know what a module does before you add the feature).

[ 14 Jul 2016 ]

Can’t Add a new UI Component Type · Issue #5647 · magento/magento2:

An interesting side effect of the new XML schemas – the definition.xml files for UI components have their top nodes locked down, which means developers can’t add their own UI component types.

[ 11 Jul 2016 ]

Formatting Dates in Magento Javascript:

If you’re doing any work in Magento’s RequireJS based javascript modules and see a dateFormat string

defaults: {
    dateFormat: 'MMM d, YYYY h:mm:ss A'

Chances are its a Moment.js date format string.

You can pull in the main moment function via a RequireJS shim

define(['moment'], function(moment){

And the mageUtils RequireJS library (an alias for mage/utils/main) appears to export a normalizeDate function that will convert Magento’s old custom date format into a Moment.js based format.

define(['mageUtils'], function(mageUtils){
    momentFormat = mageUtils.normalizeDate(oldMageFormat);
[ 9 Jul 2016 ]

Demystifying Plugins (MageTitans Italy 2016):

Concise explanation of the code involved in using a Magento 2 Plugin to change core system behavior, with the talk over here if you’re the sort who likes context.

[ 7 Jul 2016 ]

I’ve been digging through Magento’s UI Components this week and hit a stumbling block. The main KnockoutJS template that kicks off rendering (vendor/magento//module-ui/view/base/web/templates/collection.html) looks like this

<each args="data: elems, as: 'element'"><render if="hasTemplate()"></render></each>

This sort of thing is exactly where Magento hits the unsweet spot of being new, and using a technology I’m not super familiar with (KnockoutJS).

I’m pretty sure the HTML5 kids haven’t added there’s an <each></each> or <render></render> tag to HTML.

In my readings through KnockoutJS’s docs I discover that component bindings create custom tags, but some unfruitful searching through Magento’s code doesn’t show any obvious place where this has been done for an each or render tag. Some more digging into KnockoutJS’s implementation let me rule this …

[ 5 Jul 2016 ]

I just updated pestle with a new magento2:generate:ui:grid command. Magento 2.1+ only, not likely to be ported backwards to the 2.0.x branch. A longer article over on is forthcoming, but here’s the quickie version.

Here’s the arguments to use to create a UI Component Listing.

$ pestle.phar magento2:generate:ui:grid
Which Module? (Pulsestorm_Gridexample)] Pulsestorm_ToDoCrud
Create a unique ID for your Listing/Grid! (pulsestorm_gridexample_log)] pulsestorm_todo_listing
What Resource Collection Model should your listing use? (Magento\Cms\Model\ResourceModel\Page\Collection)] Pulsestorm\ToDoCrud\Model\ResourceModel\TodoItem\Collection
What's the ID field for you model? (pulsestorm_gridexample_log_id)] pulsestorm_todocrud_todoitem_id

The above assumes you’ve create a “To Do CRUD Model” by working through the Magento2: CRUD Models for Database Access tutorial, and then created yourself an admin/backend controller endpoint.

The Which Module? argument determines the already create module where pestle will …