Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions docroot/modules/custom/foia_request/foia_request.module
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ function _foia_request_validate_status(array $element, FormStateInterface $form_
}
}

/**
* Implements hook_ENTITY_TYPE_insert().
*
* When a request is created, update the field_num_requests count for that
* agency component.
*/
function foia_request_foia_request_insert(FoiaRequestInterface $entity) {
foia_request_recount_num_requests($entity);
}

/**
* Implements hook_ENTITY_TYPE_update().
*
Expand Down Expand Up @@ -107,32 +97,3 @@ function foia_request_foia_request_delete(FoiaRequestInterface $entity) {
$webformSubmission->delete();
}
}

/**
* Recalculate agency component counts when a request entity is created.
*/
function foia_request_recount_num_requests(FoiaRequestInterface $entity) {

$agency_component_id = $entity->get('field_agency_component')->target_id;

if (!$agency_component_id) {
return;
}

// Count all request entities referencing this agency_component.
$count = \Drupal::entityQuery('foia_request')
->condition('field_agency_component.target_id', $agency_component_id)
->accessCheck(FALSE)
->count()
->execute();

$storage = \Drupal::entityTypeManager()->getStorage('node');

$agency_component = $storage->load($agency_component_id);

/** @var \Drupal\node\NodeInterface $agency_component */
if ($agency_component && $agency_component->bundle() === 'agency_component') {
$agency_component->set('field_num_requests', $count);
$agency_component->save();
}
}
Loading