You are here

public function PrevNextApi::modifyPointingEntities in Previous/Next API 8.2

Helper function to update other entities pointing to a particular entity.

Parameters

int $entity_id: Entity id.

string $bundle_name: Entity type.

Overrides PrevNextApiInterface::modifyPointingEntities

2 calls to PrevNextApi::modifyPointingEntities()
PrevNextApi::remove in src/PrevNextApi.php
Remove the prev_next records.
PrevNextApi::update in src/PrevNextApi.php
Update the prev_next records.

File

src/PrevNextApi.php, line 196

Class

PrevNextApi
Defines an PrevNextApi service.

Namespace

Drupal\prev_next

Code

public function modifyPointingEntities($entity_id, $bundle_name) {

  // First for previous.
  $prev = $this->database
    ->query("SELECT nid FROM {prev_next_node} WHERE prev_nid = :prev_nid", array(
    ':prev_nid' => $entity_id,
  ))
    ->fetchField();
  if ($prev) {
    $this
      ->add($prev, $bundle_name);
  }

  // Then for next.
  $next = $this->database
    ->query("SELECT nid FROM {prev_next_node} WHERE next_nid = :next_nid", array(
    ':next_nid' => $entity_id,
  ))
    ->fetchField();
  if ($next) {
    $this
      ->add($next, $bundle_name);
  }
}