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;
|
||||
}
|
||||
|
||||
}
|
58
modules/opencase_entities/src/Entity/OCEventInterface.php
Normal file
58
modules/opencase_entities/src/Entity/OCEventInterface.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityChangedInterface;
|
||||
use Drupal\Core\Entity\EntityPublishedInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining Event entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
interface OCEventInterface extends ContentEntityInterface, EntityChangedInterface, EntityPublishedInterface {
|
||||
|
||||
/**
|
||||
* Add get/set methods for your configuration properties here.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets the Event name.
|
||||
*
|
||||
* @return string
|
||||
* Name of the Event.
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Sets the Event name.
|
||||
*
|
||||
* @param string $name
|
||||
* The Event name.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCEventInterface
|
||||
* The called Event entity.
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Gets the Event creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* Creation timestamp of the Event.
|
||||
*/
|
||||
public function getCreatedTime();
|
||||
|
||||
/**
|
||||
* Sets the Event creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The Event creation timestamp.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCEventInterface
|
||||
* The called Event entity.
|
||||
*/
|
||||
public function setCreatedTime($timestamp);
|
||||
|
||||
}
|
58
modules/opencase_entities/src/Entity/OCEventType.php
Normal file
58
modules/opencase_entities/src/Entity/OCEventType.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
||||
|
||||
/**
|
||||
* Defines the Event type entity.
|
||||
*
|
||||
* @ConfigEntityType(
|
||||
* id = "oc_event_type",
|
||||
* label = @Translation("Event type"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\opencase_entities\OCEventTypeListBuilder",
|
||||
* "form" = {
|
||||
* "add" = "Drupal\opencase_entities\Form\OCEventTypeForm",
|
||||
* "edit" = "Drupal\opencase_entities\Form\OCEventTypeForm",
|
||||
* "delete" = "Drupal\opencase_entities\Form\OCEventTypeDeleteForm"
|
||||
* },
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\opencase_entities\OCEventTypeHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* config_prefix = "oc_event_type",
|
||||
* admin_permission = "administer site configuration",
|
||||
* bundle_of = "oc_event",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label",
|
||||
* "uuid" = "uuid"
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/admin/opencase/oc_event_type/{oc_event_type}",
|
||||
* "add-form" = "/admin/opencase/oc_event_type/add",
|
||||
* "edit-form" = "/admin/opencase/oc_event_type/{oc_event_type}/edit",
|
||||
* "delete-form" = "/admin/opencase/oc_event_type/{oc_event_type}/delete",
|
||||
* "collection" = "/admin/opencase/oc_event_type"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class OCEventType extends ConfigEntityBundleBase implements OCEventTypeInterface {
|
||||
|
||||
/**
|
||||
* The Event type ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* The Event type label.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining Event type entities.
|
||||
*/
|
||||
interface OCEventTypeInterface extends ConfigEntityInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
}
|
23
modules/opencase_entities/src/Entity/OCEventViewsData.php
Normal file
23
modules/opencase_entities/src/Entity/OCEventViewsData.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\views\EntityViewsData;
|
||||
|
||||
/**
|
||||
* Provides Views data for Event entities.
|
||||
*/
|
||||
class OCEventViewsData extends EntityViewsData {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewsData() {
|
||||
$data = parent::getViewsData();
|
||||
|
||||
// Additional information for Views integration, such as table joins, can be
|
||||
// put here.
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user