-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathHarvestPlan.php
More file actions
100 lines (91 loc) · 3.19 KB
/
Copy pathHarvestPlan.php
File metadata and controls
100 lines (91 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace Drupal\harvest\Entity;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\harvest\HarvestPlanInterface;
/**
* Defines the harvest plan entity class.
*
* The entity stores an identifier for the plan ('id') and a blob of JSON to
* represent the plan ('data'). This is not the JSON of the harvest, but the
* DKAN harvest plan. See components.schemas.harvestPlan within
* modules/harvest/docs/openapi_spec.json for the schema of a plan.
*
* The plan JSON must contain an object with a property named 'identifier'. The
* 'id' field of this entity must contain the same value as that identifier.
*
* @ContentEntityType(
* id = "harvest_plan",
* label = @Translation("Harvest Plan"),
* label_collection = @Translation("Harvests"),
* label_singular = @Translation("harvest plan"),
* label_plural = @Translation("harvest plans"),
* label_count = @PluralTranslation(
* singular = "@count harvest plans",
* plural = "@count harvest plans",
* ),
* handlers = {
* "list_builder" = "Drupal\harvest\HarvestPlanListBuilder",
* "views_data" = "Drupal\views\EntityViewsData",
* "access" = "Drupal\harvest\ContentAccessControlHandler",
* "route_provider" = {
* "html" = "Drupal\harvest\Routing\HarvestDashboardHtmlRouteProvider",
* },
* "form" = {
* "run" = "Drupal\harvest\Form\HarvestPlanRunForm",
* }
* },
* base_table = "harvest_plans",
* admin_permission = "administer harvest plan",
* entity_keys = {
* "id" = "id",
* "label" = "id",
* },
* links = {
* "collection" = "/admin/dkan/harvest",
* "canonical" = "/harvest-plan/{harvest_plan}",
* "run-form" = "/admin/harvest-plan/{harvest_plan}/run",
* },
* internal = TRUE,
* )
*
* Canonical must be supplied for the route builder, but is not currently used.
*
* Internal = TRUE tells JSON:API not to expose this entity. We have our own
* harvest API, so we don't want this.
*
* @todo Add fields for each element of the harvestPlan schema.
* @todo Add links and handlers for register, run, and deregister operations.
*/
final class HarvestPlan extends HarvestEntityBase implements HarvestPlanInterface {
/**
* {@inheritDoc}
*
* Provides identifier and JSON data base fields.
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
// Get base fields based on annotated config above.
$base_fields = parent::baseFieldDefinitions($entity_type);
// The 'id' field is the unique identifier for each harvest plan row.
$base_fields['id'] = static::getBaseFieldIdentifier(
new TranslatableMarkup('Identifier')
);
// The 'data' field contains JSON which describes the harvest plan. The plan
// must be an object with at least a property of 'identifier'.
$base_fields['data'] = static::getBaseFieldJsonData(new TranslatableMarkup('Data'));
return $base_fields;
}
/**
* {@inheritDoc}
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() {
return $this->getPlan();
}
/**
* {@inheritDoc}
*/
public function getPlan(): object {
return json_decode($this->get('data')->getString());
}
}