Add a simple Plan record relationship entity type (with bundles).
This commit is contained in:
parent
9c6d597404
commit
9d31aa5ce7
|
@ -0,0 +1,13 @@
|
|||
plan_record.type.*:
|
||||
type: config_entity
|
||||
label: 'Plan record relationship type'
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'Machine-readable name'
|
||||
label:
|
||||
type: label
|
||||
label: 'Type'
|
||||
description:
|
||||
type: text
|
||||
label: 'Description'
|
|
@ -3,3 +3,5 @@ description: Provides an entity to store the relationship between a plan and a r
|
|||
type: module
|
||||
package: farmOS
|
||||
core_version_requirement: ^10
|
||||
dependencies:
|
||||
- entity:entity
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\plan_record\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityBase;
|
||||
|
||||
/**
|
||||
* Defines the Plan record relationship entity.
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "plan_record",
|
||||
* label = @Translation("Plan record relationship"),
|
||||
* bundle_label = @Translation("Plan record relationship type"),
|
||||
* label_collection = @Translation("Plan record relationships"),
|
||||
* label_singular = @Translation("plan record relationship"),
|
||||
* label_plural = @Translation("plan record relationships"),
|
||||
* label_count = @PluralTranslation(
|
||||
* singular = "@count plan record relationship",
|
||||
* plural = "@count plan record relationships",
|
||||
* ),
|
||||
* base_table = "plan_record",
|
||||
* data_table = "plan_record_data",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "uuid" = "uuid",
|
||||
* "label" = "uuid",
|
||||
* "bundle" = "type",
|
||||
* },
|
||||
* bundle_entity_type = "plan_record_type",
|
||||
* common_reference_target = TRUE,
|
||||
* )
|
||||
*/
|
||||
class PlanRecord extends ContentEntityBase implements PlanRecordInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBundleLabel() {
|
||||
/** @var \Drupal\plan_record\Entity\PlanRecordTypeInterface $type */
|
||||
$type = \Drupal::entityTypeManager()
|
||||
->getStorage('plan_record_type')
|
||||
->load($this->bundle());
|
||||
return $type->label();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\plan_record\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining plan record relationship entities.
|
||||
*/
|
||||
interface PlanRecordInterface extends ContentEntityInterface {
|
||||
|
||||
/**
|
||||
* Gets the label of the plan record relationship type.
|
||||
*
|
||||
* @return string
|
||||
* The label of the plan record relationship type.
|
||||
*/
|
||||
public function getBundleLabel();
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\plan_record\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
||||
|
||||
/**
|
||||
* Defines the Plan record relationship type entity.
|
||||
*
|
||||
* @ConfigEntityType(
|
||||
* id = "plan_record_type",
|
||||
* label = @Translation("Plan record relationship type"),
|
||||
* label_collection = @Translation("Plan record relationship types"),
|
||||
* label_singular = @Translation("Plan record relationship type"),
|
||||
* label_plural = @Translation("plan record relationship types"),
|
||||
* label_count = @PluralTranslation(
|
||||
* singular = "@count plan record relationship type",
|
||||
* plural = "@count plan record relationship types",
|
||||
* ),
|
||||
* handlers = {
|
||||
* "access" = "\Drupal\entity\BundleEntityAccessControlHandler",
|
||||
* },
|
||||
* config_prefix = "type",
|
||||
* bundle_of = "plan_record",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label",
|
||||
* "uuid" = "uuid",
|
||||
* },
|
||||
* config_export = {
|
||||
* "id",
|
||||
* "label",
|
||||
* "description",
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class PlanRecordType extends ConfigEntityBundleBase implements PlanRecordTypeInterface {
|
||||
|
||||
/**
|
||||
* The Plan record relationship type ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* The Plan record relationship type label.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
/**
|
||||
* A brief description of this plan record relationship type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setDescription($description) {
|
||||
return $this->set('description', $description);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\plan_record\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
use Drupal\Core\Entity\EntityDescriptionInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining Plan record relationship type entities.
|
||||
*/
|
||||
interface PlanRecordTypeInterface extends ConfigEntityInterface, EntityDescriptionInterface {
|
||||
|
||||
}
|
Loading…
Reference in New Issue