markshust / magento2-module-simpledata
markshust/magento2-module-simpledata
The SimpleData module simplifies calling Magento data structures.
MarkShust_SimpleData
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:

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(): void
{
$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
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog
and this project adheres to Semantic Versioning.
[2.0.2] - 2022-06-28
Fixed
- Change return type to match PatchInterface.
[2.0.1] - 2020-01-13
Fixed
- Removed typed properties for PHP 7.3 support.
[2.0.0] - 2020-01-12
Added
- Added type declarations to class properties.
Removed
- Removed
SimpleConfigclass_alias as it caused issues in production mode (#4).
[1.0.0] - 2020-05-20
Added
- Initial release.
| Version | Stability | QA Status | Compatibility | Released |
|---|---|---|---|---|
| 2.0.2 | stable | Pass | Magento 2.4.7-2.4.9 Details | 2022-06-29 11:38:04 |
| 2.0.1 | stable | Not tested | Not yet tested Details | 2021-01-13 14:59:37 |
| 2.0.0 | stable | Not tested | Not yet tested Details | 2021-01-12 18:40:39 |
| 1.0.0 | stable | Not tested | Not yet tested Details | 2020-05-20 16:45:29 |
Requires 2
| Package | Constraint |
|---|---|
| php | >=7.1 |
| magento/framework | >=101 |
Compatibility
Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.
Code Quality
Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge — a phpcs finding can't make a module incompatible.
Static analysis
Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.
PHPStan
Type-checks the module's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases. Cell → details modal.
Tests
Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.
Unit tests
| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | ||
| 2.4.8 | N/A | N/A | ||
| 2.4.9 | N/A | N/A |
Integration tests
| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | ||
| 2.4.8 | N/A | N/A | ||
| 2.4.9 | N/A | N/A |
Security
Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.
More from markshust
View vendorThe Page Builder Source Code module adds a Source Code button to the toolbar of the Page Builder WYSIWYG editor.
The Order Grid module adds more details to the order grid in the admin.
The DisableTwoFactorAuth module provides the ability to disable two-factor authentication.
Turn an existing module into recurring revenue.
If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.