cloud-8.x-2.0-beta1/modules/cloud_service_providers/k8s/src/Entity/K8sCronJob.php
modules/cloud_service_providers/k8s/src/Entity/K8sCronJob.php
<?php
namespace Drupal\k8s\Entity;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Defines the Cron Job entity.
*
* @ingroup k8s
*
* @ContentEntityType(
* id = "k8s_cron_job",
* label = @Translation("Kubernetes Cron Job"),
* handlers = {
* "view_builder" = "Drupal\k8s\Entity\K8sCronJobViewBuilder",
* "list_builder" = "Drupal\cloud\Controller\CloudContentListBuilder",
* "views_data" = "Drupal\k8s\Entity\K8sCronJobViewsData",
* "access" = "Drupal\k8s\Controller\K8sCronJobAccessControlHandler",
* "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_cron_job",
* admin_permission = "administer k8s cron job",
* fieldable = TRUE,
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* },
* links = {
* "canonical" = "/clouds/k8s/{cloud_context}/cron_job/{k8s_cron_job}",
* "collection" = "/clouds/k8s/{cloud_context}/cron_job",
* "add-form" = "/clouds/k8s/{cloud_context}/cron_job/add",
* "edit-form" = "/clouds/k8s/{cloud_context}/cron_job/{k8s_cron_job}/edit",
* "delete-form" = "/clouds/k8s/{cloud_context}/cron_job/{k8s_cron_job}/delete",
* "delete-multiple-form" = "/clouds/k8s/{cloud_context}/cron_job/delete_multiple",
* },
* field_ui_base_route = "k8s_cron_job.settings"
* )
*/
class K8sCronJob extends K8sEntityBase implements K8sCronJobInterface {
/**
* {@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 getSchedule() {
return $this->get('schedule');
}
/**
* {@inheritdoc}
*/
public function setSchedule($schedule) {
return $this->set('schedule', $schedule);
}
/**
* {@inheritdoc}
*/
public function getActive() {
return $this->get('active');
}
/**
* {@inheritdoc}
*/
public function setActive($active) {
return $this->set('active', $active);
}
/**
* {@inheritdoc}
*/
public function isSuspend() {
return $this->get('suspend');
}
/**
* {@inheritdoc}
*/
public function setSuspend($suspend) {
return $this->set('suspend', $suspend);
}
/**
* {@inheritdoc}
*/
public function getLastScheduleTime() {
return $this->get('last_schedule_time');
}
/**
* {@inheritdoc}
*/
public function setLastScheduleTime($last_schedule_time) {
return $this->set('last_schedule_time', $last_schedule_time);
}
/**
* {@inheritdoc}
*/
public function getConcurrencyPolicy() {
return $this->get('concurrency_policy');
}
/**
* {@inheritdoc}
*/
public function setConcurrencyPolicy($concurrency_policy) {
return $this->set('concurrency_policy', $concurrency_policy);
}
/**
* {@inheritdoc}
*/
public function getStartingDeadlineSeconds() {
return $this->get('starting_deadline_seconds');
}
/**
* {@inheritdoc}
*/
public function setStartingDeadlineSeconds($starting_deadline_seconds) {
return $this->set('starting_deadline_seconds', $starting_deadline_seconds);
}
/**
* {@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 Cron Job entity.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Cron Job 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 cron job name.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['namespace'] = BaseFieldDefinition::create('string')
->setLabel(t('Namespace'))
->setDescription(t('The namespace of cron job.'))
->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['schedule'] = BaseFieldDefinition::create('string')
->setLabel(t('Schedule'))
->setDescription(t('The schedule in Cron format.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['active'] = BaseFieldDefinition::create('integer')
->setLabel(t('Active'))
->setDescription(t('The number of currently running jobs.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['suspend'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Suspend'))
->setDescription(t('This flag tells the controller to suspend subsequent executions, it does not apply to already started executions. Defaults to false.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'boolean',
'weight' => -5,
'settings' => [
'format' => 'true-false',
],
]);
$fields['last_schedule_time'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Last Schedule Time'))
->setDescription('Information when was the last time the job was successfully scheduled.')
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'timestamp',
'weight' => -5,
]);
$fields['concurrency_policy'] = BaseFieldDefinition::create('string')
->setLabel(t('Concurrency Policy'))
->setDescription(t('Specifies how to treat concurrent executions of a Job.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['starting_deadline_seconds'] = BaseFieldDefinition::create('integer')
->setLabel(t('Starting Deadline Seconds'))
->setDescription(t('Optional deadline in seconds for starting the job if it misses scheduled time for any reason.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['detail'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Detail'))
->setDescription(t('Cron Job 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;
}
}
