The Home for
Magento Excellence

Explore. Discover. Elevate. #magento

162
Modules Tested
99
Ready for Magento 2.4
63
Need Your Help
Popular Module Potentially Abandoned v2.0.2

MarkShust_SimpleData

markshust/magento2-module-simpledata

A module that simplifies calling Magento data structures and provides a SimpleDataPatch class which simplifies writing data patch scripts.

166,609
Downloads
Below average
94
GitHub Stars
Above average
3y ago
Last Release
5
Open Issues
Build Passing
Ready to install

Build Tests

Composer Install
DI Compile
Templates

Code Quality

CS Coding Standard
L5 PHPStan

Tested on Magento 2.4.8-p3

Recent Test History

Each release is tested against the latest Magento version at that time.

v2.0.2 on Magento 2.4.8-p3
Dec 16, 2025
v2.0.2 on Magento 2.4.8-p2
Aug 14, 2025
v2.0.2 on Magento 2.4.8
May 21, 2025
v2.0.2 on Magento 2.4.7-p4
Feb 15, 2025
v2.0.2 on Magento 2.4.7-p3
Oct 20, 2024
v2.0.2 on Magento 2.4.7-p2
Sep 8, 2024

+4 older tests

GitHub Repository
Source code & docs
Packagist
Version history
Issues & Support
Get help or report bugs

Share This Module's Status

MarkShust_SimpleData Magento compatibility status badge

README

Loaded from GitHub

Table of contents

Summary

Calling Magento data structures can be confusing. There are many classes available, and knowing which to call and when can be confusing & overwhelming.

This module aims to simplify calling these data structures. All classes are prefixed with Simple so they are easy to lookup within IDEs. They also follow a pretty standard naming convention which aligns with Magento's way of naming modules. It also provides a SimpleDataPatch class which greatly simplifies writing data patch scripts.

For example, here is a data patch script to update the content of a CMS page with and without SimpleData:

Demo

Installation

composer require markshust/magento2-module-simpledata
bin/magento module:enable MarkShust_SimpleData
bin/magento setup:upgrade

Usage

Here are the signatures of the simplified data structures classes:

MarkShust\SimpleData\Api\Data\Cms\SimpleBlock

/**
 * Delete a block from a given identifier and optional store id.
 * @param string $identifier
 * @param int $storeId
 */
public function delete(string $identifier, int $storeId = Store::DEFAULT_STORE_ID): void

/**
 * If the CMS block identifier is found, attempt to update the record.
 * If it is not found, attempt to create a new record.
 * @param array $data
 */
public function save(array $data): void

MarkShust\SimpleData\Api\Data\Cms\SimplePage

/**
 * Delete a page from a given identifier and optional store id.
 * @param string $identifier
 * @param int $storeId
 */
public function delete(string $identifier, int $storeId = Store::DEFAULT_STORE_ID): void

/**
 * If the CMS page identifier is found, attempt to update the record.
 * If it is not found, attempt to create a new record.
 * @param array $data
 */
public function save(array $data): void

Examples using SimpleDataPatch

Create block

<?php
declare(strict_types = 1);

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class BlockFooBarCreate extends SimpleDataPatch
{
    public function apply(): self
    {
        $this->block->save([
            'identifier' => 'foo_bar',
            'title' => 'Foo bar',
            'content' => <<<CONTENT
<div class="foo-bar">
    Foo bar
</div>
CONTENT,
        ]);
    }
}

Delete block

<?php
declare(strict_types = 1);

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class BlockFooBarDelete extends SimpleDataPatch
{
    public function apply()
    {
        $this->block->delete('foo_bar');
    }
}

Update block

<?php
declare(strict_types = 1);

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class BlockFooBarUpdate extends SimpleDataPatch
{
    public function apply()
    {
        $this->block->save([
            'identifier' => 'foo_bar',
            'title' => 'Foo bar 1',
        ]);
    }
}

Create page

<?php
declare(strict_types = 1);

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class PageFooBarCreate extends SimpleDataPatch
{
    public function apply()
    {
        $this->page->save([
            'identifier' => 'foo_bar',
            'title' => 'Foo bar',
            'content' => <<<CONTENT
<div class="foo-bar">
    Foo bar
</div>
CONTENT,
        ]);
    }
}

Update page

<?php
declare(strict_types = 1);

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class MyDataPatch extends SimpleDataPatch
{
    public function apply()
    {
        $this->page->save([
            'identifier' => 'foo_bar',
            'title' => 'Foo bar 1',
        ]);
    }
}

Delete page

<?php
declare(strict_types = 1);

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class PageFooBarDelete extends SimpleDataPatch
{
    public function apply()
    {
        $this->page->delete('foo_bar');
    }
}

Create or update config

<?php

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class ConfigFooBarCreate extends SimpleDataPatch
{
    public function apply()
    {
        $this->config->save('foo/bar', 'baz');
    }
}

Delete config

<?php

namespace MarkShust\Data\Setup\Patch\Data;

use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch;

class ConfigFooBarDelete extends SimpleDataPatch
{
    public function apply()
    {
        $this->config->delete('foo/bar');
    }
}

Example using dependency injection

<?php
declare(strict_types = 1);

namespace MarkShust\SimpleData;

use MarkShust\SimpleData\Api\Cms\SimpleBlock;

class MyClass
{
    /** @var SimpleBlock */
    protected $block;

    /**
     * SimpleDataPatch constructor.
     * @param SimpleBlock $simpleBlock
     */
    public function __construct(
        SimpleBlock $simpleBlock
    ) {
        $this->block = $simpleBlock;
    }

    /**
     * {@inheritdoc}
     */
    public function execute(): void
    {
        $this->block->save([
            'identifier' => 'foo_bar',
            'title' => 'Foo bar',
            'content' => <<<CONTENT
<div class="foo-bar">
    Foo bar
</div>
CONTENT,
        ]);

        // Carry out other actions...
    }
}

License

MIT

This content is fetched directly from the module's GitHub repository. We are not the authors of this content and take no responsibility for its accuracy, completeness, or any consequences arising from its use.

Back to All Modules