trait ProjectTrait in Drupal PM (Project Management) 4.x
Provides a trait for "belongs" to a project behaviour.
@package Drupal\pm_project\Entity
Hierarchy
- trait \Drupal\pm_project\Entity\ProjectTrait
7 files declare their use of ProjectTrait
- Board.php in modules/
pm_board/ src/ Entity/ Board.php - Epic.php in modules/
pm_epic/ src/ Entity/ Epic.php - Expense.php in modules/
pm_expense/ src/ Entity/ Expense.php - Feature.php in modules/
pm_feature/ src/ Entity/ Feature.php - Invoice.php in modules/
pm_invoice/ src/ Entity/ Invoice.php
File
- modules/
pm_project/ src/ Entity/ ProjectTrait.php, line 16
Namespace
Drupal\pm_project\EntityView source
trait ProjectTrait {
/**
* Returns an array of base field definitions for publishing status.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type to add the publishing status field to.
*
* @return \Drupal\Core\Field\BaseFieldDefinition[]
* An array of base field definitions.
*
* @throws \Drupal\Core\Entity\Exception\UnsupportedEntityTypeDefinitionException
* Thrown when the entity type does not implement EntityPublishedInterface
* or if it does not have a "published" entity key.
*/
public static function projectFieldDefinitions(EntityTypeInterface $entity_type) {
if (!is_subclass_of($entity_type
->getClass(), ContentEntityInterface::class)) {
throw new UnsupportedEntityTypeDefinitionException('The entity type ' . $entity_type
->id() . ' does not implement \\Drupal\\Core\\Entity\\ContentEntityInterface.');
}
$fields = [];
$fields['project'] = BaseFieldDefinition::create('entity_reference')
->setLabel(new TranslatableMarkup('Project'))
->setSetting('target_type', 'pm_project')
->setSetting('handler', 'default')
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'Project',
'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)
->setRequired(TRUE)
->setCardinality(1);
return $fields;
}
/**
* {@inheritdoc}
*/
public function getProject() {
return (bool) $this
->getEntityKey('project');
}
/**
* {@inheritdoc}
*/
public function setProject($project_id) {
$this
->set('project', $project_id);
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ProjectTrait:: |
public | function | ||
ProjectTrait:: |
public static | function | Returns an array of base field definitions for publishing status. | |
ProjectTrait:: |
public | function |