Sets the p1 through p9 properties for a menu link entity being saved.
\Drupal\Core\Entity\EntityInterface $entity: A menu link entity.
\Drupal\Core\Entity\EntityInterface $parent: A menu link entity.
protected function setParents(EntityInterface $entity, EntityInterface $parent) {
$i = 1;
while ($i < $entity->depth) {
$p = 'p' . $i++;
$entity->{$p} = $parent->{$p};
}
$p = 'p' . $i++;
// The parent (p1 - p9) corresponding to the depth always equals the mlid.
$entity->{$p} = $entity
->id();
while ($i <= MENU_MAX_DEPTH) {
$p = 'p' . $i++;
$entity->{$p} = 0;
}
}