-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from youvo/lifecycle-history
Inscribe lifecycle history with every project transition
- Loading branch information
Showing
20 changed files
with
348 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
config/sync/field.field.project.project.field_lifecycle_history.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
uuid: 4f801fce-81be-465a-9383-d9a3a9f92137 | ||
langcode: de | ||
status: true | ||
dependencies: | ||
config: | ||
- field.storage.project.field_lifecycle_history | ||
module: | ||
- lifecycle | ||
- projects | ||
id: project.project.field_lifecycle_history | ||
field_name: field_lifecycle_history | ||
entity_type: project | ||
bundle: project | ||
label: 'Lifecycle History' | ||
description: '' | ||
required: false | ||
translatable: false | ||
default_value: { } | ||
default_value_callback: '' | ||
settings: { } | ||
field_type: lifecycle_history_item |
19 changes: 19 additions & 0 deletions
19
config/sync/field.storage.project.field_lifecycle_history.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
uuid: e80ad92f-3570-49a2-b92c-2e23ae1d74e2 | ||
langcode: de | ||
status: true | ||
dependencies: | ||
module: | ||
- lifecycle | ||
- projects | ||
id: project.field_lifecycle_history | ||
field_name: field_lifecycle_history | ||
entity_type: project | ||
type: lifecycle_history_item | ||
settings: { } | ||
module: lifecycle | ||
locked: false | ||
cardinality: -1 | ||
translatable: true | ||
indexes: { } | ||
persist_with_no_fields: false | ||
custom_storage: false |
110 changes: 110 additions & 0 deletions
110
web/modules/custom/projects/lifecycle/src/Plugin/Field/FieldType/LifecycleHistoryItem.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\lifecycle\Plugin\Field\FieldType; | ||
|
||
use Drupal\Core\Field\FieldItemBase; | ||
use Drupal\Core\Field\FieldStorageDefinitionInterface; | ||
use Drupal\Core\StringTranslation\TranslatableMarkup; | ||
use Drupal\Core\TypedData\DataDefinition; | ||
|
||
/** | ||
* Provides a lifecycle history field item. | ||
* | ||
* This field type does not provide an UI and is intended to be used in code. | ||
* | ||
* @FieldType( | ||
* id = "lifecycle_history_item", | ||
* label = @Translation("Lifecyle History"), | ||
* description = @Translation("Allows you to store a workflow state."), | ||
* default_formatter = NULL, | ||
* default_widget = NULL, | ||
* ) | ||
* | ||
* @property string|null $transition | ||
* @property string|null $from | ||
* @property string $to | ||
* @property int $uid | ||
* @property int $timestamp | ||
*/ | ||
class LifecycleHistoryItem extends FieldItemBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition): array { | ||
|
||
$properties['transition'] = DataDefinition::create('string') | ||
->setLabel(new TranslatableMarkup('Transition')) | ||
->setDescription(new TranslatableMarkup('The type of the transition.')); | ||
|
||
$properties['from'] = DataDefinition::create('string') | ||
->setLabel(new TranslatableMarkup('From')) | ||
->setDescription(new TranslatableMarkup('The state that the transition started from.')); | ||
|
||
$properties['to'] = DataDefinition::create('string') | ||
->setLabel(new TranslatableMarkup('To')) | ||
->setDescription(new TranslatableMarkup('The state that the transition went to.')) | ||
->setRequired(TRUE); | ||
|
||
$properties['uid'] = DataDefinition::create('integer') | ||
->setLabel(new TranslatableMarkup('Initiator')) | ||
->setDescription(new TranslatableMarkup('The initiator of the transition.')) | ||
->setSetting('unsigned', TRUE) | ||
->setRequired(TRUE); | ||
|
||
$properties['timestamp'] = DataDefinition::create('timestamp') | ||
->setLabel(new TranslatableMarkup('Timestamp')) | ||
->setDescription(new TranslatableMarkup('The time of the transition.')) | ||
->setRequired(TRUE); | ||
|
||
return $properties; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function schema(FieldStorageDefinitionInterface $field_definition): array { | ||
return [ | ||
'columns' => [ | ||
'transition' => [ | ||
'description' => 'The type of the transition.', | ||
'type' => 'varchar', | ||
'length' => 64, | ||
], | ||
'from' => [ | ||
'description' => 'The state that the transition started from.', | ||
'type' => 'varchar', | ||
'length' => 64, | ||
], | ||
'to' => [ | ||
'description' => 'The state that the transition went to.', | ||
'type' => 'varchar', | ||
'length' => 64, | ||
], | ||
'uid' => [ | ||
'description' => 'The initiator of the transition.', | ||
'type' => 'int', | ||
'unsigned' => TRUE, | ||
], | ||
'timestamp' => [ | ||
'description' => 'The time of the transition.', | ||
'type' => 'int', | ||
'unsigned' => TRUE, | ||
], | ||
], | ||
'indexes' => [ | ||
'format' => ['transition'], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isEmpty(): bool { | ||
return FALSE; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.