You are here

protected function SimpleSitemapSyncExtend::sitemapSupportsEntityType in CMS Content Sync 2.0.x

Same name and namespace in other branches
  1. 8 modules/cms_content_sync_simple_sitemap/src/EventSubscriber/SimpleSitemapSyncExtend.php \Drupal\cms_content_sync_simple_sitemap\EventSubscriber\SimpleSitemapSyncExtend::sitemapSupportsEntityType()
  2. 2.1.x modules/cms_content_sync_simple_sitemap/src/EventSubscriber/SimpleSitemapSyncExtend.php \Drupal\cms_content_sync_simple_sitemap\EventSubscriber\SimpleSitemapSyncExtend::sitemapSupportsEntityType()

Basically copied from different parts of the simple sitemap module. Must be updated when the logic of simple sitemap changes.

Parameters

string $entity_type_name:

string $bundle_name:

Return value

bool Whether or not the simple sitemap module supports configuring sitemap settings for the given entity type + bundle.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException

3 calls to SimpleSitemapSyncExtend::sitemapSupportsEntityType()
SimpleSitemapSyncExtend::extendEntityType in modules/cms_content_sync_simple_sitemap/src/EventSubscriber/SimpleSitemapSyncExtend.php
Add the field to the entity type for the simple sitemap configuration.
SimpleSitemapSyncExtend::extendPull in modules/cms_content_sync_simple_sitemap/src/EventSubscriber/SimpleSitemapSyncExtend.php
@internal param $entity @internal param $intent
SimpleSitemapSyncExtend::extendPush in modules/cms_content_sync_simple_sitemap/src/EventSubscriber/SimpleSitemapSyncExtend.php
Alter the push to include the sitemap settings, if enabled for the entity type and cached by the form values. Will not support programmatically added sitemap settings, so that's not supported out of the box.

File

modules/cms_content_sync_simple_sitemap/src/EventSubscriber/SimpleSitemapSyncExtend.php, line 43

Class

SimpleSitemapSyncExtend
Event subscriptions for events dispatched by Content Sync.

Namespace

Drupal\cms_content_sync_simple_sitemap\EventSubscriber

Code

protected function sitemapSupportsEntityType($entity_type_name, $bundle_name) {

  /**
   * @var \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
   */
  $entity_type_manager = \Drupal::service('entity_type.manager');
  $entity_type = $entity_type_manager
    ->getDefinition($entity_type_name, FALSE);
  if (!$entity_type instanceof ContentEntityTypeInterface || !method_exists($entity_type, 'getBundleEntityType') || !$entity_type
    ->hasLinkTemplate('canonical')) {
    return FALSE;
  }

  /**
   * @var \Drupal\Core\Config\ConfigFactory $config_factory
   */
  $config_factory = \Drupal::service('config.factory');
  $setting = $config_factory
    ->get('simple_sitemap.settings')
    ->get('enabled_entity_types');
  if (empty($setting) || !in_array($entity_type_name, $setting)) {
    return FALSE;
  }
  $bundle_settings = $config_factory
    ->get("simple_sitemap.bundle_settings.{$entity_type_name}.{$bundle_name}")
    ->get();

  // @todo Add support for multiple sitemap variants which have been
  // added by Simple Sitemap Version 3.0.
  if (empty($bundle_settings)) {
    $bundle_settings = $config_factory
      ->get("simple_sitemap.bundle_settings.default.{$entity_type_name}.{$bundle_name}")
      ->get();
  }
  if (empty($bundle_settings) || empty($bundle_settings['index'])) {
    return FALSE;
  }
  return TRUE;
}