cloud-8.x-2.0-beta1/modules/cloud_service_providers/k8s/src/Entity/K8sNamespace.php
modules/cloud_service_providers/k8s/src/Entity/K8sNamespace.php
<?php
namespace Drupal\k8s\Entity;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Defines the K8s Namespace entity.
*
* @ingroup k8s
*
* @ContentEntityType(
* id = "k8s_namespace",
* label = @Translation("Kubernetes Namespace"),
* handlers = {
* "view_builder" = "Drupal\k8s\Entity\K8sNamespaceViewBuilder",
* "list_builder" = "Drupal\cloud\Controller\CloudContentListBuilder",
* "views_data" = "Drupal\k8s\Entity\K8sNamespaceViewsData",
* "access" = "Drupal\k8s\Controller\K8sNamespaceAccessControlHandler",
* "form" = {
* "add" = "Drupal\k8s\Form\K8sNamespaceCreateForm",
* "edit" = "Drupal\k8s\Form\K8sNamespaceEditForm",
* "delete" = "Drupal\k8s\Form\K8sNamespaceDeleteForm",
* "delete-multiple-confirm" = "Drupal\k8s\Form\K8sNamespaceDeleteMultipleForm",
* },
* "route_provider" = {
* "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
* },
* },
* base_table = "k8s_namespace",
* admin_permission = "administer k8s namespace",
* fieldable = TRUE,
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* },
* links = {
* "canonical" = "/clouds/k8s/{cloud_context}/namespace/{k8s_namespace}",
* "collection" = "/clouds/k8s/{cloud_context}/namespace",
* "add-form" = "/clouds/k8s/{cloud_context}/namespace/add",
* "edit-form" = "/clouds/k8s/{cloud_context}/namespace/{k8s_namespace}/edit",
* "delete-form" = "/clouds/k8s/{cloud_context}/namespace/{k8s_namespace}/delete",
* "delete-multiple-form" = "/clouds/k8s/{cloud_context}/namespace/delete_multiple",
* },
* field_ui_base_route = "k8s_namespace.settings"
* )
*/
class K8sNamespace extends K8sEntityBase implements K8sNamespaceInterface {
/**
* {@inheritdoc}
*/
public function getName() {
return $this->get('name')->value;
}
/**
* {@inheritdoc}
*/
public function getStatus() {
return $this->get('status')->value;
}
/**
* {@inheritdoc}
*/
public function setStatus($status) {
return $this->set('status', $status);
}
/**
* {@inheritdoc}
*/
public function getLabels() {
return $this->get('labels')->getValue();
}
/**
* {@inheritdoc}
*/
public function setLabels(array $labels) {
return $this->set('labels', $labels);
}
/**
* {@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 function setCreated($created = 0) {
return $this->set('created', $created);
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the K8s Namespace entity.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the K8s Namespace 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 service provider.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The k8s namespace name.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['status'] = BaseFieldDefinition::create('string')
->setLabel(t('Status'))
->setDescription(t('The status of k8s namespace.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$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,
])
->setDisplayOptions('form', [
'type' => 'key_value_item',
]);
$fields['detail'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Detail'))
->setDescription(t('Namespace detail.'))
->setRequired(TRUE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'pre_string_formatter',
'weight' => -5,
]);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'timestamp',
'weight' => -5,
]);
$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 K8s Namespace 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;
}
}
