cloud-8.x-2.0-beta1/modules/cloud_service_providers/k8s/src/Entity/K8sLimitRange.php
modules/cloud_service_providers/k8s/src/Entity/K8sLimitRange.php
<?php
namespace Drupal\k8s\Entity;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Defines the Limit Range entity.
*
* @ingroup k8s
*
* @ContentEntityType(
* id = "k8s_limit_range",
* label = @Translation("Kubernetes Limit Range"),
* handlers = {
* "view_builder" = "Drupal\k8s\Entity\K8sLimitRangeViewBuilder",
* "list_builder" = "Drupal\cloud\Controller\CloudContentListBuilder",
* "views_data" = "Drupal\k8s\Entity\K8sLimitRangeViewsData",
* "access" = "Drupal\k8s\Controller\K8sLimitRangeAccessControlHandler",
* "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_limit_range",
* admin_permission = "administer k8s limit range",
* fieldable = TRUE,
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* },
* links = {
* "canonical" = "/clouds/k8s/{cloud_context}/limit_range/{k8s_limit_range}",
* "collection" = "/clouds/k8s/{cloud_context}/limit_range",
* "add-form" = "/clouds/k8s/{cloud_context}/limit_range/add",
* "edit-form" = "/clouds/k8s/{cloud_context}/limit_range/{k8s_limit_range}/edit",
* "delete-form" = "/clouds/k8s/{cloud_context}/limit_range/{k8s_limit_range}/delete",
* "delete-multiple-form" = "/clouds/k8s/{cloud_context}/limit_range/delete_multiple",
* },
* field_ui_base_route = "k8s_limit_range.settings"
* )
*/
class K8sLimitRange extends K8sEntityBase implements K8sLimitRangeInterface {
/**
* {@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 getLimits() {
return $this->get('limits');
}
/**
* {@inheritdoc}
*/
public function setLimits($limits) {
return $this->set('limits', $limits);
}
/**
* {@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 Limit Range entity.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Limit Range entity.'))
->setReadOnly(TRUE);
$fields['cloud_context'] = BaseFieldDefinition::create('string')
->setRequired(TRUE)
->setLabel(t('Cloud 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 limit range name.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['namespace'] = BaseFieldDefinition::create('string')
->setLabel(t('Namespace'))
->setDescription(t('The namespace of limit range.'))
->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['limits'] = BaseFieldDefinition::create('limit')
->setLabel(t('Limits'))
->setDescription(t('The limits.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', [
'type' => 'limit_formatter',
'weight' => -5,
]);
$fields['detail'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Detail'))
->setDescription(t('Limit Range 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;
}
}
