Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/strakers/drupal-entity-decorator
Implements a decorator pattern to access and customize an entity's properties and methods, with the option to strongly type return values.
https://github.com/strakers/drupal-entity-decorator
drupal entity php
Last synced: about 1 month ago
JSON representation
Implements a decorator pattern to access and customize an entity's properties and methods, with the option to strongly type return values.
- Host: GitHub
- URL: https://github.com/strakers/drupal-entity-decorator
- Owner: strakers
- License: gpl-3.0
- Created: 2023-12-08T18:12:20.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-08T23:03:55.000Z (12 months ago)
- Last Synced: 2024-11-14T15:21:10.425Z (3 months ago)
- Topics: drupal, entity, php
- Language: PHP
- Homepage:
- Size: 235 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Drupal Entity Decorator API
Implements a decorator pattern to access and customize an entity's properties and methods, with the option to strongly
type return values.---
## Installation
```bash
composer require strakez/drupal-entity-decorator
```---
## Requirements
- PHP 8.1+
- Drupal 10+---
## Purpose
Provides a simple means to retrieve and display entity data, and solves some of the challenges experienced when working
with entities. This implementation of the decorator pattern wraps the entity and provides customized methods for
interacting with the entity.Please note, this only exposes classes for use in other modules and does not provide any Drupal functionality on its own.
There will not be anything to display via the UI unless specifically implemented.---
## Usage
```php
$id = 1;
$node = NodeDecorator::load($id); // Collection$node->id(); // 1
$node->get('title'); // 'My First Node'
$node->get('sticky'); // false
```For information on using and extending decorators, see the [Decorator documentation](docs/Decorators.md).
For tips and best practices, see the [Tips & Best Practices](docs/BestPractices.md) section.
---
## Working with Collections
When loading multiple decorators at a time, the data will be representated in a collection. This provides an advantage
over simple arrays, as this data can be easily sorted, mutated, counted, and indexed.```php
$set = NodeDecorator::loadByOwned($user); // Collection
```For more information, see the [Collection documentation](docs/Collections.md).
## Final Words
Please have fun using this API, and feel free to submit your comments and/or improvements if you find any. Thanks!