Skip to content

Commit

Permalink
DDST-166: Hardening
Browse files Browse the repository at this point in the history
  • Loading branch information
bibliophileaxe committed Jun 4, 2024
1 parent 3834a7f commit 1c21d53
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions modules/dgi_actions_handle/dgi_actions_handle.module
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ function dgi_actions_handle_node_presave(NodeInterface $node): void {
$suffix_field = _dgi_actions_handle_get_suffix_field();

// Check if the node has the suffix field.
if ($suffix_field && $node->hasField($suffix_field)) {
if (!$node->isNew() && $suffix_field && $node->hasField($suffix_field)) {
// Load the original node from the database.
$original_node = Drupal::entityTypeManager()->getStorage('node')->loadUnchanged($node->id());

// Check if the field value has been changed.
if ($node->{$suffix_field}->value != $original_node->{$suffix_field}->value) {
// If the field value has been changed, revert it to the original value.
$node->{$suffix_field}->value = $original_node->{$suffix_field}->value;
Drupal::messenger()->addMessage('The suffix field cannot be changed.');
Drupal::messenger()->addWarning('The suffix field cannot be changed.');
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/dgi_actions_handle/src/Utility/HandleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public function getPrefix(): string {
* Gets the suffix for the entity.
*/
public function getSuffix(): ?string {
$suffix_field = $this->getIdentifier()->getServiceData()->getData()['prefix'];
$suffix_field = $this->getIdentifier()->getServiceData()->getData()['suffix_field'];

// If a field is configured, use that.
if ($this->getEntity()->hasField($suffix_field)) {
if ($suffix_field && $this->getEntity()->hasField($suffix_field)) {
return $this->getEntity()->get($suffix_field)->value;
}

Expand Down

0 comments on commit 1c21d53

Please sign in to comment.