You are here

protected function SimpleSitemapTypeStorage::doSave in Simple XML sitemap 4.x

Performs storage-specific saving of the entity.

Parameters

int|string $id: The original entity ID.

\Drupal\Core\Entity\EntityInterface $entity: The entity to save.

Return value

bool|int If the record insert or update failed, returns FALSE. If it succeeded, returns SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Overrides ConfigEntityStorage::doSave

File

src/Entity/SimpleSitemapTypeStorage.php, line 41

Class

SimpleSitemapTypeStorage

Namespace

Drupal\simple_sitemap\Entity

Code

protected function doSave($id, EntityInterface $entity) {

  /** @var SimpleSitemapTypeInterface $entity */
  if ($entity
    ->get('sitemap_generator') === NULL || $entity
    ->get('sitemap_generator') === '') {
    throw new \InvalidArgumentException("The sitemap type must define its sitemap generator.");
  }
  if (empty($entity
    ->get('url_generators'))) {
    throw new \InvalidArgumentException("The sitemap type must define its URL generators");
  }
  if ($entity
    ->label() === NULL || $entity
    ->label() === '') {
    $entity
      ->set('label', $id);
  }
  return parent::doSave($id, $entity);
}