Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / simple_sitemap / src / EntityHelper.php
1 <?php
2
3 namespace Drupal\simple_sitemap;
4
5 use Drupal\Core\Entity\ContentEntityTypeInterface;
6 use Drupal\Core\Entity\EntityTypeManagerInterface;
7 use Drupal\Core\Entity\Entity;
8
9 /**
10  * Class EntityHelper
11  * @package Drupal\simple_sitemap
12  */
13 class EntityHelper {
14
15   /**
16    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
17    */
18   protected $entityTypeManager;
19
20   /**
21    * EntityHelper constructor.
22    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
23    */
24   public function __construct(EntityTypeManagerInterface $entityTypeManager) {
25     $this->entityTypeManager = $entityTypeManager;
26   }
27
28   /**
29    * Gets an entity's bundle name.
30    *
31    * @param \Drupal\Core\Entity\Entity $entity
32    * @return string
33    */
34   public function getEntityInstanceBundleName(Entity $entity) {
35     return $entity->getEntityTypeId() == 'menu_link_content'
36       // Menu fix.
37       ? $entity->getMenuName() : $entity->bundle();
38   }
39
40   /**
41    * Gets the entity type id for a bundle.
42    *
43    * @param \Drupal\Core\Entity\Entity $entity
44    * @return null|string
45    */
46   public function getBundleEntityTypeId(Entity $entity) {
47     return $entity->getEntityTypeId() == 'menu'
48       // Menu fix.
49       ? 'menu_link_content' : $entity->getEntityType()->getBundleOf();
50   }
51
52   /**
53    * Returns objects of entity types that can be indexed.
54    *
55    * @return array
56    *   Objects of entity types that can be indexed by the sitemap.
57    */
58   public function getSitemapEntityTypes() {
59     $entity_types = $this->entityTypeManager->getDefinitions();
60
61     foreach ($entity_types as $entity_type_id => $entity_type) {
62       if (!$entity_type instanceof ContentEntityTypeInterface
63         || !method_exists($entity_type, 'getBundleEntityType')
64         || !$entity_type->hasLinkTemplate('canonical')) {
65         unset($entity_types[$entity_type_id]);
66       }
67     }
68     return $entity_types;
69   }
70
71   /**
72    * Checks whether an entity type does not provide bundles.
73    *
74    * @param string $entity_type_id
75    * @return bool
76    */
77   public function entityTypeIsAtomic($entity_type_id) {
78     // Menu fix.
79     if ($entity_type_id == 'menu_link_content') {
80       return FALSE;
81     }
82
83     $sitemap_entity_types = $this->getSitemapEntityTypes();
84     if (isset($sitemap_entity_types[$entity_type_id])) {
85       $entity_type = $sitemap_entity_types[$entity_type_id];
86       if (empty($entity_type->getBundleEntityType())) {
87         return TRUE;
88       }
89     }
90     // todo: throw exception.
91     return FALSE;
92   }
93
94 }