5

In the Magento 2 layout loading code, there's the following method

public function getAllDesignAbstractions()
{
    $result = [];

    $conditions = [
        '(@design_abstraction="' . self::DESIGN_ABSTRACTION_PAGE_LAYOUT .
        '" or @design_abstraction="' . self::DESIGN_ABSTRACTION_CUSTOM . '")',
    ];
    $xpath = '/layouts/*[' . implode(' or ', $conditions) . ']';
    $nodes = $this->getFileLayoutUpdatesXml()->xpath($xpath) ?: [];
    /** @var $node \Magento\Framework\View\Layout\Element */
    foreach ($nodes as $node) {
        $name = $node->getAttribute('id');
        $info = [
            'name' => $name,
            'label' => (string)new \Magento\Framework\Phrase((string)$node->getAttribute('label')),
            'design_abstraction' => $node->getAttribute('design_abstraction'),
        ];
        $result[$name] = $info;
    }
    return $result;
}

What is a Magento 2 design abstraction? I've poked around the Frontend developer's guide and other sections on the dev docs site, but I can't seem to find any information about this feature there. Is this something that's still used in Magento 2? Or is it something that's been abandoned?

1 Answer 1

5

Any layout handle can be marked as a "design abstraction" to allow it to be used as a target for widget creation. By adding a label="Friendly Name" and design_abstraction="custom" to a layout handle it will appear in the widget creation interface. Then a widget can be created to display in a specified container on any pages that are updated by the chosen layout handle.

Note that this same approach existed in Magento 1, but there all you needed to do was create a <label> child node inside the layout handle for it to be picked up as a widget target. Magento 2 just changes it to an attribute and adds the requirement to set the design_abstraction attribute as well.

There is official mention of it here, though it's not linked to be easy to find: http://devdocs.magento.com/guides/v2.2/architecture/view/design-abstract.html

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.