state = $state; } /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $entity_type, $container->get('config.factory'), $container->get('uuid'), $container->get('language_manager'), $container->get('state'), $container->has('entity.memory_cache') ? $container->get('entity.memory_cache') : NULL ); } /** * {@inheritdoc} */ protected function doDelete($entities) { // Delete the auxiliar xmlsitemap data. foreach ($entities as $entity) { $this->state->delete('xmlsitemap.' . $entity->id()); xmlsitemap_clear_directory($entity, TRUE); } parent::doDelete($entities); } /** * {@inheritdoc} */ protected function doLoadMultiple(array $ids = NULL) { $entities = parent::doLoadMultiple($ids); // Load the auxiliar xmlsitemap data and attach it to the entity. foreach ($entities as $entity) { $settings = $this->state->get('xmlsitemap.' . $entity->id(), [ 'chunks' => NULL, 'links' => NULL, 'max_filesize' => NULL, 'updated' => NULL, ]); foreach ($settings as $setting => $value) { $entity->{$setting} = $value; } // Load the entity URI. $entity->uri = xmlsitemap_sitemap_uri($entity); // Load in the default contexts if they haven't been set yet. $contexts = xmlsitemap_get_context_info(); foreach ($contexts as $context_key => $context) { if (!isset($entity->context[$context_key]) && isset($context['default'])) { $entity->context[$context_key] = $context['default']; } } // Remove invalid contexts. $entity->context = array_intersect_key($entity->context, $contexts); } return $entities; } /** * {@inheritdoc} */ protected function doSave($id, EntityInterface $entity) { // Store the xmlsitemap auxiliar data. $this->state->set('xmlsitemap.' . $entity->id(), [ 'chunks' => $entity->getChunks(), 'links' => $entity->getLinks(), 'max_filesize' => $entity->getMaxFileSize(), 'updated' => $entity->getUpdated(), ]); $is_new = parent::doSave($id, $entity); return $is_new ? SAVED_NEW : SAVED_UPDATED; } }