browse the blogs

[ 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
define([
    'jquery',
    'underscore',
    'tinymce',
    'mage/translate',
    'prototype',
    'mage/adminhtml/events',
    'mage/adminhtml/browser'
], 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.

requirejs([
    'Magento_Ui/js/lib/core/class',
], function (Class) {
    'use strict';
    var o = new Class;
    console.log(o);
});    

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.

[ 27 May 2016 ]

Magento’s documentation tells you to run tests with the following

php bin/magento dev:tests:run unit

This isn’t wrong, but it pretty time consuming. You’re running every test in the suite. This one liner will let you run an individual test

vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist path/to/Test/Unit/SomeTest.php

Thanks to Vinai Kopp for the reminder, and don’t forget to checkout his Mage 2 Katas series on youtube.

[ 17 May 2016 ]

Magento 2: Set a PHP umask:

It sounds like the latest version of Magento adds the ability to set a umask for PHP, which means another barrier to getting Magento up and running in industry standard, mod_php system (i.e. shared hosting and your laptop) has been knocked down. Looking forward to giving this a try when I have a moment. I know Miguel Balparda and Nexcess have been working hard to get something like this through, so give the a beverage or a hat tip the next time you see them.

[ 13 May 2016 ]

Magento 2: Sort Order gets Weird for “Around” Plugins:

Interesting bit of insight from Anton Kril on plugin firing order. My naive assumption on how this would work was

  • All before plugins fire
  • The around plugin chaining happens
  • All after plugins fire

However, based on what Anton’s said here, it sounds like an around plugin will fire before a before plugin if it has a lower sort order that the before plugin. Beyond the trickiness of following a chain of execution, this has extra implications for an around plugin that decides to skip the call to $proceed() – not only can it cancel the actual method call, it can also cancel other calls to before plugins as well.