View source
<?php
namespace Drupal\build_hooks\Entity;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\RevisionLogEntityTrait;
use Drupal\Core\Entity\RevisionLogInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
class Deployment extends ContentEntityBase implements DeploymentInterface, EntityChangedInterface, RevisionLogInterface {
use RevisionLogEntityTrait;
use EntityChangedTrait;
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['label'] = BaseFieldDefinition::create('string')
->setLabel(t('Label'))
->setRequired(TRUE)
->setTranslatable(TRUE)
->setRevisionable(TRUE)
->setSetting('max_length', 255)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'string',
'weight' => -5,
])
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(new TranslatableMarkup('Deployed'))
->setRevisionable(TRUE)
->setDefaultValue(FALSE);
$fields += static::revisionLogBaseFieldDefinitions($entity_type);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time the deployment was created.'))
->setRevisionable(TRUE)
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);
$fields['deployed'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Created'))
->setDescription(t('The time the deployment was deployed.'))
->setRevisionable(TRUE)
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the deployment was last edited.'))
->setRevisionable(TRUE)
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);
$fields['contents'] = BaseFieldDefinition::create('dynamic_entity_reference')
->setLabel((string) new TranslatableMarkup('Deployment contents'))
->setDescription((string) new TranslatableMarkup('Content entities updated since the last deployment.'))
->setRequired(FALSE)
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'dynamic_entity_reference_label',
'weight' => 20,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setSettings([
'exclude_entity_types' => TRUE,
'entity_type_ids' => [
'build_hooks_deployment',
],
]);
$fields['deleted'] = BaseFieldDefinition::create('string')
->setLabel((string) new TranslatableMarkup('Deleted items'))
->setDescription((string) new TranslatableMarkup('Content entities deleted since the last deployment.'))
->setRequired(FALSE)
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => 20,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
return $fields;
}
public function isDeployed() : bool {
return (bool) $this
->get('status')->value;
}
}