I was looking at the xml sitemap custom add form and I think if we replace the id with a UUID, we can get rid of a select statement to get the current id and add one for the next id.

<?php
   $query = $this->connection->select('xmlsitemap', 'x');
    $query->addExpression('MAX(id)');
    $id = $query->execute()->fetchField();
    $link = array(
      'id' => $id + 1,
      'loc' => '',
      'priority' => XMLSITEMAP_PRIORITY_DEFAULT,
      'lastmod' => 0,
      'changefreq' => 0,
      'changecount' => 0,
      'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    );
?>

Alternatively, we could also make id auto increment if that is easier and less disruptive?

My thought was it would make it easier for me to add my own custom links to the list


<?php

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_state->cleanValues();
    $link = $form_state->getValues();
    $foo_service = \Drupal::service("landing.services");
    // items is a list of strings 
    $items = $branch_service::getFooUrlName();
    $my_id = $link['id'] + 1;
    foreach($items as $item){
      $foo_link = array(
        "id" => $my_id,
        "type" => "custom",
        "subtype" => "",
        "loc" => "about-us/locations/" . $item,
        "priority" => 0.5,
        "changefreq" => 0,
        "language" => "en"
      );
      $this->linkStorage->save($foo_link);
      $my_id += 1;
    }
    $this->linkStorage->save($link);
    drupal_set_message($this->t('The custom link for %loc was saved.', array('%loc' => $link['loc'])));
    $form_state->setRedirect('xmlsitemap_custom.list');
  }
}


?>

Should I use something else for this? Is there a way to feed a list of urls to the xmlsitemap_custom module?

Comments

kkus created an issue.