forked from alxp/islandora
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
Binary file added
BIN
+2.09 KB
src/Plugin/search_api/processor/Property/.EntityReferenceWithUriProperty.php.un~
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/Plugin/search_api/processor/Property/EntityReferenceWithUriProperty.php~
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace Drupal\islandora\Plugin\search_api\processor\Property; | ||
|
||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\Core\StringTranslation\StringTranslationTrait; | ||
use Drupal\search_api\Item\FieldInterface; | ||
use Drupal\search_api\Processor\ConfigurablePropertyBase; | ||
use Drupal\taxonomy\Entity\Term; | ||
|
||
/** | ||
* Defines a "Entity Reference with URI" search property. | ||
* | ||
* @see \Drupal\islandora\Plugin\search_api\processor\EntityReferenceWithUri | ||
*/ | ||
class EntityReferenceWithUriProperty extends ConfigurablePropertyBase { | ||
|
||
use StringTranslationTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function defaultConfiguration() { | ||
return [ | ||
'filter_terms' => [], | ||
'require_all' => TRUE, | ||
'target_type' => '', | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildConfigurationForm(FieldInterface $field, array $form, FormStateInterface $form_state) { | ||
$configuration = $field->getConfiguration(); | ||
$logger = \Drupal::logger('islandora'); | ||
$logger->info('<pre>' . print_r($configuration['filter_terms'], TRUE) . '</pre>'); | ||
$form['filter_terms'] = [ | ||
'#type' => 'entity_autocomplete', | ||
'#target_type' => 'taxonomy_term', | ||
'#title' => $this->t('Related entities must have this URI to be included.'), | ||
'#tags' => TRUE, | ||
'#default_value' => array_map(function ($element) { | ||
return Term::load($element['target_id']); | ||
}, array_values($configuration['filter_terms'])), | ||
'#required' => TRUE, | ||
]; | ||
$form['require_all'] = [ | ||
'#type' => 'checkbox', | ||
'#title' => 'Require all terms', | ||
'#description' => 'Only index related entities that have all the listed terms.', | ||
'#default_value' => $configuration['require_all'], | ||
]; | ||
// Store the target type of the field, it's a pain to get it when indexing. | ||
$form['target_type'] = [ | ||
'#type' => 'hidden', | ||
'#value' => $field->getDataDefinition()->getSetting('target_type'), | ||
]; | ||
return $form; | ||
} | ||
|
||
} |