Added equal opps entity
This commit is contained in:
146
modules/opencase_entities/src/Entity/OCEqualOpps.php
Normal file
146
modules/opencase_entities/src/Entity/OCEqualOpps.php
Normal file
@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Defines the Equal Opps entity.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "oc_equal_opps",
|
||||
* label = @Translation("Equal Opps"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\opencase_entities\OCEqualOppsListBuilder",
|
||||
* "views_data" = "Drupal\opencase_entities\Entity\OCEqualOppsViewsData",
|
||||
*
|
||||
* "form" = {
|
||||
* "default" = "Drupal\opencase_entities\Form\OCEqualOppsForm",
|
||||
* "add" = "Drupal\opencase_entities\Form\OCEqualOppsForm",
|
||||
* "edit" = "Drupal\opencase_entities\Form\OCEqualOppsForm",
|
||||
* "delete" = "Drupal\opencase_entities\Form\OCEqualOppsDeleteForm",
|
||||
* },
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\opencase_entities\OCEqualOppsHtmlRouteProvider",
|
||||
* },
|
||||
* "access" = "Drupal\opencase_entities\OCEqualOppsAccessControlHandler",
|
||||
* },
|
||||
* base_table = "oc_equal_opps",
|
||||
* translatable = FALSE,
|
||||
* admin_permission = "administer equal opps entities",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "name",
|
||||
* "uuid" = "uuid",
|
||||
* "langcode" = "langcode",
|
||||
* "published" = "status",
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/opencase/oc_equal_opps/{oc_equal_opps}",
|
||||
* "add-form" = "/opencase/oc_equal_opps/add",
|
||||
* "edit-form" = "/opencase/oc_equal_opps/{oc_equal_opps}/edit",
|
||||
* "delete-form" = "/opencase/oc_equal_opps/{oc_equal_opps}/delete",
|
||||
* "collection" = "/opencase/oc_equal_opps",
|
||||
* },
|
||||
* field_ui_base_route = "oc_equal_opps.settings"
|
||||
* )
|
||||
*/
|
||||
class OCEqualOpps extends ContentEntityBase implements OCEqualOppsInterface {
|
||||
|
||||
use EntityChangedTrait;
|
||||
use EntityPublishedTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function preSave(EntityStorageInterface $storage) {
|
||||
parent::preSave($storage);
|
||||
// get the name of the person and make that the name of the thing.
|
||||
$name = $this->get('oc_actor')->entity->get('name')->first()->value;
|
||||
$this->setName($name);
|
||||
}
|
||||
/**
|
||||
* {@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 Equal Opps entity.'))
|
||||
->setSettings([
|
||||
'max_length' => 50,
|
||||
'text_processing' => 0,
|
||||
]);
|
||||
|
||||
$fields['oc_actor'] = \Drupal\Core\Field\BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Person'))
|
||||
->setDescription(t('The person this pertains to.'))
|
||||
->setSetting('target_type', 'oc_actor')
|
||||
->setSetting('handler', 'default')
|
||||
->setCardinality(1)
|
||||
->setDisplayOptions('view', [
|
||||
'type' => 'string',
|
||||
'weight' => -3,
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'entity_reference_autocomplete_tags',
|
||||
'weight' => -3,
|
||||
])
|
||||
->setRequired(TRUE);
|
||||
|
||||
$fields['status']->setDescription(t('A boolean indicating whether the Equal Opps 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.'));
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
@ -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 Equal Opps entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
interface OCEqualOppsInterface extends ContentEntityInterface, EntityChangedInterface, EntityPublishedInterface {
|
||||
|
||||
/**
|
||||
* Add get/set methods for your configuration properties here.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets the Equal Opps name.
|
||||
*
|
||||
* @return string
|
||||
* Name of the Equal Opps.
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Sets the Equal Opps name.
|
||||
*
|
||||
* @param string $name
|
||||
* The Equal Opps name.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCEqualOppsInterface
|
||||
* The called Equal Opps entity.
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Gets the Equal Opps creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* Creation timestamp of the Equal Opps.
|
||||
*/
|
||||
public function getCreatedTime();
|
||||
|
||||
/**
|
||||
* Sets the Equal Opps creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The Equal Opps creation timestamp.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCEqualOppsInterface
|
||||
* The called Equal Opps entity.
|
||||
*/
|
||||
public function setCreatedTime($timestamp);
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\views\EntityViewsData;
|
||||
|
||||
/**
|
||||
* Provides Views data for Equal Opps entities.
|
||||
*/
|
||||
class OCEqualOppsViewsData 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