mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Create the DataStreamNotification entity.
This commit is contained in:
parent
a73a4ff86d
commit
adf329d79e
|
@ -0,0 +1,29 @@
|
|||
# Schema for the configuration files of the Data stream notifications module.
|
||||
|
||||
data_stream_notification.data_stream_notification.*:
|
||||
type: config_entity
|
||||
label: 'Data stream notification'
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'ID'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
data_stream:
|
||||
type: integer
|
||||
nullable: true
|
||||
label: 'Data stream'
|
||||
condition_operator:
|
||||
type: string
|
||||
label: 'Condition operator'
|
||||
condition:
|
||||
type: sequence
|
||||
label: 'Conditions'
|
||||
sequence:
|
||||
type: data_stream_notification.condition.[type]
|
||||
delivery:
|
||||
type: sequence
|
||||
label: 'Delivery'
|
||||
sequence:
|
||||
type: data_stream_notification.delivery.[type]
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\data_stream_notification;
|
||||
|
||||
use Drupal\Core\Plugin\DefaultLazyPluginCollection;
|
||||
|
||||
/**
|
||||
* A plugin collection for notification condition and delivery plugins.
|
||||
*
|
||||
* Overrides the DefaultLazyPluginCollection to use "type" as the plugin key.
|
||||
*/
|
||||
class DataStreamNotificationPluginCollection extends DefaultLazyPluginCollection {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $pluginKey = 'type';
|
||||
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\data_stream_notification\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||
use Drupal\data_stream_notification\DataStreamNotificationPluginCollection;
|
||||
|
||||
/**
|
||||
* Defines the DataStreamNotification entity.
|
||||
*
|
||||
* @ConfigEntityType(
|
||||
* id = "data_stream_notification",
|
||||
* label = @Translation("Data stream notification"),
|
||||
* label_collection = @Translation("Data stream notifications"),
|
||||
* label_singular = @Translation("data stream notification"),
|
||||
* label_plural = @Translation("data stream notifications"),
|
||||
* label_count = @PluralTranslation(
|
||||
* singular = "@count data stream notification",
|
||||
* plural = "@count data stream notifications",
|
||||
* ),
|
||||
* handlers = {
|
||||
* "access" = "\Drupal\entity\EntityAccessControlHandler",
|
||||
* "permission_provider" = "\Drupal\entity\EntityPermissionProvider",
|
||||
* },
|
||||
* admin_permission = "administer data stream notification",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label",
|
||||
* "status" = "status",
|
||||
* },
|
||||
* config_export = {
|
||||
* "id",
|
||||
* "label",
|
||||
* "data_stream",
|
||||
* "condition_operator",
|
||||
* "condition",
|
||||
* "delivery",
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* @ingroup farm
|
||||
*/
|
||||
class DataStreamNotification extends ConfigEntityBase implements DataStreamNotificationInterface {
|
||||
|
||||
/**
|
||||
* The notification ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected string $id;
|
||||
|
||||
/**
|
||||
* The notification label.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected string $label;
|
||||
|
||||
/**
|
||||
* The data stream ID.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected int $data_stream;
|
||||
|
||||
/**
|
||||
* The condition operator.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected string $condition_operator;
|
||||
|
||||
/**
|
||||
* Stores all conditions of this notification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected array $condition = [];
|
||||
|
||||
/**
|
||||
* The condition plugin collection.
|
||||
*
|
||||
* @var \Drupal\data_stream_notification\DataStreamNotificationPluginCollection
|
||||
*/
|
||||
protected $conditionCollection;
|
||||
|
||||
/**
|
||||
* Stores all deliveries of this notification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected array $delivery = [];
|
||||
|
||||
/**
|
||||
* The delivery plugin collection.
|
||||
*
|
||||
* @var \Drupal\data_stream_notification\DataStreamNotificationPluginCollection
|
||||
*/
|
||||
protected $deliveryCollection;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPluginCollections() {
|
||||
foreach (['condition', 'delivery'] as $type) {
|
||||
$name = $type . 'Collection';
|
||||
if (empty($this->$name)) {
|
||||
$this->$name = new DataStreamNotificationPluginCollection(\Drupal::service("plugin.manager.data_stream_notification_$type"), $this->$type);
|
||||
}
|
||||
}
|
||||
return [
|
||||
'condition' => $this->conditionCollection,
|
||||
'delivery' => $this->deliveryCollection,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\data_stream_notification\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining data stream entities.
|
||||
*/
|
||||
interface DataStreamNotificationInterface extends ConfigEntityInterface, EntityWithPluginCollectionInterface {
|
||||
|
||||
}
|
Loading…
Reference in a new issue