FacetInterface.php 8.71 KB
Newer Older
1
2
3
<?php
/**
 * @file
4
 * Contains  Drupal\facets\FacetInterface.
5
6
 */

7
namespace Drupal\facets;
8
9

use Drupal\Core\Config\Entity\ConfigEntityInterface;
Joris Vercammen's avatar
Joris Vercammen committed
10

11
/**
Joris Vercammen's avatar
Joris Vercammen committed
12
 * The facet entity.
13
 */
14
15
interface FacetInterface extends ConfigEntityInterface {

16
17
18
  /**
   * Sets the facet's widget plugin id.
   *
19
   * @param string $widget
Joris Vercammen's avatar
Joris Vercammen committed
20
   *   The widget plugin id.
21
   *
22
   * @return $this
Joris Vercammen's avatar
Joris Vercammen committed
23
   *   Returns self
24
25
26
27
28
29
30
   */
  public function setWidget($widget);

  /**
   * Returns the facet's widget plugin id.
   *
   * @return string
Joris Vercammen's avatar
Joris Vercammen committed
31
   *   The widget plugin id.
32
33
   */
  public function getWidget();
34
35

  /**
36
   * Returns field identifier.
37
   *
38
   * @return string
Joris Vercammen's avatar
Joris Vercammen committed
39
   *   The field identifier of this facet.
40
41
42
   */
  public function getFieldIdentifier();

43
  /**
44
   * Sets field identifier.
45
   *
Joris Vercammen's avatar
Joris Vercammen committed
46
47
48
49
50
   * @param string $field_identifier
   *   The field identifier of this facet.
   *
   * @return $this
   *   Returns self.
51
52
53
   */
  public function setFieldIdentifier($field_identifier);

54
  /**
55
   * Returns the field alias used to identify the facet in the url.
56
   *
Joris Vercammen's avatar
Joris Vercammen committed
57
58
   * @return string
   *   The field alias for the facet.
59
60
61
   */
  public function getFieldAlias();

62
  /**
63
   * Returns the field name of the facet as used in the index.
64
65
66
   *
   * @TODO: Check if fieldIdentifier can be used as well!
   *
Joris Vercammen's avatar
Joris Vercammen committed
67
68
   * @return string
   *   The name of the facet.
69
70
   */
  public function getName();
Joris Vercammen's avatar
Joris Vercammen committed
71

72
  /**
73
   * Returns the name of the facet for use in the URL.
74
   *
75
   * @return string
76
   *   The name of the facet for use in the URL.
77
78
79
80
81
82
83
   */
  public function getUrlAlias();

  /**
   * Sets the name of the facet for use in the URL.
   *
   * @param string $url_alias
84
   *   The name of the facet for use in the URL.
85
86
87
   */
  public function setUrlAlias($url_alias);

88
89
90
  /**
   * Sets an item with value to active.
   *
Joris Vercammen's avatar
Joris Vercammen committed
91
92
   * @param string $value
   *   An item that is active.
93
94
95
96
   */
  public function setActiveItem($value);

  /**
97
   * Returns all the active items in the facet.
98
99
   *
   * @return mixed
Joris Vercammen's avatar
Joris Vercammen committed
100
   *   An array containing all active items.
101
102
103
   */
  public function getActiveItems();

104
  /**
Joris Vercammen's avatar
Joris Vercammen committed
105
   * Checks if a value is active.
106
107
   *
   * @param string $value
Joris Vercammen's avatar
Joris Vercammen committed
108
   *   The value to be checked.
109
   *
110
   * @return bool
Joris Vercammen's avatar
Joris Vercammen committed
111
   *   Is an active value.
112
113
114
   */
  public function isActiveValue($value);

Jur de Vries's avatar
Jur de Vries committed
115
  /**
116
   * Returns the result for the facet.
Jur de Vries's avatar
Jur de Vries committed
117
   *
118
   * @return \Drupal\facets\Result\ResultInterface[] $results
Joris Vercammen's avatar
Joris Vercammen committed
119
   *   The results of the facet.
Jur de Vries's avatar
Jur de Vries committed
120
121
122
123
   */
  public function getResults();

