browse the blogs

[ 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>
    </action>    
</block>

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

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

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 alanstorm.com 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 …

[ 5 Jul 2016 ]

If you’re following along with Magento 2 development, you’ve probably heard the drum beat that the Model/Resource Model/Collections are old and tired, and the Repository classes are new and wired. While the move towards repositories is is a Good Thing™, a Magento 2 developers still needs to know the old CRUD system, and that CRUD system is likely to remain with us for a long time coming.

I was reminded of this recently as I took some time to dig into some changes in the UI Component feature in Magento 2.1. Most of (all of?) the Grid listings in Magento 2 still rely on collection models.

The pattern is a UI component configuration binds something called a data provider …

[ 5 Jul 2016 ]

How Interceptors are Generated:

TLDR; The object manager appends Interceptor to the class name you asked for if there’s a plugin. Then a second PHP Autoloader will look for Interceptor at the end of a classes name, and if it can’t find a definition via normal means, the autoloader generates the class.