2
2
3
3
namespace Drupal \islandora \Plugin \search_api \processor ;
4
4
5
+ use Drupal \Component \Plugin \Exception \InvalidPluginDefinitionException ;
6
+ use Drupal \Component \Plugin \Exception \PluginNotFoundException ;
7
+ use Drupal \Core \Entity \EntityTypeManager ;
5
8
use Drupal \islandora \Plugin \search_api \processor \Property \EntityReferenceWithUriProperty ;
6
9
use Drupal \search_api \Datasource \DatasourceInterface ;
7
10
use Drupal \search_api \Item \ItemInterface ;
@@ -32,6 +35,13 @@ class EntityReferenceWithUri extends ProcessorPluginBase {
32
35
*/
33
36
protected IslandoraUtils $ utils ;
34
37
38
+ /**
39
+ * Entity Type Manager.
40
+ *
41
+ * @var \Drupal\Core\Entity\EntityTypeManager
42
+ */
43
+ protected EntityTypeManager $ entityTypeManager ;
44
+
35
45
/**
36
46
* Constructor.
37
47
*
@@ -46,15 +56,19 @@ class EntityReferenceWithUri extends ProcessorPluginBase {
46
56
* The plugin implementation definition.
47
57
* @param \Drupal\islandora\IslandoraUtils $utils
48
58
* Islandora utils.
59
+ * @param \Drupal\Core\Entity\EntityTypeManager $entityTypeManager
60
+ * Drupal Entity Type Manager.
49
61
*/
50
62
public function __construct (
51
63
array $ configuration ,
52
64
$ plugin_id ,
53
65
$ plugin_definition ,
54
- IslandoraUtils $ utils
66
+ IslandoraUtils $ utils ,
67
+ EntityTypeManager $ entityTypeManager
55
68
) {
56
69
parent ::__construct ($ configuration , $ plugin_id , $ plugin_definition );
57
70
$ this ->utils = $ utils ;
71
+ $ this ->entityTypeManager = $ entityTypeManager ;
58
72
}
59
73
60
74
/**
@@ -66,6 +80,7 @@ public static function create(ContainerInterface $container, array $configuratio
66
80
$ plugin_id ,
67
81
$ plugin_definition ,
68
82
$ container ->get ('islandora.utils ' ),
83
+ $ container ->get ('entity_type.manager ' ),
69
84
);
70
85
}
71
86
@@ -81,7 +96,7 @@ public function getPropertyDefinitions(DatasourceInterface $datasource = NULL) {
81
96
$ entity_type = $ datasource ->getEntityTypeId ();
82
97
83
98
// Get all configured Entity Relation fields for this entity type.
84
- $ fields = \Drupal:: entityTypeManager () ->getStorage ('field_config ' )->loadByProperties ([
99
+ $ fields = $ this -> entityTypeManager ->getStorage ('field_config ' )->loadByProperties ([
85
100
'entity_type ' => $ entity_type ,
86
101
'field_type ' => 'entity_reference ' ,
87
102
]);
@@ -97,7 +112,7 @@ public function getPropertyDefinitions(DatasourceInterface $datasource = NULL) {
97
112
'@label ' => $ field ->label (),
98
113
'@bundle ' => $ field ->getTargetBundle (),
99
114
]),
100
- 'description ' => $ this ->t ('Index the target entity, but only if the target entity has a taxonomy term. ' ),
115
+ 'description ' => $ this ->t ('Index the related entity, but only if the target entity has a taxonomy term. ' ),
101
116
'type ' => 'string ' ,
102
117
'processor_id ' => $ this ->getPluginId (),
103
118
'settings ' => [
@@ -114,6 +129,7 @@ public function getPropertyDefinitions(DatasourceInterface $datasource = NULL) {
114
129
115
130
/**
116
131
* {@inheritdoc}
132
+ * @throws \Drupal\search_api\SearchApiException
117
133
*/
118
134
public function addFieldValues (ItemInterface $ item ) {
119
135
// Skip if no Entity Reference with URI fields are configured.
@@ -144,9 +160,13 @@ public function addFieldValues(ItemInterface $item) {
144
160
foreach ($ content_entity ->get ($ field_name )->getValue () as $ values ) {
145
161
foreach ($ values as $ value ) {
146
162
// Load the entity stored in our field.
147
- $ target_entity = \Drupal::entityTypeManager ()
148
- ->getStorage ($ entity_type )
149
- ->load ($ value );
163
+ try {
164
+ $ target_entity = $ this ->entityTypeManager
165
+ ->getStorage ($ entity_type )
166
+ ->load ($ value );
167
+ } catch (InvalidPluginDefinitionException $ e ) {
168
+ } catch (PluginNotFoundException $ e ) {
169
+ }
150
170
// Load the taxonomy terms on the entity stored in our field.
151
171
$ referenced_terms = array_merge ($ referenced_terms , array_filter ($ target_entity ->referencedEntities (), function ($ entity ) {
152
172
if ($ entity ->getEntityTypeId () != 'taxonomy_term ' ) {
0 commit comments