browse the blogs

[ 28 Jun 2016 ]

One of the things Magento 2.1 doesn’t bring to the table is the ability to symlink your modules and other components. It’s hard to tell if this is a deliberate omission, or just something that’s not a priority for the development team and keeps getting lost in the shuffle. If you checkout the Context section of this GitHub bug, you can see Magento’s template validation does still check the allow symlinks setting, but the immediately does another check that could never pass with a module available via a symlink outside the Magento system’s folder structure.

Maddening, but something we can at least work around. If we create a module that has a plugin for the Magento\Framework\View\Element\Template\File\Validator class

pestle.phar ...

[ 28 Jun 2016 ]

This is another one of those 10,000 foot view posts, as much to get my own head straight about something as anything else.

In programming, the term scope usually means

If I’ve defined variable X “here”, where else can I access it?

Magento’s core team have borrowed the term scope to described Magento’s multi-store features.

Websites, Store Groups, and Store Views

Magento allows you to create CRUD objects called “Websites”. A Website is a simple object and has two main pieces of data – a unique alphanumeric code for identification, and a reference to a default “Store Group”.

A “Store Group” is another CRUD object. It is similarly simple, and two two primary pieces of data – a default category ID, and …

[ 20 Jun 2016 ]

How Can I Resolve a RequireJS Alias in Magento 2?:

A quick command line that will, usually, resolve those RequireJS map/shim/alias things that often obscure where a file lives in Magento 2. Spoilers

find vendor/magento/ -name requirejs-config.js -exec grep addToCart '{}' +
[ 16 Jun 2016 ]

I was investigating Magento 2’s TinyMCE implementation the other day, and came across this

#File: vendor/magento//magento2-base/lib/web/mage/adminhtml/wysiwyg/tiny_mce/setup.js
], function(jQuery, _, tinyMCE) {

    tinyMceWysiwygSetup = Class.create();    

The TinyMCE RequireJS setup module was referencing a Class object – but there was no such object imported in the list of module dependencies.

I was flummoxed as to where this came from for a few minutes – did I miss some modern javascript addition where classes are something more than an alias to a function constructor?

Then I looked again …

[ 13 Jun 2016 ]

Magento 2, KnockoutJS ViewModels, and Scope Binding:

A self answer from me over on the Magento StackExchange. The short version – Magento applies knockout bindings without a default view model. The Magento_Ui/js/core/app module/program, embeded via x-magento-init, adds view model objects to the uiRegistry. Finally, Magento has implementd a custom scope binding which developers can use to load a view model from the uiRegistry and apply it to any sub-nodes.

[ 13 Jun 2016 ]

Magento 2’s core javascript library ships with a basic implementation of a class based object system, and the uiComponent feature uses these classes and objects extensively. The base class is the Magento_Ui/js/lib/core/class module/object/function, and you create a new instance of the class using javascript build-in new keyword.

], function (Class) {
    'use strict';
    var o = new Class;

You can create a child class using the base class’s extend function. You pass extend a list of key/function pairs to define methods. Magento’s objects have a constructor-like method named initialize is called when you instantiate an object. You can call a parent …

[ 11 Jun 2016 ]

KnockoutJS: What Does Calling applyBindings Without Arguments do?:

Getting into Magento 2’s KnockoutJS implementation, and being slightly annoyed at the JS world. Knockout’s a great framework, but by positioning themselves as an MVVM framework they create the impression that Knockout itself is enough to contain your entire application logic. Its not, and once developers adopt Knockout they end up building a custom, undocumented framework around it. Great for developers who want to keep themselves useful in a job – less great for creating an open source framework that anyone can learn to use and contribute to.

[ 8 Jun 2016 ]

First, lets bask in the awful yet accurate glory of my original title for this quickie: Dependency Injection Argument Specific Instance Objects.

If you’ve worked your way through my Magento 2 Object Manager series, you know its possible to tell Magento’s object system that a particular object should be instantiated every time its used in automatic constructor dependency injection.

To recap, Magento defaults to using the object manager’s get method to return objects for automatic constructor dependency injection, which will return the same object instance every time. However, if your di.xml configuration contains the following for a specific class

<type name="Foo\Baz\Bar" shared="false"/>

Magento will always instantiate a new Foo\Baz\Bar.

What I didn’t realize until today is, shared="false" works with argument replacement as …

[ 6 Jun 2016 ]

Rackspace Magento Hosting Post Mortem – Dev Notes:

Rackspace has fallen a long way from the days of the defacto preferred Magento host.

[ 27 May 2016 ]

Magento 2 Mock Fixing:

Speaking of Vinai, here’s a nice how to on adjusting Magento’s test mocks, and then some good typing on what would really fix them.