  /**
Joris Vercammen's avatar
Joris Vercammen committed
124
   * Sets the results for the facet.
Jur de Vries's avatar
Jur de Vries committed
125
   *
126
   * @param \Drupal\facets\Result\ResultInterface[] $results
Joris Vercammen's avatar
Joris Vercammen committed
127
   *   The results of the facet.
Jur de Vries's avatar
Jur de Vries committed
128
129
130
   */
  public function setResults(array $results);

131
132
133
134
135
136
137
  /**
   * Sets an array of unfiltered results.
   *
   * These unfiltered results are used to set the correct count of the actual
   * facet results when using the OR query operator. They are not results value
   * objects like those in ::$results.
   *
138
   * @param array $all_results
139
140
141
142
143
   *   Unfiltered results.
   */
  public function setUnfilteredResults(array $all_results = []);

  /**
144
   * Returns an array of unfiltered results.
145
146
   *
   * @return array
147
   *   Unfiltered results.
148
149
   */
  public function getUnfilteredResults();
150
151

  /**
152
   * Returns the query type instance.
153
   *
154
   * @return string
Joris Vercammen's avatar
Joris Vercammen committed
155
   *   The query type plugin being used.
156
157
158
   */
  public function getQueryType();

159
  /**
160
   * Returns the query operator.
161
162
163
164
165
166
   *
   * @return string
   *   The query operator being used.
   */
  public function getQueryOperator();

167
168
169
170
171
172
173
174
175
176
177
178
  /**
   * Returns the value of the exclude boolean.
   *
   * This will return true when the current facet's value should be exclusive
   * from the search rather than inclusive.
   * When this returns TRUE, the operator will be "<>" instead of "=".
   *
   * @return bool
   *   A boolean flag indicating if search should exlude selected facets
   */
  public function getExclude();

179
  /**
180
   * Returns the plugin name for the url processor.
181
   *
Joris Vercammen's avatar
Joris Vercammen committed
182
183
   * @return string
   *   The id of the url processor.
184
185
186
   */
  public function getUrlProcessorName();

187
188
189
190
191
  /**
   * Sets a string representation of the Facet source plugin.
   *
   * This is usually the name of the Search-api view.
   *
192
   * @param string $facet_source_id
Joris Vercammen's avatar
Joris Vercammen committed
193
   *   The facet source id.
194
   *
195
   * @return $this
Joris Vercammen's avatar
Joris Vercammen committed
196
   *   Returns self.
197
   */
198
  public function setFacetSourceId($facet_source_id);
199

200
201
202
  /**
   * Sets the query operator.
   *
203
   * @param string $operator
204
205
206
207
   *   The query operator being used.
   */
  public function setQueryOperator($operator);

208
209
210
  /**
   * Sets the exclude.
   *
Joris Vercammen's avatar
Joris Vercammen committed
211
   * @param bool $exclude
Joris Vercammen's avatar
Joris Vercammen committed
212
   *   A boolean flag indicating if search should exclude selected facets.
213
214
215
   */
  public function setExclude($exclude);

216
  /**
217
   * Returns the Facet source id.
218
   *
219
   * @return string
Joris Vercammen's avatar
Joris Vercammen committed
220
   *   The id of the facet source.
221
   */
222
223
224
225
226
  public function getFacetSourceId();

