cloud-8.x-2.0-beta1/modules/cloud_service_providers/k8s/src/Entity/K8sServiceEntity.php
modules/cloud_service_providers/k8s/src/Entity/K8sServiceEntity.php
<?php
namespace Drupal\k8s\Entity;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Defines the Service entity.
*
* @ingroup k8s
*
* @ContentEntityType(
* id = "k8s_service",
* label = @Translation("Kubernetes Service"),
* handlers = {
* "view_builder" = "Drupal\k8s\Entity\K8sServiceViewBuilder",
* "list_builder" = "Drupal\cloud\Controller\CloudContentListBuilder",
* "views_data" = "Drupal\k8s\Entity\K8sServiceViewsData",
* "access" = "Drupal\k8s\Controller\K8sServiceAccessControlHandler",
* "form" = {
* "add" = "Drupal\k8s\Form\K8sCreateForm",
* "edit" = "Drupal\k8s\Form\K8sEditForm",
* "delete" = "Drupal\k8s\Form\K8sDeleteForm",
* "delete-multiple-confirm" = "Drupal\k8s\Form\K8sDeleteMultipleForm",
* },
* "route_provider" = {
* "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
* },
* },
* base_table = "k8s_service",
* admin_permission = "administer k8s service",
* fieldable = TRUE,
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* },
* links = {
* "canonical" = "/clouds/k8s/{cloud_context}/service/{k8s_service}",
* "collection" = "/clouds/k8s/{cloud_context}/service",
* "add-form" = "/clouds/k8s/{cloud_context}/service/add",
* "edit-form" = "/clouds/k8s/{cloud_context}/service/{k8s_service}/edit",
* "delete-form" = "/clouds/k8s/{cloud_context}/service/{k8s_service}/delete",
* "delete-multiple-form" = "/clouds/k8s/{cloud_context}/service/delete_multiple",
* },
* field_ui_base_route = "k8s_service.settings"
* )
*/
class K8sServiceEntity extends K8sEntityBase implements K8sServiceEntityInterface {
/**
* {@inheritdoc}
*/
public function getName() {
return $this->get('name')->value;
}
/**
* {@inheritdoc}
*/
public function setName($name) {
return $this->set('name', $name);
}
/**
* {@inheritdoc}
*/
public function getNamespace() {
return $this->get('namespace')->value;
}
/**
* {@inheritdoc}
*/
public function setNamespace($namespace) {
return $this->set('namespace', $namespace);
}
/**
* {@inheritdoc}
*/
public function getLabels() {
return $this->get('labels');
}
/**
* {@inheritdoc}
*/
public function setLabels($labels) {
return $this->set('labels', $labels);
}
/**
* {@inheritdoc}
*/
public function getAnnotations() {
return $this->get('annotations');
}
/**
* {@inheritdoc}
*/
public function setAnnotations($annotations) {
return $this->set('annotations', $annotations);
}
/**
* {@inheritdoc}
*/
public function getSelector() {
return $this->get('selector');
}
/**
* {@inheritdoc}
*/
public function setSelector($selector) {
return $this->set('selector', $selector);
}
/**
* {@inheritdoc}
*/
public function getType() {
return $this->get('type');
}
/**
* {@inheritdoc}
*/
public function setType($type) {
return $this->set('type', $type);
}
/**
* {@inheritdoc}
*/
public function getSessionAffinity() {
return $this->get('session_affinity');
}
/**
* {@inheritdoc}
*/
public function setSessionAffinity($session_affinity) {
return $this->set('session_affinity', $session_affinity);
}
/**
* {@inheritdoc}
*/
public function getClusterIp() {
return $this->get('cluster_ip');
}
/**
* {@inheritdoc}
*/
public function setClusterIp($cluster_ip) {
return $this->set('cluster_ip', $cluster_ip);
}
/**
* {@inheritdoc}
*/
public function getInternalEndpoints() {
return $this->get('internal_endpoints');
}
/**
* {@inheritdoc}
*/
public function setInternalEndpoints($internal_endpoints) {
return $this->set('internal_endpoints', $internal_endpoints);
}
/**
* {@inheritdoc}
*/
public function getExternalEndpoints() {
return $this->get('external_endpoints');
}
/**
* {@inheritdoc}
*/
public function setExternalEndpoints($external_endpoints) {
return $this->set('external_endpoints', $external_endpoints);
}
/**
* {@inheritdoc}
*/
public function getDetail() {
return $this->get('detail')->value;
}
/**
* {@inheritdoc}
*/
public function setDetail($detail) {
return $this->set('detail', $detail);
}
/**
* {@inheritdoc}
*/
public function getRefreshed() {
return $this->get('refreshed')->value;
}
/**
* {@inheritdoc}
*/
public function setRefreshed($time) {
return $this->set('refreshed', $time);
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the Service entity.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Service entity.'))
->setReadOnly(TRUE);
$fields['cloud_context'] = BaseFieldDefinition::create('string')
->setRequired(TRUE)
->setLabel(t('Cloud Service Provider ID'))
->setDescription(t('A unique machine name for the cloud provider.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The service name.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['namespace'] = BaseFieldDefinition::create('string')
->setLabel(t('Namespace'))
->setDescription(t('The namespace of service.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['labels'] = BaseFieldDefinition::create('key_value')
->setLabel(t('Labels'))
->setDescription(t('Map of string keys and values that can be used to organize and categorize (scope and select) objects.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', [
'type' => 'key_value_formatter',
'weight' => -5,
]);
$fields['annotations'] = BaseFieldDefinition::create('key_value')
->setLabel(t('Annotations'))
->setDescription(t('Annotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setSetting('max_length', 4096)
->setDisplayOptions('view', [
'type' => 'key_value_formatter',
'weight' => -5,
]);
$fields['selector'] = BaseFieldDefinition::create('key_value')
->setLabel(t('Selector'))
->setDescription(t('Route service traffic to pods with label keys and values matching this selector.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setSetting('max_length', 4096)
->setDisplayOptions('view', [
'type' => 'key_value_formatter',
'weight' => -5,
]);
$fields['type'] = BaseFieldDefinition::create('string')
->setLabel(t('Type'))
->setDescription(t('Determines how the Service is exposed.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['session_affinity'] = BaseFieldDefinition::create('string')
->setLabel(t('Session Affinity'))
->setDescription(t('Supports "ClientIP" and "None". Used to maintain session affinity.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['cluster_ip'] = BaseFieldDefinition::create('string')
->setLabel(t('Cluster IP'))
->setDescription(t('ClusterIP is the IP address of the service and is usually assigned randomly by the master.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['internal_endpoints'] = BaseFieldDefinition::create('string')
->setLabel(t('Internal Endpoints'))
->setDescription(t('Internal endpoints.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['external_endpoints'] = BaseFieldDefinition::create('string')
->setLabel(t('External Endpoints'))
->setDescription(t('External endpoints.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['detail'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Detail'))
->setDescription(t('Service detail.'))
->setRequired(TRUE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'pre_string_formatter',
'weight' => -5,
])
->setDisplayOptions('form', [
'type' => 'string_textarea',
'settings' => [
'rows' => 20,
],
])
->addConstraint('yaml_array_data');
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the entity was last edited.'));
$fields['refreshed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Refreshed'))
->setDescription(t('The time that the entity was last refreshed.'));
$fields['uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Authored by'))
->setDescription(t('The user ID of the Pod entity author.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setDefaultValueCallback('Drupal\node\Entity\Node::getCurrentUserId')
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'author',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
return $fields;
}
}
