sisl-source / magento2-simpledata
The SimpleData module simplifies calling Magento data structures.
Package info
github.com/SISL-source/magento2-simpledata
Type:magento2-module
pkg:composer/sisl-source/magento2-simpledata
Fund package maintenance!
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0
- magento/framework: >=103.0.4 <104
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A developer helper for programmatically managing CMS content in Magento 2. Instead of wiring up repositories, interfaces and factories by hand, you call a single method:
$this->block->save([ 'identifier' => 'footer-links', 'title' => 'Footer Links', 'content' => '<p>…</p>', 'is_active' => 1, 'stores' => [0], ]);
save() is idempotent (upsert by identifier + store_id): if the block/page exists it is
updated, otherwise it is created. There is also delete($identifier, $storeId). On top of that,
an abstract base SimpleDataPatch (implements DataPatchInterface) that you extend to seed
CMS content from a data patch without the boilerplate.
This is a maintained fork of the abandoned markshust/magento2-module-simpledata (Mark Shust,
94★, last commit 2023). The original declares very loose php: >=7.1 / magento/framework: >=101;
the fork pins the dependencies and is verified on Magento 2.4.9 / PHP 8.4 (di:compile + a
create/read/delete test of a CMS block against a live database).
Compatibility
- Magento 2.4.4 – 2.4.9 (Open Source / Adobe Commerce)
- PHP 8.1 – 8.4
Installation
composer require sisl-source/magento2-simpledata
bin/magento module:enable MarkShust_SimpleData
bin/magento setup:upgrade
bin/magento setup:di:compile # production mode
Example: a data patch seeding a CMS block
use MarkShust\SimpleData\Setup\Patch\SimpleDataPatch; class CreateFooterBlock extends SimpleDataPatch { public function apply(): self { $this->block->save([ 'identifier' => 'sisl-footer', 'title' => 'SISL Footer', 'content' => '<p>© SISL</p>', 'is_active' => 1, 'stores' => [0], ]); return $this; } }
API
MarkShust\SimpleData\Api\Cms\SimpleBlock—save(array $data),delete(string $identifier, int $storeId)MarkShust\SimpleData\Api\Cms\SimplePage— same, for CMS pagesMarkShust\SimpleData\Setup\Patch\SimpleDataPatch— abstract data-patch base
License
MIT (same as upstream). Fork maintained by SISL.
Maintained by SISL
Maintained fork by SISL — Magento 2 development and modules. More self-hosted plugins: SISL Marketplace.