  /**
   * Returns the plugin instance of a facet source.
   *
227
   * @return \Drupal\facets\FacetSource\FacetSourcePluginInterface
228
229
   *   The plugin instance for the facet source.
   */
230
231
  public function getFacetSource();

232
233
234
235
236
237
238
239
  /**
   * Returns the facet source configuration object.
   *
   * @return \Drupal\facets\FacetSourceInterface
   *   A facet source configuration object.
   */
  public function getFacetSourceConfig();

240
  /**
241
   * Loads the facet sources for this facet.
242
243
   *
   * @param bool|TRUE $only_enabled
Joris Vercammen's avatar
Joris Vercammen committed
244
   *   Only return enabled facet sources.
245
   *
246
   * @return \Drupal\facets\FacetSource\FacetSourcePluginInterface[]
Joris Vercammen's avatar
Joris Vercammen committed
247
   *   An array of facet sources.
248
249
250
   */
  public function getFacetSources($only_enabled = TRUE);

251
252
253
254
  /**
   * Returns an array of processors with their configuration.
   *
   * @param bool|TRUE $only_enabled
Joris Vercammen's avatar
Joris Vercammen committed
255
   *   Only return enabled processors.
256
   *
257
   * @return \Drupal\facets\Processor\ProcessorInterface[]
Joris Vercammen's avatar
Joris Vercammen committed
258
   *   An array of processors.
259
260
261
   */
  public function getProcessors($only_enabled = TRUE);

262
263
264
265
266
  /**
   * Loads this facets processors for a specific stage.
   *
   * @param string $stage
   *   The stage for which to return the processors. One of the
267
   *   \Drupal\facets\Processor\ProcessorInterface::STAGE_* constants.
268
269
270
271
   * @param bool $only_enabled
   *   (optional) If FALSE, also include disabled processors. Otherwise, only
   *   load enabled ones.
   *
272
   * @return \Drupal\facets\Processor\ProcessorInterface[]
273
274
275
276
277
278
   *   An array of all enabled (or available, if if $only_enabled is FALSE)
   *   processors that support the given stage, ordered by the weight for that
   *   stage.
   */
  public function getProcessorsByStage($stage, $only_enabled = TRUE);

279
280
281
282
283
284
285
286
  /**
   * Retrieves this facets's processor configs.
   *
   * @return array
   *   An array of processors and their configs.
   */
  public function getProcessorConfigs();

287
288
289
  /**
   * Sets the "only visible when facet source is visible" boolean flag.
   *
290
   * @param bool $only_visible_when_facet_source_is_visible
291
292
293
294
   *   A boolean flag indicating if the facet should be hidden on a page that
   *   does not show the facet source.
   *
   * @return $this
Joris Vercammen's avatar
Joris Vercammen committed
295
   *   Returns self.
296
297
298
299
300
301
   */
  public function setOnlyVisibleWhenFacetSourceIsVisible($only_visible_when_facet_source_is_visible);

  /**
   * Returns the "only visible when facet source is visible" boolean flag.
   *
Joris Vercammen's avatar
Joris Vercammen committed
302
303
   * @return bool
   *   True when the facet is only shown on a page with the facet source.
304
305
   */
  public function getOnlyVisibleWhenFacetSourceIsVisible();
306

307
  /**
308
   * Adds a processor for this facet.
309
310
   *
   * @param array $processor
311
   *   An array definition for a processor.
312
313
314
315
   */
  public function addProcessor(array $processor);

  /**
316
   * Removes a processor for this facet.
317
318
   *
   * @param string $processor_id
319
   *   The plugin id of the processor.
320
321
322
323
   */
  public function removeProcessor($processor_id);

  /**
324
   * Defines the no-results behavior.
325
326
   *
   * @param array $behavior
327
   *   The definition of the behavior.
328
   */
329
  public function setEmptyBehavior(array $behavior);
330
331

  /**
332
   * Returns the defined no-results behavior or NULL if none defined.
333
334
   *
   * @return array|NULL
335
   *   The behavior definition or NULL.
336
337
338
339
   */
  public function getEmptyBehavior();

  /**
340
   * Returns the configuration of the selected widget.
341
342
   *
   * @return array
343
   *   The configuration settings for the widget.
344
345
346
347
   */
  public function getWidgetConfigs();

  /**
348
   * Sets the configuration for the widget of this facet.
349
350
   *
   * @param array $widget_config
351
   *   The configuration settings for the widget.
352
353
354
355
   */
  public function setWidgetConfigs(array $widget_config);

  /**
356
   * Returns any additional configuration for this facet, not defined above.
357
358
   *
   * @return array
359
   *   An array of additional configuration for the facet.
360
361
362
363
   */
  public function getFacetConfigs();

  /**
364
   * Defines any additional configuration for this facet not defined above.
365
366
   *
   * @param array $facet_config
367
   *   An array of additional configuration for the facet.
368
369
370
   */
  public function setFacetConfigs(array $facet_config);

371
}