Added Event entity type.
This commit is contained in:
159
modules/opencase_entities/src/Entity/OCEvent.php
Normal file
159
modules/opencase_entities/src/Entity/OCEvent.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Entity\ContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityChangedTrait;
|
||||
use Drupal\Core\Entity\EntityPublishedTrait;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
|
||||
/**
|
||||
* Defines the Event entity.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "oc_event",
|
||||
* label = @Translation("Event"),
|
||||
* bundle_label = @Translation("Event type"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\opencase_entities\OCEventListBuilder",
|
||||
* "views_data" = "Drupal\opencase_entities\Entity\OCEventViewsData",
|
||||
*
|
||||
* "form" = {
|
||||
* "default" = "Drupal\opencase_entities\Form\OCEventForm",
|
||||
* "add" = "Drupal\opencase_entities\Form\OCEventForm",
|
||||
* "edit" = "Drupal\opencase_entities\Form\OCEventForm",
|
||||
* "delete" = "Drupal\opencase_entities\Form\OCEventDeleteForm",
|
||||
* },
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\opencase_entities\OCEventHtmlRouteProvider",
|
||||
* },
|
||||
* "access" = "Drupal\opencase_entities\OCEventAccessControlHandler",
|
||||
* },
|
||||
* base_table = "oc_event",
|
||||
* translatable = FALSE,
|
||||
* permission_granularity = "bundle",
|
||||
* admin_permission = "administer event entities",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "bundle" = "type",
|
||||
* "label" = "name",
|
||||
* "uuid" = "uuid",
|
||||
* "langcode" = "langcode",
|
||||
* "published" = "status",
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/opencase/oc_event/{oc_event}",
|
||||
* "add-page" = "/opencase/oc_event/add",
|
||||
* "add-form" = "/opencase/oc_event/add/{oc_event_type}",
|
||||
* "edit-form" = "/opencase/oc_event/{oc_event}/edit",
|
||||
* "delete-form" = "/opencase/oc_event/{oc_event}/delete",
|
||||
* "collection" = "/opencase/oc_event",
|
||||
* },
|
||||
* bundle_entity_type = "oc_event_type",
|
||||
* field_ui_base_route = "entity.oc_event_type.edit_form"
|
||||
* )
|
||||
*/
|
||||
class OCEvent extends ContentEntityBase implements OCEventInterface {
|
||||
|
||||
use EntityChangedTrait;
|
||||
use EntityPublishedTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName() {
|
||||
return $this->get('name')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setName($name) {
|
||||
$this->set('name', $name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCreatedTime() {
|
||||
return $this->get('created')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setCreatedTime($timestamp) {
|
||||
$this->set('created', $timestamp);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
// Add the published field.
|
||||
$fields += static::publishedBaseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['name'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Name'))
|
||||
->setDescription(t('The name of the Event entity.'))
|
||||
->setSettings([
|
||||
'max_length' => 50,
|
||||
'text_processing' => 0,
|
||||
])
|
||||
->setDefaultValue('')
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'above',
|
||||
'type' => 'string',
|
||||
'weight' => -4,
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'string_textfield',
|
||||
'weight' => -4,
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->setDisplayConfigurable('view', TRUE)
|
||||
->setRequired(TRUE);
|
||||
|
||||
$fields['status']->setDescription(t('A boolean indicating whether the Event is published.'));
|
||||
|
||||
$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['activity_date_time'] = BaseFieldDefinition::create('datetime')
|
||||
->setLabel(t('Date and time'))
|
||||
->setRevisionable(TRUE)
|
||||
->setRequired(TRUE)
|
||||
// Uses the currentDateTime function from the Activity entity
|
||||
->setDefaultValueCallback('\Drupal\opencase_entities\Entity\OCActivity::currentDateTime')
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'above',
|
||||
'type' => 'datetime_default',
|
||||
'settings' => [
|
||||
'format_type' => 'medium',
|
||||
],
|
||||
'weight' => -3,
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'datetime_default',
|
||||
'weight' => -3,
|
||||
]);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user